Re: [PATCH 1/3] fs, mm: add ->cachestat() file operation
From: Nhat Pham
Date: Tue Jun 23 2026 - 12:01:31 EST
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?
> ---
> 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>