Re: [PATCH 1/3] fs, mm: add ->cachestat() file operation

From: Pavel Tikhomirov

Date: Wed Jun 24 2026 - 07:49:19 EST




On 6/23/26 18:01, Nhat Pham wrote:
> On Tue, Jun 23, 2026 at 4:15 AM Pavel Tikhomirov
> <ptikhomirov@xxxxxxxxxxxxx> wrote:
>>
>> The cachestat() syscall reads page cache statistics straight from the
>> file's f_mapping. Stackable filesystems such as overlayfs keep the data
>> pages in an underlying inode's mapping rather than in the overlay
>> inode's, so cachestat() reports all zeroes for them.
>>
>> Add a ->cachestat() file operation and route the syscall through a new
>> vfs_cachestat() helper that calls it when present, falling back to
>> file's f_mapping otherwise. This lets stackable filesystems forward the
>> query to the file that actually owns the page cache. No behaviour change
>> for regular files.
>>
>> Signed-off-by: Pavel Tikhomirov <ptikhomirov@xxxxxxxxxxxxx>
>> ---
>> Note: Memset change might be a bit tricky, I moved it to no
>> ->cachestat() path to avoid multiple memset on nested overlayfs, that
>> means that ->cachestat() is expected to be able to handle unitialized
>> cs.
>
> nit: maybe a comment somewhere to document this?

Sure, will do in v2.

>
>> ---
>> include/linux/fs.h | 10 ++++++++++
>> mm/filemap.c | 43 +++++++++++++++++++++++++++++++++++--------
>> 2 files changed, 45 insertions(+), 8 deletions(-)
>>
>
> LGTM otherwise. With Amir's suggestions incorporated:
>
> Acked-by: Nhat Pham <nphamcs@xxxxxxxxx>

--
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.