From: Zi Yan <ziy@nvidia.com>
To: 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, Andrew Morton <akpm@linux-foundation.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 v4 3/5] selftests/mm: reimplement is_backed_by_thp() with more precise check
Date: Mon, 18 Aug 2025 10:44:18 -0400 [thread overview]
Message-ID: <02BE8434-25B0-4FD6-B1DD-0156FD5DCA1C@nvidia.com> (raw)
In-Reply-To: <c31e9dfd-019a-4d54-8237-8c3501c730a7@redhat.com>
On 18 Aug 2025, at 4:33, David Hildenbrand wrote:
> On 15.08.25 04:39, 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>
>> ---
>> .../selftests/mm/split_huge_page_test.c | 90 ++++++++++++++-----
>> tools/testing/selftests/mm/vm_util.c | 13 +++
>> tools/testing/selftests/mm/vm_util.h | 4 +
>> 3 files changed, 84 insertions(+), 23 deletions(-)
>>
>> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
>> index 89d3dc08fe4c..80f718ca21c7 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,27 +35,71 @@ 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)
>> #define GET_ORDER(nr_pages) (31 - __builtin_clz(nr_pages))
>> -static int is_backed_by_thp(char *vaddr, int pagemap_file, int kpageflags_file)
>> +static int is_backed_by_folio(char *vaddr, int order, int pagemap_fd,
>> + int kpageflags_fd)
>
> Could we convert this into a bool and simply return "false" on error instead of "-"? These tristate returns for a "is_*" function are a bit unfortunate.
OK.
>
>> {
>> - uint64_t paddr;
>> - uint64_t page_flags;
>> + unsigned long pfn_head;
>> + uint64_t pfn_flags;
>> + unsigned long pfn;
>> + unsigned long i;
>> - if (pagemap_file) {
>> - pread(pagemap_file, &paddr, sizeof(paddr),
>> - ((long)vaddr >> pageshift) * sizeof(paddr));
>> + if (pagemap_fd == -1 || kpageflags_fd == -1)
>> + goto fail;
>
> Should we rather expect that callers make sure these are valid? In particular, because split_pte_mapped_thp() seems to ksft_exit_fail_msg() already.
Sure.
>
>> - if (kpageflags_file) {
>> - pread(kpageflags_file, &page_flags, sizeof(page_flags),
>> - (paddr & PFN_MASK) * sizeof(page_flags));
>> + pfn = pagemap_get_pfn(pagemap_fd, vaddr);
>
> Hm, if it's swapped out we would get intermittent errors, but that just seems hard to avoid. The caller could mock to avoid swapout.
>
> Memory migration is another possible problem ...
>
> But this is nothing new regarding your patch, so no need to worry for now.
Right. The function is only used by PTE-mapped THP split and I assume swapping
and migration would not happen. If this function is used more broadly, it
will need to take care of cases.
>
> [...]
>
>> +int get_pfn_flags(unsigned long pfn, int kpageflags_fd, uint64_t *flags)
>> +{
>> + size_t count;
>> +
>> + count = pread(kpageflags_fd, flags, sizeof(*flags),
>> + pfn * sizeof(*flags));
>> +
>> + if (count != sizeof(*flags))
>> + return -1;
>> +
>> + return 0;
>> +}
>
> I would have called this function "pageflags_get()" to resemble "pagemap_get"
OK. Will rename it.
Thanks.
--
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2025-08-18 14:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 2:39 [PATCH v4 0/5] Better split_huge_page_test result check Zi Yan
2025-08-15 2:39 ` [PATCH v4 1/5] mm/huge_memory: add new_order and offset to split_huge_pages*() pr_debug Zi Yan
2025-08-15 2:39 ` [PATCH v4 2/5] selftests/mm: mark all functions static in split_huge_page_test.c Zi Yan
2025-08-15 3:03 ` Wei Yang
2025-08-15 3:26 ` wang lian
2025-08-18 7:56 ` David Hildenbrand
2025-08-15 2:39 ` [PATCH v4 3/5] selftests/mm: reimplement is_backed_by_thp() with more precise check Zi Yan
2025-08-15 3:14 ` Wei Yang
2025-08-15 5:40 ` wang lian
2025-08-16 7:30 ` Andrew Morton
2025-08-16 11:43 ` Zi Yan
2025-08-18 8:33 ` David Hildenbrand
2025-08-18 14:44 ` Zi Yan [this message]
2025-08-15 2:39 ` [PATCH v4 4/5] selftests/mm: add check_after_split_folio_orders() helper Zi Yan
2025-08-15 2:39 ` [PATCH v4 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=02BE8434-25B0-4FD6-B1DD-0156FD5DCA1C@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