summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-02-23 14:08:33 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-02-23 14:08:33 +0100
commitf7c60230669e8e00bc794f07726070d577d5aa3f (patch)
tree70cad4d1e56b4b663b6ca50560ea68157bfb4518 /sys
parentb7089d66ad5a26a2b39c1c1e17a4761cd1670728 (diff)
devswap: dont assume Proc* structures returned from proctab() are continuous
Diffstat (limited to 'sys')
-rw-r--r--sys/src/9/port/devswap.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/sys/src/9/port/devswap.c b/sys/src/9/port/devswap.c
index 745303d74..db42b7172 100644
--- a/sys/src/9/port/devswap.c
+++ b/sys/src/9/port/devswap.c
@@ -155,16 +155,14 @@ reclaim(void)
static void
pager(void*)
{
- int i;
+ Proc *p;
Segment *s;
- Proc *p, *ep;
-
- p = proctab(0);
- ep = &p[conf.nproc];
+ int x, i;
while(waserror())
;
+ x = -1;
for(;;){
up->psstate = "Reclaim";
if(reclaim()){
@@ -185,11 +183,12 @@ pager(void*)
i = ageclock;
do {
- if(++p >= ep){
+ if(++x >= conf.nproc){
if(++ageclock == i)
goto Killbig;
- p = proctab(0);
+ x = 0;
}
+ p = proctab(x);
} while(p->state == Dead || p->noswap || !canqlock(&p->seglock));
up->psstate = "Pageout";
for(i = 0; i < NSEG; i++) {
@@ -266,25 +265,24 @@ pageout(Proc *p, Segment *s)
static int
canflush(Proc *p, Segment *s)
{
- int i;
- Proc *ep;
+ int x, i;
if(incref(s) == 2) /* Easy if we are the only user */
return canpage(p);
- /* Now we must do hardwork to ensure all processes which have tlb
+ /*
+ * Now we must do hardwork to ensure all processes which have tlb
* entries for this segment will be flushed if we succeed in paging it out
*/
- p = proctab(0);
- ep = &p[conf.nproc];
- while(p < ep) {
- if(p->state != Dead) {
- for(i = 0; i < NSEG; i++)
- if(p->seg[i] == s)
- if(!canpage(p))
- return 0;
+ for(x = 0; x < conf.nproc; x++){
+ p = proctab(x);
+ if(p->state == Dead)
+ continue;
+ for(i = 0; i < NSEG; i++){
+ if(p->seg[i] == s)
+ if(!canpage(p))
+ return 0;
}
- p++;
}
return 1;
}