shithub: riscv

Download patch

ref: c29719ce841be56ed8486697433f6059011c63ee
parent: 1d1fafc89248be211ec5d2176f4f5f9b6189bdb0
parent: 521a34d33b85e75013656b3dbb333035ed1d8a41
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Feb 24 17:43:21 EST 2014

merge

--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -64,7 +64,7 @@
 	print("%ldM swap\n", vkb/1024);
 }
 
-static void
+void
 pageunchain(Page *p)
 {
 	if(canlock(&palloc))
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -202,6 +202,7 @@
 int		openmode(ulong);
 Block*		packblock(Block*);
 Block*		padblock(Block*, int);
+void		pageunchain(Page*);
 void		pagechainhead(Page*);
 void		pageinit(void);
 ulong	pagenumber(Page*);
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -313,7 +313,7 @@
 imagereclaim(void)
 {
 	int n;
-	Page *p;
+	Page *p, *x;
 	uvlong ticks;
 
 	irstats.calls++;
@@ -329,11 +329,16 @@
 	 * end of the list (see putpage) so start there and work
 	 * backward.
 	 */
-	for(p = palloc.tail; p && p->image && (n<1000 || !imagealloc.free); p = p->prev) {
+	for(p = palloc.tail; p && p->image && (n<1000 || !imagealloc.free); p = x) {
+		x = p->prev;
 		if(p->ref == 0 && canlock(p)) {
 			if(p->ref == 0 && p->image && !p->image->notext) {
 				n++;
 				uncachepage(p);
+
+				/* move to head to maintain the invariant above */
+				pageunchain(p);
+				pagechainhead(p);
 			}
 			unlock(p);
 		}