Re: [PATCH] mm/shmem: remove truncated folios from the page cache in batches
From: David Hildenbrand (Arm)
Date: Tue Nov 03 2026 - 03:29:37 EST
On 10/30/26 04:44, Qiliang Yuan wrote:
> truncate_inode_pages_range() takes the folios it finds out of the page
> cache with delete_from_page_cache_batch(), which takes the inode's
> i_lock and the i_pages lock once for each batch of up to
> FOLIO_BATCH_SIZE folios.
>
> shmem_undo_range() calls truncate_inode_folio() on each folio instead,
> so filemap_remove_folio() takes and drops both locks once per folio.
> Truncating, punching or freeing a tmpfs file or memfd made of small
> folios, such as a large /dev/shm segment, pays for that on every page.
>
> Clean each folio up as truncate_inode_folio() does, collect the ones to
> remove and take them out with delete_from_page_cache_batch(), which
> needs truncate_cleanup_folio() outside mm/truncate.c. Swap entries, and
> the folios kept when undoing a failed fallocate(), stay out of the
> batch. Dropping an 8 GiB file of 4K folios, median of five runs,
> averaged over two boots of each kernel, in a 32 vCPU VM:
>
> before after
> ftruncate() to 0 1163 ms 913 ms
> hole punch 1155 ms 914 ms
> close() of a memfd 1161 ms 914 ms
> unlink() 1162 ms 916 ms
>
> Files of PMD-sized folios take 20-25 ms with or without this change.
>
> Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
> ---
Doesn't look like something earth shattering :)
I'll wait a couple of days for more review and will then pick this up.
--
Cheers,
David