Re: [PATCH v5 2/3] cachestat: implement cachestat syscall

Hillf Danton
2023-01-11T23:53:47Z

On 4 Jan 2023 15:11:26 -0800 Nhat Pham <nphamcs@gmail.com>
> Implement a new syscall that queries cache state of a file and
> summarizes the number of cached pages, number of dirty pages, number of
> pages marked for writeback, number of (recently) evicted pages, etc. in
> a given range.

Feel free to add why. Do copy-and-paste if it is in the cover letter.
>
> +/**
> + * filemap_cachestat() - compute the page cache statistics of a mapping
> + * @mapping: The mapping to compute the statistics for.
> + * @first_index: The starting page cache index.
> + * @last_index: The final page index (inclusive).
> + * @cs: the cachestat struct to write the result to.
> + *
> + * This will query the page cache statistics of a mapping in the
> + * page range of [first_index, last_index] (inclusive). The statistics
> + * queried include: number of dirty pages, number of pages marked for
> + * writeback, and the number of (recently) evicted pages.
> + */
> +void filemap_cachestat(struct address_space *mapping, pgoff_t first_index,
> + pgoff_t last_index, struct cachestat *cs)
> +{
> + XA_STATE(xas, &mapping->i_pages, first_index);
> + struct folio *folio;
> +
> + rcu_read_lock();
> + xas_for_each(&xas, folio, last_index) {

It does not make sense to take more than two ticks to walk the xarray
with rcu read lock held.

Add stats to mapping instead if CONFIG_CACHESTAT_SYSCALL is enabled, in
case of difficulty handling rcu read lock.