Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals()
@ 2026-07-10 23:19 yahia
  2026-07-10 23:43 ` yahia
  0 siblings, 1 reply; 2+ messages in thread
From: yahia @ 2026-07-10 23:19 UTC (permalink / raw)
  To: willy, jack, akpm; +Cc: linux-fsdevel, linux-mm, yahia ahmed

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals()
  2026-07-10 23:19 [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals() yahia
@ 2026-07-10 23:43 ` yahia
  0 siblings, 0 replies; 2+ messages in thread
From: yahia @ 2026-07-10 23:43 UTC (permalink / raw)
  To: willy, jack, akpm; +Cc: linux-fsdevel, linux-mm

Hi,

Please drop this patch as the condition
i was evaluating can't occur.

Best regards,
yahia


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-10 23:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 23:19 [PATCH] mm: truncate: exit on empty batches in truncate_folio_batch_exceptionals() yahia
2026-07-10 23:43 ` yahia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox