From: "Alex Zhu (Kernel)" <alexlzhu@fb.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
Kernel Team <Kernel-team@fb.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH v2] mm: add thp_utilization metrics to debugfs
Date: Wed, 10 Aug 2022 19:14:11 +0000 [thread overview]
Message-ID: <9215F2F7-8354-4A86-B5DF-A82ED75B3BCD@fb.com> (raw)
In-Reply-To: <YvJiG3oviaRgPSVC@casper.infradead.org>
> On Aug 9, 2022, at 6:33 AM, Matthew Wilcox <willy@infradead.org> wrote:
>
> >
> On Mon, Aug 08, 2022 at 06:49:50PM -0700, alexlzhu@fb.com wrote:
>> +int thp_number_utilized_pages(struct page *page)
>> +{
>> + unsigned long page_index, page_offset, value;
>> + int thp_nr_utilized_pages = HPAGE_PMD_NR;
>> + int step_size = sizeof(unsigned long);
>> + bool is_all_zeroes;
>> + void *kaddr;
>> +
>> + if (!page || !is_anon_transparent_hugepage(page))
>> + return -1;
>> +
>> + kaddr = kmap_local_page(compound_head(page));
>> + for (page_index = 0; page_index < HPAGE_PMD_NR; page_index++) {
>> + is_all_zeroes = true;
>> + for (page_offset = 0; page_offset < PAGE_SIZE; page_offset += step_size) {
>> + value = *(unsigned long *)(kaddr + page_index * PAGE_SIZE + page_offset);
>> + if (value != 0) {
>> + is_all_zeroes = false;
>> + break;
>> + }
>> + }
>> + if (is_all_zeroes)
>> + thp_nr_utilized_pages--;
>> + }
>> + kunmap_local(kaddr);
>
> You haven't tested this on 32-bit maachines with HIGHMEM, have you?
> kmap_local_page() only maps PAGE_SIZE bytes, so you need to map it and
> unmap each page. Also, why are you calling compound_head()? Surely
> you're already assuming that page is a head page here?
>
> (this is why I introduced the struct folio type, so you know whether
> a pointer is already to a head page and you don't need to call
> compound_head() again).
>
I see. Thanks for catching this! I have reimplemented with folio in a way that will work on 32 bit
architectures with HIGHMEM. Will send out v3.
prev parent reply other threads:[~2022-08-10 19:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-09 1:49 alexlzhu
2022-08-09 13:33 ` Matthew Wilcox
2022-08-10 19:14 ` Alex Zhu (Kernel) [this message]
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=9215F2F7-8354-4A86-B5DF-A82ED75B3BCD@fb.com \
--to=alexlzhu@fb.com \
--cc=Kernel-team@fb.com \
--cc=akpm@linux-foundation.org \
--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