linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rik van Riel <riel@conectiva.com.br>
To: linux-mm@kvack.org
Subject: [PATCH] bgaging + balance  v2
Date: Thu, 26 Apr 2001 22:08:05 -0300 (BRST)	[thread overview]
Message-ID: <Pine.LNX.4.21.0104262206310.19012-100000@imladris.rielhome.conectiva> (raw)

Hi,

in my patch yesterday evening there was a big mistake;
the old line calculating maxscan wasn't removed, so all
the fancy recalculation wouldn't do anything ;)

A new patch with this one line fixed is below.

Thanks to Adrian Drzewiecki for discovering this one...

regards,

Rik
--
Virtual memory is like a game you can't win;
However, without VM there's truly nothing to lose...

		http://www.surriel.com/
http://www.conectiva.com/	http://distro.conectiva.com.br/



--- linux-2.4.4-pre7/mm/vmscan.c.orig	Wed Apr 25 23:59:48 2001
+++ linux-2.4.4-pre7/mm/vmscan.c	Thu Apr 26 22:06:23 2001
@@ -24,6 +24,8 @@
 
 #include <asm/pgalloc.h>
 
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+
 /*
  * The swap-out function returns 1 if it successfully
  * scanned all the pages it was asked to (`count').
@@ -631,21 +633,48 @@
 /**
  * refill_inactive_scan - scan the active list and find pages to deactivate
  * @priority: the priority at which to scan
- * @oneshot: exit after deactivating one page
+ * @count: the number of pages to deactivate
  *
  * This function will scan a portion of the active list to find
  * unused pages, those pages will then be moved to the inactive list.
  */
-int refill_inactive_scan(unsigned int priority, int oneshot)
+int refill_inactive_scan(unsigned int priority, int count)
 {
 	struct list_head * page_lru;
 	struct page * page;
-	int maxscan, page_active = 0;
-	int ret = 0;
+	int maxscan = nr_active_pages >> priority;
+	int page_active = 0;
+
+	/*
+	 * If no count was specified, we do background page aging.
+	 * This is done so, after periods of little VM activity, we
+	 * know which pages to swap out and we can handle load spikes.
+	 * However, if we scan unlimited and deactivate all pages,
+	 * we still wouldn't know which pages to swap ...
+	 *
+	 * The obvious solution is to do less background scanning when
+	 * we have lots of inactive pages and to completely stop if we
+	 * have tons of them...
+	 */
+	if (!count) {
+		int nr_active, nr_inactive;
+		
+		/* Active pages can be "hidden" in ptes, take a saner number. */
+		nr_active = MAX(nr_active_pages, num_physpages / 2);
+		nr_inactive = nr_inactive_dirty_pages + nr_free_pages() +
+					nr_inactive_clean_pages();
+
+		if (nr_inactive * 10 < nr_active) {
+			maxscan = nr_active_pages >> 4;
+		} else if (nr_inactive * 3 < nr_active_pages) {
+			maxscan = nr_active >> 8;
+		} else {
+			maxscan = 0;
+		}
+	}
 
 	/* Take the lock while messing with the list... */
 	spin_lock(&pagemap_lru_lock);
-	maxscan = nr_active_pages >> priority;
 	while (maxscan-- > 0 && (page_lru = active_list.prev) != &active_list) {
 		page = list_entry(page_lru, struct page, lru);
 
@@ -690,14 +719,13 @@
 			list_del(page_lru);
 			list_add(page_lru, &active_list);
 		} else {
-			ret = 1;
-			if (oneshot)
+			if (--count <= 0)
 				break;
 		}
 	}
 	spin_unlock(&pagemap_lru_lock);
 
-	return ret;
+	return count;
 }
 
 /*
@@ -805,10 +833,9 @@
 			schedule();
 		}
 
-		while (refill_inactive_scan(DEF_PRIORITY, 1)) {
-			if (--count <= 0)
-				goto done;
-		}
+		count -= refill_inactive_scan(DEF_PRIORITY, count);
+		if (--count <= 0)
+			goto done;
 
 		/* If refill_inactive_scan failed, try to page stuff out.. */
 		swap_out(DEF_PRIORITY, gfp_mask);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

             reply	other threads:[~2001-04-27  1:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-27  1:08 Rik van Riel [this message]
2001-04-27  6:17 ` Marcelo Tosatti
2001-04-27 14:26   ` Rik van Riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0104262206310.19012-100000@imladris.rielhome.conectiva \
    --to=riel@conectiva.com.br \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox