From: yahia ahmed 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 --- 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