summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-07-09 00:01:50 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-07-09 00:01:50 +0200
commit8ed25f24b7831eab394f14697766d55065b18822 (patch)
tree58fade4cfccb0e0e081e7687a3860406c80d54e1
parentfcb9abccbbc73a4f449d55c2c7fb369db2ad139d (diff)
downloadplan9front-8ed25f24b7831eab394f14697766d55065b18822.tar.xz
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
-rw-r--r--sys/src/9/port/page.c25
-rw-r--r--sys/src/9/port/portfns.h4
-rw-r--r--sys/src/9/port/segment.c24
-rw-r--r--sys/src/9/port/swap.c19
4 files changed, 37 insertions, 35 deletions
diff --git a/sys/src/9/port/page.c b/sys/src/9/port/page.c
index 2b0c10eeb..85406f4af 100644
--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -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
diff --git a/sys/src/9/port/portfns.h b/sys/src/9/port/portfns.h
index 5fbcf1305..2f135c31b 100644
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -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);
diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c
index a15f928cc..987f984cc 100644
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -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);
diff --git a/sys/src/9/port/swap.c b/sys/src/9/port/swap.c
index 73d12345a..f2966449b 100644
--- a/sys/src/9/port/swap.c
+++ b/sys/src/9/port/swap.c
@@ -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();
}