linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [2x PATCH] page map aging & improved kswap logic
@ 1998-02-26 21:00 Rik van Riel
  0 siblings, 0 replies; 4+ messages in thread
From: Rik van Riel @ 1998-02-26 21:00 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Stephen C. Tweedie, linux-mm

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1451 bytes --]

Hi Linus,

Here are the two patches I sent you earlier today,
this time against 2.1.89-pre2.

The kswapd logic is almost completely redone. Basically,
kswapd tries (free_pages_high - nr_free_pages) times to
free a page, but when memory becomes tighter, the number
of tries become even higher.

Since the code is compiling as I write, I don't know if
the agression factor is right, but we can adjust that
later...

A nice sideeffect of this is, that when memory is being
allocated slowly, kswapd will behave itself much better
then when memory is allocated faster. In the latter case,
kswapd will also become _far_ more agressive. It's kinda
self-tuning, but just not yet :-)

As for the other patch, it simply copies kswapd's page-aging
behaviour for page cache (and swap cache) pages. Buffer
pages, and possibly other ones, are still thrown out as soon
as they're not used any more.

OK... wait and see if it compiles <wait...wait...wait...wait>:
Yup, it compiles without a hitch (only mprotect.c gives a
warning about an ambiguous else ... gcc-2.8.0).
And since there's no new code in action, I leave the rebooting
to you guys.

Rik.
+-----------------------------+------------------------------+
| For Linux mm-patches, go to | "I'm busy managing memory.." |
| my homepage (via LinuxHQ).  | H.H.vanRiel@fys.ruu.nl       |
| ...submissions welcome...   | http://www.fys.ruu.nl/~riel/ |
+-----------------------------+------------------------------+

[-- Attachment #2: Type: TEXT/PLAIN, Size: 2207 bytes --]

--- vmscan.pre89-2	Thu Feb 26 21:10:33 1998
+++ vmscan.c	Thu Feb 26 21:57:53 1998
@@ -539,7 +539,7 @@
 	init_swap_timer();
 	add_wait_queue(&kswapd_wait, &wait);
 	while (1) {
-		int async;
+		int tries;
 
 		kswapd_awake = 0;
 		flush_signals(current);
@@ -549,32 +549,45 @@
 		kswapd_awake = 1;
 		swapstats.wakeups++;
 		/* Do the background pageout: 
-		 * We now only swap out as many pages as needed.
-		 * When we are truly low on memory, we swap out
-		 * synchronously (WAIT == 1).  -- Rik.
-		 * If we've had too many consecutive failures,
-		 * go back to sleep to let other tasks run.
+		 * When we've got loads of memory, we try
+		 * (free_pages_high - nr_free_pages) times to
+		 * free memory. As memory gets tighter, kswapd
+		 * gets more and more agressive. -- Rik.
 		 */
-		async = 1;
-		for (;;) {
+		tries = free_pages_high - nr_free_pages;
+		if (tries < min_free_pages) {
+			tries = min_free_pages;
+		}
+		else if (nr_free_pages < (free_pages_high + free_pages_low) / 2) {
+			tries <<= 1;
+			if (nr_free_pages < free_pages_low) {
+				tries <<= 1;
+				if (nr_free_pages <= min_free_pages) {
+					tries <<= 1;
+				}
+			}
+		}
+		while (tries--) {
 			int gfp_mask;
 
 			if (free_memory_available())
 				break;
 			gfp_mask = __GFP_IO;
-			if (!async)
-				gfp_mask |= __GFP_WAIT;
-			async = try_to_free_page(gfp_mask);
-			if (!(gfp_mask & __GFP_WAIT) || async)
-				continue;
-
+			try_to_free_page(gfp_mask);
 			/*
-			 * Not good. We failed to free a page even though
-			 * we were synchronous. Complain and give up..
+			 * Syncing large chunks is faster than swapping
+			 * synchronously (less head movement). -- Rik.
 			 */
-			printk("kswapd: failed to free page\n");
-			break;
+			if (atomic_read(&nr_async_pages) >= SWAP_CLUSTER_MAX)
+				run_task_queue(&tq_disk);
+
 		}
+	/*
+	 * Report failure if we couldn't even reach min_free_pages.
+	 */
+	if (nr_free_pages < min_free_pages)
+		printk("kswapd: failed, got %d of %d\n",
+			nr_free_pages, min_free_pages);
 	}
 	/* As if we could ever get here - maybe we want to make this killable */
 	remove_wait_queue(&kswapd_wait, &wait);

[-- Attachment #3: Type: TEXT/PLAIN, Size: 1224 bytes --]

--- linux/mm/filemap.pre89-2	Thu Feb 26 21:10:44 1998
+++ linux/mm/filemap.c	Thu Feb 26 21:19:52 1998
@@ -25,6 +25,7 @@
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 #include <linux/blkdev.h>
+#include <linux/swapctl.h>
 
 #include <asm/system.h>
 #include <asm/pgtable.h>
@@ -158,12 +159,15 @@
 
 		switch (atomic_read(&page->count)) {
 			case 1:
-				/* If it has been referenced recently, don't free it */
-				if (test_and_clear_bit(PG_referenced, &page->flags))
-					break;
-
 				/* is it a swap-cache or page-cache page? */
 				if (page->inode) {
+					if (test_and_clear_bit(PG_referenced, &page->flags)) {
+						touch_page(page);
+						break;
+					}
+					age_page(page);
+					if (page->age)
+						break;
 					if (PageSwapCache(page)) {
 						delete_from_swap_cache(page);
 						return 1;
@@ -173,6 +177,10 @@
 					__free_page(page);
 					return 1;
 				}
+				/* It's not a cache page, so we don't do aging.
+				 * If it has been referenced recently, don't free it */
+				if (test_and_clear_bit(PG_referenced, &page->flags))
+					break;
 
 				/* is it a buffer cache page? */
 				if ((gfp_mask & __GFP_IO) && bh && try_to_free_buffer(bh, &bh, 6))

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-02-27 22:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199802270929.KAA28081@boole.fs100.suse.de>
1998-02-27  9:58 ` [2x PATCH] page map aging & improved kswap logic Rik van Riel
1998-02-27 19:52   ` Stephen C. Tweedie
1998-02-27 22:28     ` Benjamin C.R. LaHaise
1998-02-26 21:00 Rik van Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox