From: Zi Yan <ziy@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
wang lian <lianux.mm@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
linux-mm@kvack.org, Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v5 3/5] selftests/mm: reimplement is_backed_by_thp() with more precise check
Date: Tue, 19 Aug 2025 12:58:51 -0400 [thread overview]
Message-ID: <F54782D6-65A3-4D35-AE03-8ADE636EE258@nvidia.com> (raw)
In-Reply-To: <B8ADCDEA-DB05-4843-983E-A66DE78AD1D6@nvidia.com>
On 19 Aug 2025, at 12:50, Zi Yan wrote:
> On 19 Aug 2025, at 4:54, David Hildenbrand wrote:
>
>> On 18.08.25 20:46, Zi Yan wrote:
>>> and rename it to is_backed_by_folio().
>>>
>>> is_backed_by_folio() checks if the given vaddr is backed a folio with
>>> a given order. It does so by:
>>> 1. getting the pfn of the vaddr;
>>> 2. checking kpageflags of the pfn;
>>>
>>> if order is greater than 0:
>>> 3. checking kpageflags of the head pfn;
>>> 4. checking kpageflags of all tail pfns.
>>>
>>> pmd_order is added to split_huge_page_test.c and replaces max_order.
>>>
>>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>>> Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
>>> Reviewed-by: wang lian <lianux.mm@gmail.com>
>>> ---
>>> .../selftests/mm/split_huge_page_test.c | 88 ++++++++++++++-----
>>> tools/testing/selftests/mm/vm_util.c | 13 +++
>>> tools/testing/selftests/mm/vm_util.h | 4 +
>>> 3 files changed, 81 insertions(+), 24 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
>>> index 089e146efeab..56d1eaf9a860 100644
>>> --- a/tools/testing/selftests/mm/split_huge_page_test.c
>>> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
>>> @@ -25,6 +25,7 @@
>>> uint64_t pagesize;
>>> unsigned int pageshift;
>>> uint64_t pmd_pagesize;
>>> +unsigned int pmd_order;
>>> #define SPLIT_DEBUGFS "/sys/kernel/debug/split_huge_pages"
>>> #define SMAP_PATH "/proc/self/smaps"
>>> @@ -34,26 +35,66 @@ uint64_t pmd_pagesize;
>>> #define PID_FMT_OFFSET "%d,0x%lx,0x%lx,%d,%d"
>>> #define PATH_FMT "%s,0x%lx,0x%lx,%d"
>>> -#define PFN_MASK ((1UL<<55)-1)
>>> -#define KPF_THP (1UL<<22)
>>> -
>>> -static int is_backed_by_thp(char *vaddr, int pagemap_file, int kpageflags_file)
>>> +static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
>>> + int kpageflags_fd)
>>> {
>>> - uint64_t paddr;
>>> - uint64_t page_flags;
>>> + unsigned long pfn_head;
>>> + uint64_t pfn_flags;
>>> + unsigned long pfn;
>>> + unsigned long i;
>>
>> Final nit (sorry!) :)
>>
>> const unsigned long nr_pages = 1ul << order;
>>
>> so you can make some of the code below easier to read.
>
> Sure. Will send a fixup.
>
>>
>> Acked-by: David Hildenbrand <david@redhat.com>
>>
> Thanks.
Hi Andrew,
The fixup below replaced 1 << order with nr_pages based on David's
suggestion. Do you mind folding it in?
Thanks.
From c07eb882465b938a70acb84e4cdc5b6598536322 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Tue, 19 Aug 2025 12:52:13 -0400
Subject: [PATCH] fixup: selftests/mm: use nr_pages instead of 1UL << order.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
tools/testing/selftests/mm/split_huge_page_test.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 56d1eaf9a860..f2882cfab568 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -38,6 +38,7 @@ unsigned int pmd_order;
static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
int kpageflags_fd)
{
+ const unsigned long nr_pages = 1UL << order;
unsigned long pfn_head;
uint64_t pfn_flags;
unsigned long pfn;
@@ -63,7 +64,7 @@ static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
if (!(pfn_flags & KPF_THP))
return false;
- pfn_head = pfn & ~((1 << order) - 1);
+ pfn_head = pfn & ~(nr_pages - 1);
if (pageflags_get(pfn_head, kpageflags_fd, &pfn_flags))
goto fail;
@@ -73,7 +74,7 @@ static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
return false;
/* check all tail PFN flags */
- for (i = 1; i < 1UL << order; i++) {
+ for (i = 1; i < nr_pages; i++) {
if (pageflags_get(pfn_head + i, kpageflags_fd, &pfn_flags))
goto fail;
if (!(pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL)))
@@ -84,7 +85,7 @@ static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
* check the PFN after this folio, but if its flags cannot be obtained,
* assume this folio has the expected order
*/
- if (pageflags_get(pfn_head + (1UL << order), kpageflags_fd, &pfn_flags))
+ if (pageflags_get(pfn_head + nr_pages, kpageflags_fd, &pfn_flags))
return true;
/* this folio is bigger than the given order */
--
2.50.1
--
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2025-08-19 16:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 18:46 [PATCH v5 0/5] Better split_huge_page_test result check Zi Yan
2025-08-18 18:46 ` [PATCH v5 1/5] mm/huge_memory: add new_order and offset to split_huge_pages*() pr_debug Zi Yan
2025-08-18 18:46 ` [PATCH v5 2/5] selftests/mm: mark all functions static in split_huge_page_test.c Zi Yan
2025-08-18 18:46 ` [PATCH v5 3/5] selftests/mm: reimplement is_backed_by_thp() with more precise check Zi Yan
2025-08-19 8:54 ` David Hildenbrand
2025-08-19 16:50 ` Zi Yan
2025-08-19 16:58 ` Zi Yan [this message]
2025-08-18 18:46 ` [PATCH v5 4/5] selftests/mm: add check_after_split_folio_orders() helper Zi Yan
2025-08-20 9:22 ` Baolin Wang
2025-08-20 13:49 ` Zi Yan
2025-08-21 1:11 ` Baolin Wang
2025-08-18 18:46 ` [PATCH v5 5/5] selftests/mm: check after-split folio orders in split_huge_page_test Zi Yan
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=F54782D6-65A3-4D35-AE03-8ADE636EE258@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=npache@redhat.com \
--cc=richard.weiyang@gmail.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/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