kernel: various cleanups of imagereclaim(), pagereclaim(), freepages(), putimage()
imagereclaim(), pagereclaim(): - move imagereclaim() and pagereclaim() declarations to portfns.h - consistently use ulong type for page counts - name number of pages to free "pages" instead of "min" - check for pages == 0 on entry freepages(): - move pagechaindone() call to wakeup newpage() consumers inside palloc critical section. putimage(): - use long type for refcount
This commit is contained in:
parent
fcb9abccbb
commit
8ed25f24b7
|
@ -83,22 +83,25 @@ pagechaindone(void)
|
|||
}
|
||||
|
||||
static void
|
||||
freepages(Page *head, Page *tail, int n)
|
||||
freepages(Page *head, Page *tail, ulong np)
|
||||
{
|
||||
lock(&palloc);
|
||||
tail->next = palloc.head;
|
||||
palloc.head = head;
|
||||
palloc.freecount += n;
|
||||
unlock(&palloc);
|
||||
palloc.freecount += np;
|
||||
pagechaindone();
|
||||
unlock(&palloc);
|
||||
}
|
||||
|
||||
int
|
||||
pagereclaim(Image *i, int min)
|
||||
ulong
|
||||
pagereclaim(Image *i, ulong pages)
|
||||
{
|
||||
Page **h, **l, **x, *p;
|
||||
Page *fh, *ft;
|
||||
int n;
|
||||
ulong np;
|
||||
|
||||
if(pages == 0)
|
||||
return 0;
|
||||
|
||||
lock(i);
|
||||
if(i->pgref == 0){
|
||||
|
@ -107,7 +110,7 @@ pagereclaim(Image *i, int min)
|
|||
}
|
||||
incref(i);
|
||||
|
||||
n = 0;
|
||||
np = 0;
|
||||
fh = ft = nil;
|
||||
for(h = i->pghash; h < &i->pghash[PGHSIZE]; h++){
|
||||
l = h;
|
||||
|
@ -133,16 +136,16 @@ pagereclaim(Image *i, int min)
|
|||
else
|
||||
ft->next = p;
|
||||
ft = p;
|
||||
if(++n >= min)
|
||||
if(++np >= pages)
|
||||
break;
|
||||
}
|
||||
unlock(i);
|
||||
putimage(i);
|
||||
|
||||
if(n > 0)
|
||||
freepages(fh, ft, n);
|
||||
if(np > 0)
|
||||
freepages(fh, ft, np);
|
||||
|
||||
return n;
|
||||
return np;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -131,6 +131,7 @@ long ibrk(uintptr, int);
|
|||
void ilock(Lock*);
|
||||
void interrupted(void);
|
||||
void iunlock(Lock*);
|
||||
ulong imagereclaim(ulong);
|
||||
long incref(Ref*);
|
||||
void initseg(void);
|
||||
int iprint(char*, ...);
|
||||
|
@ -204,7 +205,8 @@ Block* padblock(Block*, int);
|
|||
void pagechaindone(void);
|
||||
void pagechainhead(Page*);
|
||||
void pageinit(void);
|
||||
ulong pagenumber(Page*);
|
||||
ulong pagenumber(Page*);
|
||||
ulong pagereclaim(Image*, ulong);
|
||||
void pagersummary(void);
|
||||
void panic(char*, ...);
|
||||
Cmdbuf* parsecmd(char *a, int n);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "fns.h"
|
||||
#include "../port/error.h"
|
||||
|
||||
int imagereclaim(int);
|
||||
|
||||
/*
|
||||
* Attachable segment types
|
||||
*/
|
||||
|
@ -295,20 +293,22 @@ found:
|
|||
return i;
|
||||
}
|
||||
|
||||
extern int pagereclaim(Image*, int); /* page.c */
|
||||
|
||||
int
|
||||
imagereclaim(int min)
|
||||
ulong
|
||||
imagereclaim(ulong pages)
|
||||
{
|
||||
static Image *i, *ie;
|
||||
int j, n;
|
||||
ulong np;
|
||||
int j;
|
||||
|
||||
if(pages == 0)
|
||||
return 0;
|
||||
|
||||
eqlock(&imagealloc.ireclaim);
|
||||
if(i == nil){
|
||||
i = imagealloc.list;
|
||||
ie = &imagealloc.list[conf.nimage];
|
||||
}
|
||||
n = 0;
|
||||
np = 0;
|
||||
for(j = 0; j < conf.nimage; j++, i++){
|
||||
if(i >= ie)
|
||||
i = imagealloc.list;
|
||||
|
@ -319,14 +319,14 @@ imagereclaim(int min)
|
|||
* reclaim pages from inactive images.
|
||||
*/
|
||||
if(imagealloc.free != nil || i->ref == i->pgref){
|
||||
n += pagereclaim(i, min - n);
|
||||
if(n >= min)
|
||||
np += pagereclaim(i, pages - np);
|
||||
if(np >= pages)
|
||||
break;
|
||||
}
|
||||
}
|
||||
qunlock(&imagealloc.ireclaim);
|
||||
|
||||
return n;
|
||||
return np;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -334,7 +334,7 @@ putimage(Image *i)
|
|||
{
|
||||
Image *f, **l;
|
||||
Chan *c;
|
||||
int r;
|
||||
long r;
|
||||
|
||||
if(i->notext){
|
||||
decref(i);
|
||||
|
|
|
@ -118,25 +118,22 @@ kickpager(void)
|
|||
kproc("pager", pager, 0);
|
||||
}
|
||||
|
||||
extern int pagereclaim(Image*,int); /* page.c */
|
||||
extern int imagereclaim(int); /* segment.c */
|
||||
|
||||
static int
|
||||
reclaim(void)
|
||||
{
|
||||
int n;
|
||||
ulong np;
|
||||
|
||||
for(;;){
|
||||
if((n = pagereclaim(&fscache, 1000)) > 0) {
|
||||
if(0) print("reclaim: %d fscache\n", n);
|
||||
} else if((n = pagereclaim(&swapimage, 1000)) > 0) {
|
||||
if(0) print("reclaim: %d swap\n", n);
|
||||
} else if((n = imagereclaim(1000)) > 0) {
|
||||
if(0) print("reclaim: %d image\n", n);
|
||||
if((np = pagereclaim(&fscache, 1000)) > 0) {
|
||||
if(0) print("reclaim: %lud fscache\n", np);
|
||||
} else if((np = pagereclaim(&swapimage, 1000)) > 0) {
|
||||
if(0) print("reclaim: %lud swap\n", np);
|
||||
} else if((np = imagereclaim(1000)) > 0) {
|
||||
if(0) print("reclaim: %lud image\n", np);
|
||||
}
|
||||
if(!needpages(nil))
|
||||
return 1; /* have pages, done */
|
||||
if(n == 0)
|
||||
if(np == 0)
|
||||
return 0; /* didnt reclaim, need to swap */
|
||||
sched();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue