linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Subject: [PATCH 7/7] swapin: fix valid_swaphandles defect
Date: Sat, 6 Oct 2007 21:48:41 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0710062147540.16223@blonde.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0710062130400.16223@blonde.wat.veritas.com>

valid_swaphandles is supposed to do a quick pass over the swap map
entries neigbouring the entry which swapin_readahead is targetting,
to determine for it a range worth reading all together.  But since
it always starts its search from the beginning of the swap "cluster",
a reject (free entry) there immediately curtails the readaround, and
every swapin_readahead from that cluster is for just a single page.
Instead scan forwards and backwards around the target entry.

Use better names for some variables: a swap_info pointer is usually
called "si" not "swapdev".  And at the end, if only the target page
should be read, return count of 0 to disable readaround, to avoid
the unnecessarily repeated call to read_swap_cache_async.

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

 mm/swapfile.c |   49 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)

--- patch6/mm/swapfile.c	2007-10-04 19:24:36.000000000 +0100
+++ patch7/mm/swapfile.c	2007-10-04 19:24:46.000000000 +0100
@@ -1776,31 +1776,48 @@ get_swap_info_struct(unsigned type)
  */
 int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
 {
+	struct swap_info_struct *si;
 	int our_page_cluster = page_cluster;
-	int ret = 0, i = 1 << our_page_cluster;
-	unsigned long toff;
-	struct swap_info_struct *swapdev = swp_type(entry) + swap_info;
+	pgoff_t target, toff;
+	pgoff_t base, end;
+	int nr_pages = 0;
 
 	if (!our_page_cluster)	/* no readahead */
 		return 0;
-	toff = (swp_offset(entry) >> our_page_cluster) << our_page_cluster;
-	if (!toff)		/* first page is swap header */
-		toff++, i--;
-	*offset = toff;
+
+	si = &swap_info[swp_type(entry)];
+	target = swp_offset(entry);
+	base = (target >> our_page_cluster) << our_page_cluster;
+	end = base + (1 << our_page_cluster);
+	if (!base)		/* first page is swap header */
+		base++;
 
 	spin_lock(&swap_lock);
-	do {
-		/* Don't read-ahead past the end of the swap area */
-		if (toff >= swapdev->max)
+	if (end > si->max)	/* don't go beyond end of map */
+		end = si->max;
+
+	/* Count contiguous allocated slots above our target */
+	for (toff = target; ++toff < end; nr_pages++) {
+		/* Don't read in free or bad pages */
+		if (!si->swap_map[toff])
 			break;
+		if (si->swap_map[toff] == SWAP_MAP_BAD)
+			break;
+	}
+	/* Count contiguous allocated slots below our target */
+	for (toff = target; --toff >= base; nr_pages++) {
 		/* Don't read in free or bad pages */
-		if (!swapdev->swap_map[toff])
+		if (!si->swap_map[toff])
 			break;
-		if (swapdev->swap_map[toff] == SWAP_MAP_BAD)
+		if (si->swap_map[toff] == SWAP_MAP_BAD)
 			break;
-		toff++;
-		ret++;
-	} while (--i);
+	}
 	spin_unlock(&swap_lock);
-	return ret;
+
+	/*
+	 * Indicate starting offset, and return number of pages to get:
+	 * if only 1, say 0, since there's then no readahead to be done.
+	 */
+	*offset = ++toff;
+	return nr_pages? ++nr_pages: 0;
 }

--
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-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2007-10-06 20:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-06 20:35 [PATCH 0/7] swapin/shmem patches Hugh Dickins
2007-10-06 20:38 ` [PATCH 1/7] swapin_readahead: excise NUMA bogosity Hugh Dickins
2007-10-06 22:43   ` Rik van Riel
2007-10-07 22:05   ` Andi Kleen
2007-10-07 22:37     ` Rik van Riel
2007-10-08 17:31   ` Christoph Lameter
2007-10-08 17:35     ` Rik van Riel
2007-10-08 17:41       ` Christoph Lameter
2007-10-08 17:47         ` Rik van Riel
2007-10-08 17:52           ` Christoph Lameter
2007-10-08 18:48             ` Rik van Riel
2007-10-06 20:39 ` [PATCH 2/7] swapin_readahead: move and rearrange args Hugh Dickins
2007-10-07  2:26   ` Rik van Riel
2007-10-06 20:43 ` [PATCH 3/7] swapin needs gfp_mask for loop on tmpfs Hugh Dickins
2007-10-07 23:23   ` Rik van Riel
2007-10-08 13:52   ` Peter Zijlstra
2007-10-06 20:45 ` [PATCH 4/7] shmem: SGP_QUICK and SGP_FAULT redundant Hugh Dickins
2007-10-07 23:23   ` Rik van Riel
2007-10-06 20:46 ` [PATCH 5/7] shmem_getpage return page locked Hugh Dickins
2007-10-07  8:01   ` Nick Piggin
2007-10-08 12:05     ` Hugh Dickins
2007-10-08  7:08       ` Nick Piggin
2007-10-08  0:44   ` Rik van Riel
2007-10-06 20:47 ` [PATCH 6/7] shmem_file_write is redundant Hugh Dickins
2007-10-08  0:46   ` Rik van Riel
2007-10-06 20:48 ` Hugh Dickins [this message]
2007-10-08  1:14   ` [PATCH 7/7] swapin: fix valid_swaphandles defect 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.64.0710062147540.16223@blonde.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@linux-foundation.org \
    --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