Skip to content

Commit

Permalink
mm/truncate: reset xa_has_values flag on each iteration
Browse files Browse the repository at this point in the history
Currently mapping_try_invalidate() and invalidate_inode_pages2_range()
traverses the xarray in batches and then for each batch, maintains and
sets the flag named xa_has_values if the batch has a shadow entry to clear
the entries at the end of the iteration.

However they forgot to reset the flag at the end of the iteration which
causes them to always try to clear the shadow entries in the subsequent
iterations where there might not be any shadow entries.

Fix this inefficiency.

Link: https://lkml.kernel.org/r/20241002225150.2334504-1-shakeel.butt@linux.dev
Fixes: 61c663e ("mm/truncate: batch-clear shadow entries")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Yu Zhao <yuzhao@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Shakeel Butt authored and Andrew Morton committed Nov 7, 2024
1 parent e26060d commit 5f5a3e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mm/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,
unsigned long ret;
unsigned long count = 0;
int i;
bool xa_has_values = false;

folio_batch_init(&fbatch);
while (find_lock_entries(mapping, &index, end, &fbatch, indices)) {
bool xa_has_values = false;
int nr = folio_batch_count(&fbatch);

for (i = 0; i < nr; i++) {
Expand Down Expand Up @@ -592,14 +592,14 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
int ret = 0;
int ret2 = 0;
int did_range_unmap = 0;
bool xa_has_values = false;

if (mapping_empty(mapping))
return 0;

folio_batch_init(&fbatch);
index = start;
while (find_get_entries(mapping, &index, end, &fbatch, indices)) {
bool xa_has_values = false;
int nr = folio_batch_count(&fbatch);

for (i = 0; i < nr; i++) {
Expand Down

0 comments on commit 5f5a3e9

Please sign in to comment.