linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rik van Riel <riel@surriel.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, kernel-team@fb.com, niketa@fb.com,
	akpm@linux-foundation.org, sjenning@redhat.com,
	ddstreet@ieee.org, konrad.wilk@oracle.com, hannes@cmpxchg.org,
	Rik van Riel <riel@surriel.com>
Subject: [PATCH 1/2] mm,swap: extract swap single page readahead into its own function
Date: Mon, 21 Sep 2020 22:01:47 -0400	[thread overview]
Message-ID: <20200922020148.3261797-2-riel@surriel.com> (raw)
In-Reply-To: <20200922020148.3261797-1-riel@surriel.com>

Split swap single page readahead into its own function, to make
the next patch easier to read. No functional changes.

Signed-off-by: Rik van Riel <riel@surriel.com>
---
 mm/swap_state.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index c16eebb81d8b..aacb9ba53f63 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -594,6 +594,28 @@ static unsigned long swapin_nr_pages(unsigned long offset)
 	return pages;
 }
 
+static struct page *swap_cluster_read_one(swp_entry_t entry,
+		unsigned long offset, gfp_t gfp_mask,
+		struct vm_area_struct *vma, unsigned long addr, bool readahead)
+{
+	bool page_allocated;
+	struct page *page;
+
+	page =__read_swap_cache_async(swp_entry(swp_type(entry), offset),
+				      gfp_mask, vma, addr, &page_allocated);
+	if (!page)
+		return NULL;
+	if (page_allocated) {
+		swap_readpage(page, false);
+		if (readahead) {
+			SetPageReadahead(page);
+			count_vm_event(SWAP_RA);
+		}
+	}
+	put_page(page);
+	return page;
+}
+
 /**
  * swap_cluster_readahead - swap in pages in hope we need them soon
  * @entry: swap entry of this memory
@@ -615,14 +637,13 @@ static unsigned long swapin_nr_pages(unsigned long offset)
 struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
 				struct vm_fault *vmf)
 {
-	struct page *page;
 	unsigned long entry_offset = swp_offset(entry);
 	unsigned long offset = entry_offset;
 	unsigned long start_offset, end_offset;
 	unsigned long mask;
 	struct swap_info_struct *si = swp_swap_info(entry);
 	struct blk_plug plug;
-	bool do_poll = true, page_allocated;
+	bool do_poll = true;
 	struct vm_area_struct *vma = vmf->vma;
 	unsigned long addr = vmf->address;
 
@@ -649,19 +670,8 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
 	blk_start_plug(&plug);
 	for (offset = start_offset; offset <= end_offset ; offset++) {
 		/* Ok, do the async read-ahead now */
-		page = __read_swap_cache_async(
-			swp_entry(swp_type(entry), offset),
-			gfp_mask, vma, addr, &page_allocated);
-		if (!page)
-			continue;
-		if (page_allocated) {
-			swap_readpage(page, false);
-			if (offset != entry_offset) {
-				SetPageReadahead(page);
-				count_vm_event(SWAP_RA);
-			}
-		}
-		put_page(page);
+		swap_cluster_read_one(entry, offset, gfp_mask, vma, addr,
+				      offset != entry_offset);
 	}
 	blk_finish_plug(&plug);
 
-- 
2.25.4



  reply	other threads:[~2020-09-22  2:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  2:01 [PATCH 0/2] mm,swap: skip swap readahead for instant IO (like zswap) Rik van Riel
2020-09-22  2:01 ` Rik van Riel [this message]
2020-09-23  6:32   ` [PATCH 1/2] mm,swap: extract swap single page readahead into its own function Christoph Hellwig
2020-09-23  8:02     ` Hillf Danton
2020-09-22  2:01 ` [PATCH 2/2] mm,swap: skip swap readahead if page was obtained instantaneously Rik van Riel
2020-09-22  3:13   ` huang ying
2020-09-22 11:33     ` Rik van Riel
2020-09-23  6:35   ` Christoph Hellwig
2020-09-22 17:12 ` [PATCH 0/2] mm,swap: skip swap readahead for instant IO (like zswap) Andrew Morton
2020-10-05 17:32   ` Rik van Riel
2020-10-09 14:38     ` 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=20200922020148.3261797-2-riel@surriel.com \
    --to=riel@surriel.com \
    --cc=akpm@linux-foundation.org \
    --cc=ddstreet@ieee.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=niketa@fb.com \
    --cc=sjenning@redhat.com \
    /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