mm: optimize invalidation of shadow entries
authorShakeel Butt <shakeel.butt@linux.dev>
Wed, 25 Sep 2024 22:47:16 +0000 (15:47 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 6 Nov 2024 00:56:30 +0000 (16:56 -0800)
commitd3db2c0425915f6b0f273770feee2e2f97dba6a3
tree618a9e1a411844df72547b8d610b1b856e45950e
parentcb8e64be7681b857f4976378ece542b3e18a8484
mm: optimize invalidation of shadow entries

The kernel invalidates the page cache in batches of PAGEVEC_SIZE.  For
each batch, it traverses the page cache tree and collects the entries
(folio and shadow entries) in the struct folio_batch.  For the shadow
entries present in the folio_batch, it has to traverse the page cache tree
for each individual entry to remove them.  This patch optimize this by
removing them in a single tree traversal.

To evaluate the changes, we created 200GiB file on a fuse fs and in a
memcg.  We created the shadow entries by triggering reclaim through
memory.reclaim in that specific memcg and measure the simple
fadvise(DONTNEED) operation.

 # time xfs_io -c 'fadvise -d 0 ${file_size}' file

              time (sec)
Without       5.12 +- 0.061
With-patch    4.19 +- 0.086 (18.16% decrease)

Link: https://lkml.kernel.org/r/20240925224716.2904498-3-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Chris Mason <clm@fb.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/truncate.c