Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: yahia <yahia.a.abdrabou@gmail.com>
To: willy@infradead.org, jack@suse.cz, akpm@linux-foundation.org
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	yahia ahmed <yahia.a.abdrabou@gmail.com>
Subject: [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals()
Date: Sat, 11 Jul 2026 02:19:30 +0300	[thread overview]
Message-ID: <20260710231930.93427-1-yahia.a.abdrabou@gmail.com> (raw)

From: yahia ahmed <yahia.a.abdrabou@gmail.com>

In truncate_folio_batch_exceptionals(), a loop scans for a shadow
entry via xa_is_value(), However, most batches sent contain valid
pages that don't require exceptional truncation.

When a batch is empty (nr <= 0), the loop and the following check
are redundant, adding an early check like if (nr <= 0) allows exiting
the function before executing any loop or redundant if.

In benchmarking, truncating 1000 files went from an initial 0.77
seconds to 0.76 seconds.

Signed-off-by: yahia ahmed <yahia.a.abdrabou@gmail.com>
---
 mm/truncate.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/truncate.c b/mm/truncate.c
index b58ba940be47..c22803d59bf0 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -69,6 +69,9 @@ static void truncate_folio_batch_exceptionals(struct address_space *mapping,
 	if (shmem_mapping(mapping))
 		return;
 
+	if (likely(nr <= 0))
+		return;
+
 	for (j = 0; j < nr; j++)
 		if (xa_is_value(fbatch->folios[j]))
 			break;
-- 
2.55.0



             reply	other threads:[~2026-07-10 23:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 23:19 yahia [this message]
2026-07-10 23:43 ` [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals() yahia

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=20260710231930.93427-1-yahia.a.abdrabou@gmail.com \
    --to=yahia.a.abdrabou@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --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