[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YvJiG3oviaRgPSVC@casper.infradead.org>
Date: Tue, 9 Aug 2022 14:33:15 +0100
From: Matthew Wilcox <willy@...radead.org>
To: alexlzhu@...com
Cc: linux-mm@...ck.org, kernel-team@...com,
linux-kernel@...r.kernel.org, akpm@...ux-foundation.org
Subject: Re: [PATCH v2] mm: add thp_utilization metrics to debugfs
On Mon, Aug 08, 2022 at 06:49:50PM -0700, alexlzhu@...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).
Powered by blists - more mailing lists