mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 09/13] scan_swap_map restyled
Date: Sat, 9 Jul 2005 01:08:31 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0507090107420.13391@goblin.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0507090057340.13391@goblin.wat.veritas.com>

Rewrite scan_swap_map to allocate in just the same way as before
(taking the next free entry SWAPFILE_CLUSTER-1 times, then restarting at
the lowest wholly empty cluster, falling back to lowest entry if none),
but with a view towards dropping the lock in the next patch.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---

 mm/swapfile.c |   91 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 44 deletions(-)

--- swap8/mm/swapfile.c	2005-07-08 19:14:54.000000000 +0100
+++ swap9/mm/swapfile.c	2005-07-08 19:15:06.000000000 +0100
@@ -84,64 +84,67 @@ void swap_unplug_io_fn(struct backing_de
 
 static inline unsigned long scan_swap_map(struct swap_info_struct *si)
 {
-	unsigned long offset;
+	unsigned long offset, last_in_cluster;
+
 	/* 
-	 * We try to cluster swap pages by allocating them
-	 * sequentially in swap.  Once we've allocated
-	 * SWAPFILE_CLUSTER pages this way, however, we resort to
-	 * first-free allocation, starting a new cluster.  This
-	 * prevents us from scattering swap pages all over the entire
-	 * swap partition, so that we reduce overall disk seek times
-	 * between swap pages.  -- sct */
-	if (si->cluster_nr) {
-		while (si->cluster_next <= si->highest_bit) {
-			offset = si->cluster_next++;
+	 * We try to cluster swap pages by allocating them sequentially
+	 * in swap.  Once we've allocated SWAPFILE_CLUSTER pages this
+	 * way, however, we resort to first-free allocation, starting
+	 * a new cluster.  This prevents us from scattering swap pages
+	 * all over the entire swap partition, so that we reduce
+	 * overall disk seek times between swap pages.  -- sct
+	 * But we do now try to find an empty cluster.  -Andrea
+	 */
+
+	if (unlikely(!si->cluster_nr)) {
+		si->cluster_nr = SWAPFILE_CLUSTER - 1;
+		if (si->pages - si->inuse_pages < SWAPFILE_CLUSTER)
+			goto lowest;
+
+		offset = si->lowest_bit;
+		last_in_cluster = offset + SWAPFILE_CLUSTER - 1;
+
+		/* Locate the first empty (unaligned) cluster */
+		for (; last_in_cluster <= si->highest_bit; offset++) {
 			if (si->swap_map[offset])
-				continue;
-			si->cluster_nr--;
-			goto got_page;
+				last_in_cluster = offset + SWAPFILE_CLUSTER;
+			else if (offset == last_in_cluster) {
+				si->cluster_next = offset-SWAPFILE_CLUSTER-1;
+				goto cluster;
+			}
 		}
+		goto lowest;
 	}
-	si->cluster_nr = SWAPFILE_CLUSTER;
 
-	/* try to find an empty (even not aligned) cluster. */
-	offset = si->lowest_bit;
- check_next_cluster:
-	if (offset+SWAPFILE_CLUSTER-1 <= si->highest_bit)
-	{
-		unsigned long nr;
-		for (nr = offset; nr < offset+SWAPFILE_CLUSTER; nr++)
-			if (si->swap_map[nr])
-			{
-				offset = nr+1;
-				goto check_next_cluster;
-			}
-		/* We found a completly empty cluster, so start
-		 * using it.
-		 */
-		goto got_page;
-	}
-	/* No luck, so now go finegrined as usual. -Andrea */
-	for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) {
-		if (si->swap_map[offset])
-			continue;
-		si->lowest_bit = offset+1;
-	got_page:
-		if (offset == si->lowest_bit)
+	si->cluster_nr--;
+cluster:
+	offset = si->cluster_next;
+	if (offset > si->highest_bit)
+lowest:		offset = si->lowest_bit;
+	if (!si->highest_bit)
+		goto no_page;
+	if (!si->swap_map[offset]) {
+got_page:	if (offset == si->lowest_bit)
 			si->lowest_bit++;
 		if (offset == si->highest_bit)
 			si->highest_bit--;
-		if (si->lowest_bit > si->highest_bit) {
+		si->inuse_pages++;
+		if (si->inuse_pages == si->pages) {
 			si->lowest_bit = si->max;
 			si->highest_bit = 0;
 		}
 		si->swap_map[offset] = 1;
-		si->inuse_pages++;
-		si->cluster_next = offset+1;
+		si->cluster_next = offset + 1;
 		return offset;
 	}
-	si->lowest_bit = si->max;
-	si->highest_bit = 0;
+
+	while (++offset <= si->highest_bit) {
+		if (!si->swap_map[offset])
+			goto got_page;
+	}
+	goto lowest;
+
+no_page:
 	return 0;
 }
 

  parent reply	other threads:[~2005-07-09  0:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09  0:00 [PATCH 00/13] some swapfile patches Hugh Dickins
2005-07-09  0:01 ` [PATCH 01/13] update swapfile i_sem comment Hugh Dickins
2005-07-09  0:01 ` [PATCH 02/13] correct swapfile nr_good_pages Hugh Dickins
2005-07-09  0:02 ` [PATCH 03/13] move destroy_swap_extents calls Hugh Dickins
2005-07-09  0:03 ` [PATCH 04/13] swap extent list is ordered Hugh Dickins
2005-07-09  0:04 ` [PATCH 05/13] show span of swap extents Hugh Dickins
2005-07-09  0:05 ` [PATCH 06/13] swap unsigned int consistency Hugh Dickins
2005-07-09  0:06 ` [PATCH 07/13] freeing update swap_list.next Hugh Dickins
2005-07-09  0:07 ` [PATCH 08/13] get_swap_page drop swap_list_lock Hugh Dickins
2005-07-09  0:08 ` Hugh Dickins [this message]
2005-07-09  0:09 ` [PATCH 10/13] scan_swap_map drop swap_device_lock Hugh Dickins
2005-07-09  0:10 ` [PATCH 11/13] scan_swap_map latency breaks Hugh Dickins
2005-07-09  0:11 ` [PATCH 12/13] swap_lock replace list+device Hugh Dickins
2005-07-09  0:15 ` [PATCH 13/13] update swsusp use of swap_info Hugh Dickins
2005-07-09 11:13   ` [PATCH 14/13] swsusp mod needed parentheses Hugh Dickins

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.61.0507090107420.13391@goblin.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®