From: Nhat Pham <nphamcs@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
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: Thu, 15 Dec 2022 09:14:15 -0800 [thread overview]
Message-ID: <CAKEwX=Pb8npL9p9bkeEnudp1FsLJ_HydabNDg9J8evD+qV9coQ@mail.gmail.com> (raw)
In-Reply-To: <Y5dNPYVNyjHgGCD6@casper.infradead.org>
On Mon, Dec 12, 2022 at 7:48 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> 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.
Good to know - I'll remove this in the next version.
>
> > + 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'.
Yikes, that's a bug that I missed! Thanks for pointing it out.
> Except that you may need to adjust nr if 'first_index' > folio->index, or
> 'last_index' < folio->index + nr.
Sounds good!
>
> 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-15 17:14 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
2022-12-15 17:14 ` Nhat Pham [this message]
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='CAKEwX=Pb8npL9p9bkeEnudp1FsLJ_HydabNDg9J8evD+qV9coQ@mail.gmail.com' \
--to=nphamcs@gmail.com \
--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=willy@infradead.org \
/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