Re: [PATCH v2] mm/shmem: remove truncated folios from the page cache in batches
From: David Hildenbrand (Arm)
Date: Thu Nov 05 2026 - 14:55:07 EST
On 11/5/26 13:32, 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 1150 ms 917 ms
> hole punch 1165 ms 919 ms
> close() of a memfd 1153 ms 921 ms
> unlink() 1152 ms 921 ms
>
> Files of PMD-sized folios take 18-27 ms with or without this change.
>
> Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
> Reviewed-by: Jan Kara <jack@xxxxxxx>
> Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
> ---
Thanks, I'll wait a couple of days and will then queue this.
--
Cheers,
David