ref: 2723c9fc775c6366011f6915d3ea1aab085a92fe
parent: fb165d6a54e46712036ec1cf4332905b94c1f97b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jun 20 17:53:45 EDT 2017
kernel: add support for sticky segments (cached, preallocated, never paged)
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -138,7 +138,7 @@
};
/* 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:
--- a/sys/src/9/port/devsegment.c
+++ b/sys/src/9/port/devsegment.c
@@ -284,6 +284,8 @@
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,
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
snprint(buf, sizeof(buf), "va %#p %#p\n", g->s->base, g->s->top-g->s->base);
return readstr(voff, a, n, buf);
@@ -331,6 +333,20 @@
if(!iseve())
error(Eperm);
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
g->s = newseg(SG_SHARED, va, len/BY2PG);
} else
--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -270,6 +270,8 @@
copypage(old, *pg);
putpage(old);
}
+ /* wet floor */
+ case SG_STICKY: /* Never paged out */
mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID;
(*pg)->modref = PG_MOD|PG_REF;
break;
--- a/sys/src/9/port/portdat.h
+++ b/sys/src/9/port/portdat.h
@@ -368,6 +368,7 @@
SG_SHARED = 04,
SG_PHYSICAL = 05,
SG_FIXED = 06,
+ SG_STICKY = 07,
SG_RONLY = 0040, /* Segment is read only */
SG_CEXEC = 0100, /* Detach at exec */
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -1595,6 +1595,7 @@
case SG_SHARED:
case SG_PHYSICAL:
case SG_FIXED:
+ case SG_STICKY:
continue;
}
qlock(s);
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -155,6 +155,7 @@
case SG_SHARED:
case SG_PHYSICAL:
case SG_FIXED:
+ case SG_STICKY:
goto sameseg;
case SG_STACK:
@@ -499,6 +500,7 @@
switch(s->type&SG_TYPE){
case SG_PHYSICAL:
case SG_FIXED:
+ case SG_STICKY:
return;
}
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -773,6 +773,7 @@
case SG_STACK:
case SG_PHYSICAL:
case SG_FIXED:
+ case SG_STICKY:
error(Ebadarg);
default:
return ibrk(va_arg(list, uintptr), i);