ref: f7c60230669e8e00bc794f07726070d577d5aa3f
parent: b7089d66ad5a26a2b39c1c1e17a4761cd1670728
author: cinap_lenrek <[email protected]>
date: Sun Feb 23 09:08:33 EST 2020
devswap: dont assume Proc* structures returned from proctab() are continuous
--- a/sys/src/9/port/devswap.c
+++ b/sys/src/9/port/devswap.c
@@ -155,16 +155,14 @@
static void
pager(void*)
{
- int i;
+ Proc *p;
Segment *s;
- Proc *p, *ep;
+ int x, i;
- p = proctab(0);
- ep = &p[conf.nproc];
-
while(waserror())
;
+ x = -1;
for(;;){
up->psstate = "Reclaim";
if(reclaim()){
@@ -185,11 +183,12 @@
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 @@
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;
}