kernel: add support for sticky segments (cached, preallocated, never paged)

This commit is contained in:
cinap_lenrek 2017-06-20 21:53:45 +02:00
parent fb165d6a54
commit 2723c9fc77
7 changed files with 24 additions and 1 deletions

View file

@ -138,7 +138,7 @@ Cmdtab proccmd[] = {
}; };
/* Segment type from portdat.h */ /* Segment type from portdat.h */
static char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys", "Fixed", }; static char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys", "Fixed", "Sticky" };
/* /*
* Qids are, in path: * Qids are, in path:

View file

@ -284,6 +284,8 @@ segmentread(Chan *c, void *a, long n, vlong voff)
if((g->s->type&SG_TYPE) == SG_FIXED) if((g->s->type&SG_TYPE) == SG_FIXED)
snprint(buf, sizeof(buf), "va %#p %#p fixed %#p\n", g->s->base, g->s->top-g->s->base, snprint(buf, sizeof(buf), "va %#p %#p fixed %#p\n", g->s->base, g->s->top-g->s->base,
g->s->map[0]->pages[0]->pa); g->s->map[0]->pages[0]->pa);
else if((g->s->type&SG_TYPE) == SG_STICKY)
snprint(buf, sizeof(buf), "va %#p %#p sticky\n", g->s->base, g->s->top-g->s->base);
else else
snprint(buf, sizeof(buf), "va %#p %#p\n", g->s->base, g->s->top-g->s->base); snprint(buf, sizeof(buf), "va %#p %#p\n", g->s->base, g->s->top-g->s->base);
return readstr(voff, a, n, buf); return readstr(voff, a, n, buf);
@ -331,6 +333,20 @@ segmentwrite(Chan *c, void *a, long n, vlong voff)
if(!iseve()) if(!iseve())
error(Eperm); error(Eperm);
g->s = fixedseg(va, len/BY2PG); g->s = fixedseg(va, len/BY2PG);
} else if(cb->nf >= 4 && strcmp(cb->f[3], "sticky") == 0){
Segment *s;
if(!iseve())
error(Eperm);
s = newseg(SG_STICKY, va, len/BY2PG);
if(waserror()){
putseg(s);
nexterror();
}
for(; va < s->top; va += BY2PG)
segpage(s, newpage(1, nil, va));
poperror();
g->s = s;
} else } else
g->s = newseg(SG_SHARED, va, len/BY2PG); g->s = newseg(SG_SHARED, va, len/BY2PG);
} else } else

View file

@ -270,6 +270,8 @@ fixfault(Segment *s, uintptr addr, int read)
copypage(old, *pg); copypage(old, *pg);
putpage(old); putpage(old);
} }
/* wet floor */
case SG_STICKY: /* Never paged out */
mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID; mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID;
(*pg)->modref = PG_MOD|PG_REF; (*pg)->modref = PG_MOD|PG_REF;
break; break;

View file

@ -368,6 +368,7 @@ enum
SG_SHARED = 04, SG_SHARED = 04,
SG_PHYSICAL = 05, SG_PHYSICAL = 05,
SG_FIXED = 06, SG_FIXED = 06,
SG_STICKY = 07,
SG_RONLY = 0040, /* Segment is read only */ SG_RONLY = 0040, /* Segment is read only */
SG_CEXEC = 0100, /* Detach at exec */ SG_CEXEC = 0100, /* Detach at exec */

View file

@ -1595,6 +1595,7 @@ killbig(char *why)
case SG_SHARED: case SG_SHARED:
case SG_PHYSICAL: case SG_PHYSICAL:
case SG_FIXED: case SG_FIXED:
case SG_STICKY:
continue; continue;
} }
qlock(s); qlock(s);

View file

@ -155,6 +155,7 @@ dupseg(Segment **seg, int segno, int share)
case SG_SHARED: case SG_SHARED:
case SG_PHYSICAL: case SG_PHYSICAL:
case SG_FIXED: case SG_FIXED:
case SG_STICKY:
goto sameseg; goto sameseg;
case SG_STACK: case SG_STACK:
@ -499,6 +500,7 @@ mfreeseg(Segment *s, uintptr start, ulong pages)
switch(s->type&SG_TYPE){ switch(s->type&SG_TYPE){
case SG_PHYSICAL: case SG_PHYSICAL:
case SG_FIXED: case SG_FIXED:
case SG_STICKY:
return; return;
} }

View file

@ -773,6 +773,7 @@ syssegbrk(va_list list)
case SG_STACK: case SG_STACK:
case SG_PHYSICAL: case SG_PHYSICAL:
case SG_FIXED: case SG_FIXED:
case SG_STICKY:
error(Ebadarg); error(Ebadarg);
default: default:
return ibrk(va_arg(list, uintptr), i); return ibrk(va_arg(list, uintptr), i);