mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Chi Zhiling <chizhiling@163.com>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Jan Kara <jack@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hugh Dickins <hughd@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chi Zhiling <chizhiling@kylinos.cn>
Subject: Re: [PATCH v2 1/5] mm/filemap: reduce unnecessary xarray lookups when read cached pages
Date: Mon, 1 Jun 2026 13:51:17 +0100	[thread overview]
Message-ID: <ah2ARWo_EiVOaWDI@casper.infradead.org> (raw)
In-Reply-To: <20260601055704.167436-2-chizhiling@163.com>

On Mon, Jun 01, 2026 at 01:57:00PM +0800, Chi Zhiling wrote:
> From: Chi Zhiling <chizhiling@kylinos.cn>
> 
> When reading small amounts of data from the page cache, only a single
> folio is typically returned from filemap_read_get_batch(). In this case,
> calling xas_advance() or xas_next() after adding the folio to the batch
> is unnecessary and only introduces extra branches.

I don't think xas_advance() is all that expensive.  The expensive part
is going to be calling xas_next() and realising that the folio now lies
beyond the required range.  I think you'll get just as much benefit from
doing this:

diff --git a/mm/filemap.c b/mm/filemap.c
index 4e636647100c..578b03bd5514 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2459,11 +2459,14 @@ static void filemap_get_read_batch(struct address_space *mapping,
 	XA_STATE(xas, &mapping->i_pages, index);
 	struct folio *folio;
 
+	if (index > max)
+		return;
+
 	rcu_read_lock();
 	for (folio = xas_load(&xas); folio; folio = xas_next(&xas)) {
 		if (xas_retry(&xas, folio))
 			continue;
-		if (xas.xa_index > max || xa_is_value(folio))
+		if (xa_is_value(folio))
 			break;
 		if (xa_is_sibling(folio))
 			break;
@@ -2480,6 +2483,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
 		if (folio_test_readahead(folio))
 			break;
 		xas_advance(&xas, folio_next_index(folio) - 1);
+		if (xas.index >= max)
+			break;
 		continue;
 put_folio:
 		folio_put(folio);
> 

  reply	other threads:[~2026-06-01 12:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01  5:56 [PATCH v2 0/5] mm/shmem: optimize read with reduced xarray lookups and folio batching Chi Zhiling
2026-06-01  5:57 ` [PATCH v2 1/5] mm/filemap: reduce unnecessary xarray lookups when read cached pages Chi Zhiling
2026-06-01 12:51   ` Matthew Wilcox [this message]
2026-06-01 14:39     ` Chi Zhiling
2026-06-01  5:57 ` [PATCH v2 2/5] mm/filemap: reduce xarray lookups in filemap_get_folios_contig() Chi Zhiling
2026-06-01  5:57 ` [PATCH v2 3/5] mm/shmem: introduce copy_zero_to_iter() for large zeroing Chi Zhiling
2026-06-01 13:22   ` Matthew Wilcox
2026-06-01 14:57     ` Chi Zhiling
2026-06-01 15:02     ` Mateusz Guzik
2026-06-01 15:11       ` Mateusz Guzik
2026-06-01 15:13       ` Matthew Wilcox
2026-06-01 15:40         ` Mateusz Guzik
2026-06-01 22:03       ` David Laight
2026-06-01  5:57 ` [PATCH v2 4/5] mm/shmem: remove page-copy fallback in shmem read path Chi Zhiling
2026-06-02  5:39   ` Baolin Wang
2026-06-02  6:17     ` Chi Zhiling
2026-06-01  5:57 ` [PATCH v2 5/5] mm/shmem: optimize file read with folio batching Chi Zhiling
2026-06-01 13:59   ` Matthew Wilcox
2026-06-01 15:00     ` Chi Zhiling
2026-06-02  5:54   ` Baolin Wang
2026-06-02  6:58     ` Chi Zhiling
2026-06-01  7:16 ` [PATCH v2 0/5] mm/shmem: optimize read with reduced xarray lookups and " Chi Zhiling
2026-06-02  0:43 ` Andrew Morton
2026-06-02  2:44   ` Chi Zhiling

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=ah2ARWo_EiVOaWDI@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chizhiling@163.com \
    --cc=chizhiling@kylinos.cn \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

Powered by JetHome