From: Sarthak Sharma <sarthak.sharma@arm.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
Leon Romanovsky <leon@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Mark Brown <broonie@kernel.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 6/6] selftests/mm: add a GUP selftest
Date: Tue, 4 Aug 2026 13:08:05 +0530 [thread overview]
Message-ID: <34e3932c-aaf1-4b69-a3c4-398784aae290@arm.com> (raw)
In-Reply-To: <178574760162.1561566.17560239060453947110.b4-review@b4>
Hi Mike!
On 8/3/26 2:30 PM, Mike Rapoport wrote:
>> Add a new GUP selftest which uses kselftest_harness.h. Cover
>> 12 mapping configurations: THP enabled, THP disabled and
>> HugeTLB, each across private/shared mappings and with/without
>> FOLL_WRITE. Run 7 testcases for every variant: get_user_pages,
>> get_user_pages_fast, pin_user_pages, pin_user_pages_fast,
>> pin_user_pages_longterm, and DUMP_USER_PAGES_TEST using both
>> get and pin.
>>
>> Sweep four nr_pages_per_call values for each test: 1, 512, 123 and
>> all pages. This preserves the coverage previously provided by
>> run_gup_matrix(): 12 mapping combinations x 5 GUP/PUP operations x 4
>> batch sizes, for 240 ioctl calls. The two dump modes add another 96
>> calls.
>>
>> Preserve the previous sparse dump coverage with a standalone test for
>> pages 0, 19 and 0x1000. In total the selftest reports 85 TAP
>> cases and issues 337 ioctls.
>>
>> Add the new gup binary to the selftests/mm build, .gitignore,
>> run_vmtests.sh and MAINTAINERS. Update
>> Documentation/core-api/pin_user_pages.rst for the new test.
>>
>> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
>> Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
>>
>> +
>> +FIXTURE_SETUP(gup_test)
>> +{
>> + int mmap_flags = MAP_PRIVATE;
>> + int zero_fd;
>> + char *p;
>> +
>> + /* zero_fd has to be >= 0. Already checked in main() */
>> + zero_fd = open("/dev/zero", O_RDWR);
>> + ASSERT_GE(zero_fd, 0);
>> +
>> + /* gup_fd has to be >= 0. Already checked in main() */
>> + self->gup_fd = open(GUP_TEST_FILE, O_RDWR);
>> + ASSERT_GE(self->gup_fd, 0);
>> +
>> + self->size = variant->hugetlb ? 256 * MB : 128 * MB;
>
> I'd derive the hugetbl variant size from the size of a huge page and
> predefined number of huge pages.
>
I was following the existing logic that run_gup_matrix() had. I can
implement this. Any suggestions what number of huge pages we can fix?
>> +
>> + if (variant->hugetlb) {
>> + unsigned long hp_size = default_huge_page_size();
>> +
>> + if (!hp_size) {
>> + close(zero_fd);
>> + close(self->gup_fd);
>
> You can move hugetlb setup after opening those and save the headache of
> closing them.
>
> And in any rate prefer
>
> goto err_do_cleanup
>
> to
> if (something_failed) {
> cleanup1();
> cleanup2();
> }
>
> if (something_else_failed) {
> cleanup1();
> cleanup2();
> cleanup3();
> }
Got it, will change.
>
>> + SKIP(return, "HugeTLB not available\n");
>> + }
>> +
>> + self->size = (self->size + hp_size - 1) & ~(hp_size - 1);
>> + if (!hugetlb_setup_default(self->size / hp_size)) {
>> + hugetlb_restore_settings();
>
> No need to call restore() here.
>
> Also, if you use a constant number of huge pages you can just add
> HUGETLB_SETUP_DEFAULT_PAGES(NR_HUGE_PAGES) somewhere in the begining and
> you won't need to setup and teardown hugetlb explicitly for every
> hugetlb test.
Ack
>
>
>> + close(zero_fd);
>> + close(self->gup_fd);
>> + SKIP(return, "Not enough huge pages\n");
>> + }
>> +
>> + mmap_flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
>> + }
>> +
>> + if (variant->shared)
>> + mmap_flags = (mmap_flags & ~MAP_PRIVATE) | MAP_SHARED;
>> +
>> + self->addr = mmap(NULL, self->size, PROT_READ | PROT_WRITE,
>> + mmap_flags, zero_fd, 0);
>> +
>> + ASSERT_NE(self->addr, MAP_FAILED) {
>> + int err = errno;
>> +
>> + close(zero_fd);
>> + close(self->gup_fd);
>> + if (variant->hugetlb)
>> + hugetlb_restore_settings();
>> + TH_LOG("mmap failed: %s", strerror(err));
>> + }
>> + close(zero_fd);
>> +
>> + if (variant->thp)
>> + madvise(self->addr, self->size, MADV_HUGEPAGE);
>> + else if (!variant->hugetlb)
>> + madvise(self->addr, self->size, MADV_NOHUGEPAGE);
>> +
>> + for (p = self->addr; (unsigned long)p < (unsigned long)self->addr
>> + + self->size; p += psize())
>> + p[0] = 0;
>> +}
>> +
>> +FIXTURE_TEARDOWN(gup_test)
>> +{
>> + munmap(self->addr, self->size);
>> + close(self->gup_fd);
>> +
>> + if (variant->hugetlb)
>> + hugetlb_restore_settings();
>> +}
>> +
>> +static void run_gup_cmd(struct __test_metadata *_metadata,
>> + FIXTURE_DATA(gup_test) *self,
>> + const FIXTURE_VARIANT(gup_test) *variant,
>> + unsigned long command,
>> + unsigned int test_flags,
>> + unsigned int which_page)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
>> + struct gup_test gup = {
>> + .addr = (unsigned long)self->addr,
>> + .size = self->size,
>> + .nr_pages_per_call = nr_pages_list[i] < 0 ?
>> + self->size / psize() : nr_pages_list[i],
>> + .test_flags = test_flags,
>> + };
>> +
>> + if (variant->write)
>> + gup.gup_flags |= FOLL_WRITE;
>> +
>> + gup.which_pages[0] = which_page;
>
> Can't these to go to the static initialization?
Will move both which_pages and gup_flags to the initialization.
next prev parent reply other threads:[~2026-08-04 7:38 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 14:08 [PATCH v6 0/6] selftests/mm: separate GUP microbenchmarking from functional testing Sarthak Sharma
2026-07-30 14:08 ` [PATCH v6 1/6] selftests/mm: make file helpers return errors Sarthak Sharma
2026-08-03 9:00 ` Mike Rapoport
2026-08-04 6:39 ` Sarthak Sharma
2026-07-30 14:08 ` [PATCH v6 2/6] tools/lib/mm: add shared file helpers Sarthak Sharma
2026-08-03 9:00 ` Mike Rapoport
2026-08-04 6:43 ` Sarthak Sharma
2026-08-04 9:23 ` Mike Rapoport
2026-07-30 14:08 ` [PATCH v6 3/6] tools/lib/mm: move hugepage_settings out of selftests Sarthak Sharma
2026-08-03 9:00 ` Mike Rapoport
2026-08-03 12:44 ` Mark Brown
2026-07-30 14:08 ` [PATCH v6 4/6] tools/mm: move gup_test from selftests/mm to tools/mm Sarthak Sharma
2026-07-30 14:08 ` [PATCH v6 5/6] tools/mm: make gup_bench a benchmark only tool Sarthak Sharma
2026-08-03 9:00 ` Mike Rapoport
2026-08-04 7:34 ` Sarthak Sharma
2026-08-04 9:31 ` Mike Rapoport
2026-07-30 14:08 ` [PATCH v6 6/6] selftests/mm: add a GUP selftest Sarthak Sharma
2026-08-03 9:00 ` Mike Rapoport
2026-08-04 7:38 ` Sarthak Sharma [this message]
2026-08-04 9:35 ` Mike Rapoport
2026-08-03 9:00 ` [PATCH v6 0/6] selftests/mm: separate GUP microbenchmarking from functional testing Mike Rapoport
2026-08-04 6:36 ` Sarthak Sharma
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=34e3932c-aaf1-4b69-a3c4-398784aae290@arm.com \
--to=sarthak.sharma@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=lance.yang@linux.dev \
--cc=leon@kernel.org \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=npache@redhat.com \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/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