linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: <linux-mm@kvack.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	<linux-fsdevel@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 10/10] readahead: Simplify gotos in page_cache_sync_ra()
Date: Tue, 25 Jun 2024 12:19:00 +0200	[thread overview]
Message-ID: <20240625101909.12234-10-jack@suse.cz> (raw)
In-Reply-To: <20240625100859.15507-1-jack@suse.cz>

Unify all conditions for initial readahead to simplify goto logic in
page_cache_sync_ra(). No functional changes.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/readahead.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/mm/readahead.c b/mm/readahead.c
index 12c0d2215329..d68d5ce657a7 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -532,20 +532,19 @@ void page_cache_sync_ra(struct readahead_control *ractl,
 	}
 
 	max_pages = ractl_max_pages(ractl, req_count);
+	prev_index = (unsigned long long)ra->prev_pos >> PAGE_SHIFT;
 	/*
-	 * start of file or oversized read
-	 */
-	if (!index || req_count > max_pages)
-		goto initial_readahead;
-
-	/*
-	 * sequential cache miss
+	 * A start of file, oversized read, or sequential cache miss:
 	 * trivial case: (index - prev_index) == 1
 	 * unaligned reads: (index - prev_index) == 0
 	 */
-	prev_index = (unsigned long long)ra->prev_pos >> PAGE_SHIFT;
-	if (index - prev_index <= 1UL)
-		goto initial_readahead;
+	if (!index || req_count > max_pages || index - prev_index <= 1UL) {
+		ra->start = index;
+		ra->size = get_init_ra_size(req_count, max_pages);
+		ra->async_size = ra->size > req_count ? ra->size - req_count :
+							ra->size >> 1;
+		goto readit;
+	}
 
 	/*
 	 * Query the page cache and look for the traces(cached history pages)
@@ -572,13 +571,6 @@ void page_cache_sync_ra(struct readahead_control *ractl,
 	ra->start = index;
 	ra->size = min(contig_count + req_count, max_pages);
 	ra->async_size = 1;
-	goto readit;
-
-initial_readahead:
-	ra->start = index;
-	ra->size = get_init_ra_size(req_count, max_pages);
-	ra->async_size = ra->size > req_count ? ra->size - req_count :
-						ra->size >> 1;
 readit:
 	ractl->_index = ra->start;
 	page_cache_ra_order(ractl, ra, 0);
-- 
2.35.3



  parent reply	other threads:[~2024-06-25 10:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25 10:18 [PATCH 0/10] mm: Fix various readahead quirks Jan Kara
2024-06-25 10:18 ` [PATCH 01/10] readahead: Make sure sync readahead reads needed page Jan Kara
2024-06-25 10:18 ` [PATCH 02/10] filemap: Fix page_cache_next_miss() when no hole found Jan Kara
2024-06-25 10:18 ` [PATCH 03/10] readahead: Properly shorten readahead when falling back to do_page_cache_ra() Jan Kara
2024-06-25 10:18 ` [PATCH 04/10] readahead: Drop pointless index from force_page_cache_ra() Jan Kara
2024-06-25 10:18 ` [PATCH 05/10] readahead: Drop index argument of page_cache_async_readahead() Jan Kara
2024-06-25 10:18 ` [PATCH 06/10] readahead: Drop dead code in page_cache_ra_order() Jan Kara
2024-06-25 10:18 ` [PATCH 07/10] readahead: Drop dead code in ondemand_readahead() Jan Kara
2024-06-25 10:18 ` [PATCH 08/10] readahead: Disentangle async and sync readahead Jan Kara
2024-06-25 10:18 ` [PATCH 09/10] readahead: Fold try_context_readahead() into its single caller Jan Kara
2024-06-25 10:19 ` Jan Kara [this message]
2024-06-25 17:12 ` [PATCH 0/10] mm: Fix various readahead quirks Josef Bacik
2024-06-27  3:04 ` Zhang Peng
2024-06-27  6:10   ` zippermonkey
2024-06-27 21:13     ` Andrew Morton

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=20240625101909.12234-10-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.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