From: Matthew Wilcox <willy@infradead.org>
To: Nhat Pham <nphamcs@gmail.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
bfoster@redhat.com, kernel-team@meta.com
Subject: Re: [PATCH v3 3/4] cachestat: implement cachestat syscall
Date: Mon, 12 Dec 2022 15:48:13 +0000 [thread overview]
Message-ID: <Y5dNPYVNyjHgGCD6@casper.infradead.org> (raw)
In-Reply-To: <20221208202808.908690-4-nphamcs@gmail.com>
On Thu, Dec 08, 2022 at 12:28:07PM -0800, Nhat Pham wrote:
> + struct address_space *mapping = f.file->f_mapping;
> + pgoff_t first_index = off >> PAGE_SHIFT;
> + pgoff_t last_index =
> + len == 0 ? ULONG_MAX : (off + len - 1) >> PAGE_SHIFT;
> + XA_STATE(xas, &mapping->i_pages, first_index);
> + struct folio *folio;
> +
> + rcu_read_lock();
> + xas_for_each(&xas, folio, last_index) {
> + if (xas_retry(&xas, folio) || !folio)
> + continue;
!folio can't be true. xas_for_each() terminates when folio is NULL.
> + if (xa_is_value(folio)) {
> + /* page is evicted */
> + void *shadow = (void *)folio;
> + bool workingset; /* not used */
> +
> + cs.nr_evicted += 1;
> +
> +#ifdef CONFIG_SWAP /* implies CONFIG_MMU */
> + if (shmem_mapping(mapping)) {
> + /* shmem file - in swap cache */
> + swp_entry_t swp = radix_to_swp_entry(folio);
> +
> + shadow = get_shadow_from_swap_cache(swp);
> + }
> +#endif
> + if (workingset_test_recent(shadow, true, &workingset))
> + cs.nr_recently_evicted += 1;
> +
> + continue;
> + }
> +
> + /* page is in cache */
> + cs.nr_cache += 1;
> +
> + if (folio_test_dirty(folio))
> + cs.nr_dirty += 1;
> +
> + if (folio_test_writeback(folio))
> + cs.nr_writeback += 1;
A folio may represent more than one page. That's the point of folios.
So there should be something in here which does
unsigned long nr = folio_nr_pages();
and then all these '1' should be 'nr'.
Except that you may need to adjust nr if 'first_index' > folio->index, or
'last_index' < folio->index + nr.
You should test this with XFS, AFS or erofs to be sure you're getting
results that look right.
next prev parent reply other threads:[~2022-12-12 15:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 20:28 [PATCH v3 0/4] cachestat: a new syscall for page cache state of files Nhat Pham
2022-12-08 20:28 ` [PATCH v3 1/4] workingset: fix confusion around eviction vs refault container Nhat Pham
2022-12-08 20:28 ` [PATCH v3 2/4] workingset: refactor LRU refault to expose refault recency check Nhat Pham
2022-12-09 8:15 ` kernel test robot
2022-12-09 9:56 ` kernel test robot
2022-12-09 17:29 ` Nhat Pham
2022-12-08 20:28 ` [PATCH v3 3/4] cachestat: implement cachestat syscall Nhat Pham
2022-12-08 22:30 ` Nhat Pham
2022-12-08 22:31 ` Nhat Pham
2022-12-12 15:48 ` Matthew Wilcox [this message]
2022-12-15 17:14 ` Nhat Pham
2023-01-16 10:08 ` Geert Uytterhoeven
2022-12-08 20:28 ` [PATCH v3 4/4] selftests: Add selftests for cachestat Nhat Pham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y5dNPYVNyjHgGCD6@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=bfoster@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox