The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH v3 35/54] selftests/mm: hugepage_dio: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-36-rppt@kernel.org>
@ 2026-05-04 12:20   ` Sarthak Sharma
  2026-05-11  8:25     ` Mike Rapoport
  0 siblings, 1 reply; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-04 12:20 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugepage_dio test fails if there are no free huge pages prepared by a
> wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  tools/testing/selftests/mm/hugetlb_dio.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> index 47019433ddaf..fb4600570e13 100644
> --- a/tools/testing/selftests/mm/hugetlb_dio.c
> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> @@ -85,8 +85,6 @@ static void run_dio_using_hugetlb(int fd, unsigned int start_off,
>  
>  	/* Get the default huge page size */
>  	h_pagesize = default_huge_page_size();
> -	if (!h_pagesize)
> -		ksft_exit_fail_msg("Unable to determine huge page size\n");
>  
>  	/* Reset file position since fd is shared across tests */
>  	if (lseek(fd, 0, SEEK_SET) < 0)
> @@ -94,10 +92,6 @@ static void run_dio_using_hugetlb(int fd, unsigned int start_off,
>  
>  	/* Get the free huge pages before allocation */
>  	free_hpage_b = hugetlb_free_default_pages();
> -	if (free_hpage_b == 0) {
> -		close(fd);
> -		ksft_exit_skip("No free hugepage, exiting!\n");
> -	}
>  
>  	/* Allocate a hugetlb page */
>  	orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
> @@ -141,8 +135,8 @@ int main(void)
>  
>  	ksft_print_header();
>  
> -	/* Check if huge pages are free */
> -	if (!hugetlb_free_default_pages())
> +	/* request a huge page */
> +	if (!hugetlb_setup_default(1))
>  		ksft_exit_skip("No free hugepage, exiting\n");

Before applying the patch, I get the following output:

TAP version 13
1..4
# No. Free pages before allocation : 112
# No. Free pages after munmap : 112
ok 1 free huge pages from 0-12288
# No. Free pages before allocation : 112
# No. Free pages after munmap : 112
ok 2 free huge pages from 0-10240
# No. Free pages before allocation : 112
# No. Free pages after munmap : 112
ok 3 free huge pages from 2048-12288
# No. Free pages before allocation : 112
# No. Free pages after munmap : 112
ok 4 free huge pages from 2048-14336
# Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0

After applying the patch, I get this:

TAP version 13
# [INFO] detected hugetlb page size: 2048 KiB
# [INFO] detected hugetlb page size: 32768 KiB
# [INFO] detected hugetlb page size: 64 KiB
# [INFO] detected hugetlb page size: 1048576 KiB
1..0 # SKIP No free hugepage, exiting

even when I have 112 free and 128 total hugepages of size 2MB (default
for my system).

Could it be because hugetlb_setup_default(1) here is trying to set the
default hugetlb pool size to exactly 1, and then checking whether there
is exactly 1 free hugepage, instead of simply checking whether at least
1 free hugepage is available?


>  
>  	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 27/54] selftests/mm: hugepage_settings: add APIs for HugeTLB setup and teardown
       [not found]         ` <afV_WAK56lQKn_z1@kernel.org>
@ 2026-05-04 13:04           ` Luiz Capitulino
  0 siblings, 0 replies; 34+ messages in thread
From: Luiz Capitulino @ 2026-05-04 13:04 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Barry Song,
	Dev Jain, Donet Tom, Jason Gunthorpe, John Hubbard,
	Liam R. Howlett, Lance Yang, Leon Romanovsky, Lorenzo Stoakes,
	Mark Brown, Michal Hocko, Nico Pache, Peter Xu, Ryan Roberts,
	Sarthak Sharma, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	Zi Yan, linux-kernel, linux-kselftest, linux-mm

On 2026-05-02 00:36, Mike Rapoport wrote:
> On Fri, May 01, 2026 at 03:30:18PM -0400, Luiz Capitulino wrote:
>> On 2026-05-01 11:25, Mike Rapoport wrote:
>>>>>     	return mode == 1 || mode == 3;
>>>>>     }
>>>>> +#define HUGETLB_MAX_NR_PAGESIZES 10
>>>>> +struct hugetlb_settings {
>>>>> +	unsigned long free_hugepages[HUGETLB_MAX_NR_PAGESIZES];
>>>>
>>>> It looks like we don't actually use this in the API or maybe I'm missing
>>>> something?
>>>
>>> Yes, it's used only in later patches.
>>
>> I don't see it, the patch below builds fine (again, sorry in advance if
>> I'm missing something obvious):
> 
> You are right, I misunderstood you comment and I thought you referred to
> entire API being unused in this patch.
> 
> free_hugepages is not used and it should not be a part of the saved state.

Thanks, I'll try to be more specific next time.

>   
>> diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
>> index 097ba085f423..a023cfeb69c5 100644
>> --- a/tools/testing/selftests/mm/hugepage_settings.c
>> +++ b/tools/testing/selftests/mm/hugepage_settings.c
>> @@ -341,7 +341,6 @@ bool thp_is_enabled(void)
>>   #define HUGETLB_MAX_NR_PAGESIZES 10
>>   struct hugetlb_settings {
>> -	unsigned long free_hugepages[HUGETLB_MAX_NR_PAGESIZES];
>>   	unsigned long nr_hugepages[HUGETLB_MAX_NR_PAGESIZES];
>>   	unsigned long sizes[HUGETLB_MAX_NR_PAGESIZES];
>>   	unsigned long default_size;
>> @@ -509,7 +508,6 @@ static void __hugetlb_save_settings(void)
>>   		if (!sz)
>>   			continue;
>> -		settings->free_hugepages[i] = hugetlb_free_pages(sz);
>>   		settings->nr_hugepages[i] = hugetlb_nr_pages(sz);
>>   	}
>>
>>> I felt it would be too churny to add users in this patch.
>>>> Otherwise, the API looks great to me. But if you allow me to bikeshed :)
>>>>
>>>> I think I'd do:
>>>>
>>>> struct hugetlb_state {
>>>> 	unsigned long nr_hugepages;
>>>> 	unsigned long size;
>>>> };
>>>>
>>>> struct hugetlb_settings {
>>>> 	struct hugetlb_state hstate[HUGETLB_MAX_PAGESIZES];
>>>> 	unsigned long default_size;
>>>> 	int nr_sizes;
>>>> };
>>>
>>> It might be slightly nicer abstraction but ...
>>>>> +static void __hugetlb_save_settings(void)
>>>>> +{
>>>>> +	struct hugetlb_settings *settings = &hugetlb_saved_settings;
>>>>> +	int nr_sizes;
>>>>> +
>>>>> +	settings->default_size = default_huge_page_size();
>>>>> +	if (!settings->default_size)
>>>>> +		return;
>>>>> +
>>>>> +	nr_sizes = detect_hugetlb_page_sizes(settings->sizes,
>>>>> +					     HUGETLB_MAX_NR_PAGESIZES);
>>>
>>> ... this immediately becomes more complex.
>>>
>>>>> +	if (!nr_sizes) {
>>>>> +		settings->default_size = 0;
>>>>> +		return;
>>>>> +	}
>>>>> +
>>>>> +	for (int i = 0; i < nr_sizes; i++) {
>>>>> +		unsigned long sz = settings->sizes[i];
>>>>> +
>>>>> +		if (!sz)
>>>>> +			continue;
>>>>> +
>>>>> +		settings->free_hugepages[i] = hugetlb_free_pages(sz);
>>>>> +		settings->nr_hugepages[i] = hugetlb_nr_pages(sz);
>>>
>>> And this as well.
>>
>> We'd need a little more code to handle those cases, may or may not be
>> worth it. But enough bikesheding from my side :) the series is great as
>> is.
>>
>>
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 40/54] selftests/mm: hugetlb-mremap: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-41-rppt@kernel.org>
@ 2026-05-05  6:51   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-05  6:51 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-mremap test fails if there are no free huge pages prepared by a
> wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  tools/testing/selftests/mm/hugetlb-mremap.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-mremap.c b/tools/testing/selftests/mm/hugetlb-mremap.c
> index 1c87c39780c5..09241a279ec2 100644
> --- a/tools/testing/selftests/mm/hugetlb-mremap.c
> +++ b/tools/testing/selftests/mm/hugetlb-mremap.c
> @@ -26,6 +26,7 @@
>  #include <stdbool.h>
>  #include "kselftest.h"
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define DEFAULT_LENGTH_MB 10UL
>  #define MB_TO_BYTES(x) (x * 1024 * 1024)
> @@ -108,8 +109,9 @@ static void register_region_with_uffd(char *addr, size_t len)
>  
>  int main(int argc, char *argv[])
>  {
> +	unsigned long hugepage_size;
> +	int ret = 0, fd, nr;
>  	size_t length = 0;
> -	int ret = 0, fd;
>  
>  	ksft_print_header();
>  	ksft_set_plan(1);
> @@ -125,7 +127,14 @@ int main(int argc, char *argv[])
>  	else
>  		length = DEFAULT_LENGTH_MB;
>  
> +	hugepage_size = default_huge_page_size();
>  	length = MB_TO_BYTES(length);
> +	length = (length + hugepage_size) & ~(hugepage_size - 1);

I might be missing something, but if we're trying to align length to the
hugepage size, should this be:

length = (length + hugepage_size - 1) & ~(hugepage_size - 1);

like in hugetlb-mmap.c? Because the current code will add an extra
hugepage if the length is already aligned.

> +	nr = length / hugepage_size;
> +
> +	if (!hugetlb_setup_default(nr))
> +		ksft_exit_skip("Not enough huge pages\n");
> +
>  	fd = memfd_create(argv[0], MFD_HUGETLB);
>  	if (fd < 0)
>  		ksft_exit_fail_msg("Open failed: %s\n", strerror(errno));


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 42/54] selftests/mm: hugetlb-soft-online: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-43-rppt@kernel.org>
@ 2026-05-05  7:15   ` Sarthak Sharma
  2026-05-11  8:25     ` Mike Rapoport
  0 siblings, 1 reply; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-05  7:15 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-soft-online test uses open coded access to /proc to determine
> availability of huge pages and fails if there are no enough free huget
> pages..
> 
> Replace open coded access to /proc with hugepage helpers and add setup
> of HugeTLB pages to the test and make sure that the original settings
> are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

The test is hugetlb-soft-offline, so let's change the commit title and
commit message to say "offine" instead of "online".

I have run the test before and after applying the patch. Before the
patch, it failed with an mmap error when hugepages were not
preallocated. After applying the patch, the test correctly allocates the
required hugepages and the test passes.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  .../selftests/mm/hugetlb-soft-offline.c       | 45 ++++---------------
>  1 file changed, 8 insertions(+), 37 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> index a8bc02688085..bc202e4ed2bd 100644
> --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c
> +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> @@ -6,9 +6,7 @@
>   * - if enable_soft_offline = 1, a hugepage should be dissolved and
>   *   nr_hugepages/free_hugepages should be reduced by 1.
>   *
> - * Before running, make sure more than 2 hugepages of default_hugepagesz
> - * are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB:
> - *   echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
> + * The test allocates 8 default hugepages
>   */
>  
>  #define _GNU_SOURCE
> @@ -25,6 +23,7 @@
>  #include <sys/types.h>
>  
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #ifndef MADV_SOFT_OFFLINE
>  #define MADV_SOFT_OFFLINE 101
> @@ -100,32 +99,6 @@ static int set_enable_soft_offline(int value)
>  	return 0;
>  }
>  
> -static int read_nr_hugepages(unsigned long hugepage_size,
> -			     unsigned long *nr_hugepages)
> -{
> -	char buffer[256] = {0};
> -	char cmd[256] = {0};
> -
> -	sprintf(cmd, "cat /sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages",
> -		hugepage_size);
> -	FILE *cmdfile = popen(cmd, "r");
> -
> -	if (cmdfile == NULL) {
> -		ksft_perror(EPREFIX "failed to popen nr_hugepages");
> -		return -1;
> -	}
> -
> -	if (!fgets(buffer, sizeof(buffer), cmdfile)) {
> -		ksft_perror(EPREFIX "failed to read nr_hugepages");
> -		pclose(cmdfile);
> -		return -1;
> -	}
> -
> -	*nr_hugepages = atoll(buffer);
> -	pclose(cmdfile);
> -	return 0;
> -}
> -
>  static int create_hugetlbfs_file(struct statfs *file_stat)
>  {
>  	int fd;
> @@ -177,20 +150,14 @@ static void test_soft_offline_common(int enable_soft_offline)
>  		ksft_exit_fail_msg("Failed to set enable_soft_offline\n");
>  	}
>  
> -	if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_before) != 0) {
> -		close(fd);
> -		ksft_exit_fail_msg("Failed to read nr_hugepages\n");
> -	}
> +	nr_hugepages_before = hugetlb_nr_default_pages();
>  
>  	ksft_print_msg("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n",
>  		       nr_hugepages_before);
>  
>  	ret = do_soft_offline(fd, 2 * file_stat.f_bsize, expect_errno);
>  
> -	if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_after) != 0) {
> -		close(fd);
> -		ksft_exit_fail_msg("Failed to read nr_hugepages\n");
> -	}
> +	nr_hugepages_after = hugetlb_nr_default_pages();
>  
>  	ksft_print_msg("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n",
>  		nr_hugepages_after);
> @@ -219,6 +186,10 @@ static void test_soft_offline_common(int enable_soft_offline)
>  int main(int argc, char **argv)
>  {
>  	ksft_print_header();
> +
> +	if (!hugetlb_setup_default(8))
> +		ksft_exit_skip("not enough hugetlb pages\n");
> +
>  	ksft_set_plan(2);
>  
>  	test_soft_offline_common(1);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 50/54] selftests/mm: uffd-wp-mremap: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-51-rppt@kernel.org>
@ 2026-05-05 11:27   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-05 11:27 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> uffd-wp-remap skips HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  tools/testing/selftests/mm/uffd-wp-mremap.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
> index 9d67b11c2f28..f63fe02f404f 100644
> --- a/tools/testing/selftests/mm/uffd-wp-mremap.c
> +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
> @@ -336,14 +336,14 @@ int main(int argc, char **argv)
>  	struct thp_settings settings;
>  	int i, j, plan = 0;
>  
> +	hugepage_save_settings(true, true);

Since hugetlb_setup below already calls hugepage_save_settings()
internally, perhaps we can change this to hugepage_save_settings(true,
false) or simply keep thp_save_settings()? Otherwise we're saving the
HugeTLB state twice here and it seems redundant.

> +
>  	pagesize = getpagesize();
>  	nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes));
> -	nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes,
> -						    ARRAY_SIZE(hugetlbsizes));
> +	nr_hugetlbsizes = hugetlb_setup(1, hugetlbsizes, ARRAY_SIZE(hugetlbsizes));
>  
>  	/* If THP is supported, save THP settings and initially disable THP. */
>  	if (nr_thpsizes) {
> -		thp_save_settings();
>  		thp_read_settings(&settings);
>  		for (i = 0; i < NR_ORDERS; i++) {
>  			settings.hugepages[i].enabled = THP_NEVER;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 41/54] selftests/mm: hugetlb-shm: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-42-rppt@kernel.org>
@ 2026-05-05 11:33   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-05 11:33 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-shm test fails if there are no free huge pages prepared by a
> wrapper script and shm liimts in proc are too low.
> 
> Add setup of HugeTLB pages and shm limits to the test and make sure that
> the original settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  tools/testing/selftests/mm/hugetlb-shm.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-shm.c b/tools/testing/selftests/mm/hugetlb-shm.c
> index 0f70b1a50b6b..7b5a5cefe458 100644
> --- a/tools/testing/selftests/mm/hugetlb-shm.c
> +++ b/tools/testing/selftests/mm/hugetlb-shm.c
> @@ -29,9 +29,24 @@
>  #include <sys/mman.h>
>  
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define LENGTH (256UL*1024*1024)
>  
> +static void prepare(void)
> +{
> +	unsigned long length, hugepage_size, nr;
> +
> +	hugepage_size = default_huge_page_size();
> +	length = (LENGTH + hugepage_size) & ~(hugepage_size - 1);

Same issue here as in hugetlb-mremap.c.

length = (LENGTH + hugepage_size) & ~(hugepage_size - 1)

will add an extra hugepage if LENGTH is already aligned. Should this be
(LENGTH + hugepage_size - 1) & ~(hugepage_size - 1) instead?

> +	nr = length / hugepage_size;
> +
> +	if (!hugetlb_setup_default(nr))
> +		ksft_exit_skip("Not enough free huge pages\n");
> +
> +	shm_limits_prepare(length);
> +}
> +
>  int main(void)
>  {
>  	int shmid;
> @@ -41,6 +56,8 @@ int main(void)
>  	ksft_print_header();
>  	ksft_set_plan(1);
>  
> +	prepare();
> +
>  	shmid = shmget(2, LENGTH, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W);
>  	if (shmid < 0)
>  		ksft_exit_fail_perror("shmget");
> @@ -78,3 +95,5 @@ int main(void)
>  	ksft_test_result_pass("hugepage using SysV shmget/shmat\n");
>  	ksft_finished();
>  }
> +
> +SHM_LIMITS_RESTORE()


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 49/54] selftests/mm: uffd-unit-tests: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-50-rppt@kernel.org>
@ 2026-05-05 11:48   ` Sarthak Sharma
  2026-05-11  8:28     ` Mike Rapoport
  0 siblings, 1 reply; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-05 11:48 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> uffd-unit-tests skips HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Replace exit() calls with _exit() to avoid restoring HugeTLB settings in
> the middle of test.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  tools/testing/selftests/mm/uffd-unit-tests.c | 31 +++++++++++++++++---
>  1 file changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
> index 1a33db281f8a..20e1829db91f 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -305,7 +305,7 @@ static int pagemap_test_fork(uffd_global_test_opts_t *gopts, bool with_event, bo
>  		if (test_pin)
>  			unpin_pages(&args);
>  		/* Succeed */
> -		exit(0);
> +		_exit(0);
>  	}
>  	waitpid(child, &result, 0);
>  
> @@ -773,7 +773,7 @@ static void uffd_sigbus_test_common(uffd_global_test_opts_t *gopts, bool wp)
>  		err("fork");
>  
>  	if (!pid)
> -		exit(faulting_process(gopts, 2, wp));
> +		_exit(faulting_process(gopts, 2, wp));
>  
>  	waitpid(pid, &err, 0);
>  	if (err)
> @@ -827,7 +827,7 @@ static void uffd_events_test_common(uffd_global_test_opts_t *gopts, bool wp)
>  		err("fork");
>  
>  	if (!pid)
> -		exit(faulting_process(gopts, 0, wp));
> +		_exit(faulting_process(gopts, 0, wp));
>  
>  	waitpid(pid, &err, 0);
>  	if (err)
> @@ -1706,11 +1706,32 @@ static int uffd_count_tests(int n_tests, int n_mems, const char *test_filter)
>  	return count;
>  }
>  
> +static unsigned long uffd_setup_hugetlb(void)
> +{
> +	unsigned long nr_hugepages, hp_size;
> +
> +	hugetlb_save_settings();
> +	hp_size = default_huge_page_size();
> +
> +	if (!hp_size)
> +		return 0;
> +
> +	/* need twice UFFD_TEST_MEM_SIZE, one for src area and one for dst */
> +	nr_hugepages = 2 * MAX(UFFD_TEST_MEM_SIZE, hp_size * 2) / hp_size;
> +	hugetlb_set_nr_default_pages(nr_hugepages);
> +
> +	if (hugetlb_free_default_pages() < nr_hugepages)
> +		return 0;
> +
> +	return hp_size;
> +}
> +
>  int main(int argc, char *argv[])
>  {
>  	int n_tests = sizeof(uffd_tests) / sizeof(uffd_test_case_t);
>  	int n_mems = sizeof(mem_types) / sizeof(mem_type_t);
>  	const char *test_filter = NULL;
> +	unsigned long hugepage_size;
>  	bool list_only = false;
>  	uffd_test_case_t *test;
>  	mem_type_t *mem_type;
> @@ -1745,6 +1766,8 @@ int main(int argc, char *argv[])
>  		return KSFT_PASS;
>  	}
>  
> +	hugepage_size = uffd_setup_hugetlb();
> +
>  	ksft_print_header();
>  	ksft_set_plan(uffd_count_tests(n_tests, n_mems, test_filter));
>  
> @@ -1771,7 +1794,7 @@ int main(int argc, char *argv[])
>  			uffd_test_case_ops = test->test_case_ops;
>  
>  			if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE | MEM_HUGETLB)) {
> -				gopts.page_size = default_huge_page_size();
> +				gopts.page_size = hugepage_size;
>  				if (gopts.page_size == 0) {
>  					uffd_test_skip("huge page size is 0, feature missing?");

A small nit, after this patch, uffd_setup_hugetlb() can return 0 in 2 cases:

a) default_huge_page_size() == 0
b) hugetlb_free_default_pages() < nr_hugepages

The skip message only covers the first case and would be misleading for
the second case. Should we differentiate both these using different skip
messages?

>  					continue;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 30/54] selftests/mm: compaction_test: use HugeTLB helpers ...
       [not found]   ` <daa3e21f-0c48-456e-a4a8-198a8c907b9d@arm.com>
@ 2026-05-05 15:26     ` Mike Rapoport
  0 siblings, 0 replies; 34+ messages in thread
From: Mike Rapoport @ 2026-05-05 15:26 UTC (permalink / raw)
  To: Sarthak Sharma
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Barry Song,
	Dev Jain, Donet Tom, Jason Gunthorpe, John Hubbard,
	Liam R. Howlett, Lance Yang, Leon Romanovsky, Lorenzo Stoakes,
	Luiz Capitulino, Mark Brown, Michal Hocko, Nico Pache, Peter Xu,
	Ryan Roberts, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	Zi Yan, linux-kernel, linux-kselftest, linux-mm

On Mon, May 04, 2026 at 03:37:31PM +0530, Sarthak Sharma wrote:
> Hi Mike!
> 
> On 4/29/26 2:12 AM, Mike Rapoport wrote:
> > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> > 
> > ... instead of open coded access of HugeTLB parameters via /proc.
> > 
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> >  tools/testing/selftests/mm/compaction_test.c | 113 +++----------------
> >  1 file changed, 17 insertions(+), 96 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
> > index 30209c40b697..962a50c3d66f 100644
> > --- a/tools/testing/selftests/mm/compaction_test.c
> > +++ b/tools/testing/selftests/mm/compaction_test.c
> > @@ -17,6 +17,7 @@
> >  #include <string.h>
> >  
> > @@ -161,48 +120,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
> >  	ret = 0;
> >  
> >   close_fd:
> 
> A small nit, should we rename close_fd: to out: now? After this change
> the label no longer closes an fd and is the common exit path, so
> close_fd feels a bit misleading.

Thanks, will fix.
 
> > -	close(fd);
> > - out:
> >  	ksft_test_result(ret == 0, "check_compaction\n");
> >  	return ret;
> >  }
> >  

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 17/54] selftests/mm: protection_keys: use kselftest framework
       [not found] ` <20260428204240.1924129-18-rppt@kernel.org>
@ 2026-05-06  8:57   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06  8:57 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> Convert protection_keys test to use kselftest framework for reporting
> and tracking successful and failing runs.
> 
> Adjust dprintf0() printouts to use "#" in the beginning of the line for
> TAP compatibility.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. It correctly
converts the test output into KTAP format.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/pkey-helpers.h    |  6 +++--
>  tools/testing/selftests/mm/protection_keys.c | 26 +++++++++++---------
>  2 files changed, 19 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
> index 7c29f075e40b..ae010b075417 100644
> --- a/tools/testing/selftests/mm/pkey-helpers.h
> +++ b/tools/testing/selftests/mm/pkey-helpers.h
> @@ -71,10 +71,12 @@ static inline void sigsafe_printf(const char *format, ...)
>  extern void abort_hooks(void);
>  #define pkey_assert(condition) do {		\
>  	if (!(condition)) {			\
> -		dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
> +		dprintf0("# assert() at %s::%d test_nr: %d iteration: %d\n", \
>  				__FILE__, __LINE__,	\
>  				test_nr, iteration_nr);	\
> -		dprintf0("errno at assert: %d", errno);	\
> +		dprintf0("# errno at assert: %d\n", errno);	\
> +		ksft_test_result_fail("test %d (iteration %d)\n",	\
> +				      test_nr, iteration_nr);		\
>  		abort_hooks();			\
>  		exit(__LINE__);			\
>  	}					\
> diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
> index 80c6124e8378..d617b41dda6b 100644
> --- a/tools/testing/selftests/mm/protection_keys.c
> +++ b/tools/testing/selftests/mm/protection_keys.c
> @@ -136,6 +136,7 @@ static void tracing_off(void)
>  
>  void abort_hooks(void)
>  {
> +	fflush(stdout);
>  	fprintf(stderr, "running %s()...\n", __func__);
>  	tracing_off();
>  #ifdef SLEEP_ON_ABORT
> @@ -370,8 +371,8 @@ static void signal_handler(int signum, siginfo_t *si, void *vucontext)
>  	if ((si->si_code == SEGV_MAPERR) ||
>  	    (si->si_code == SEGV_ACCERR) ||
>  	    (si->si_code == SEGV_BNDERR)) {
> -		printf("non-PK si_code, exiting...\n");
> -		exit(4);
> +		dprintf0("# non-PK si_code: %d, exiting...\n", si->si_code);
> +		exit(1);
>  	}
>  
>  	si_pkey_ptr = siginfo_get_pkey_ptr(si);
> @@ -719,7 +720,7 @@ static void setup_hugetlbfs(void)
>  	long hpagesz_mb;
>  
>  	if (geteuid() != 0) {
> -		fprintf(stderr, "WARNING: not run as root, can not do hugetlb test\n");
> +		ksft_print_msg("WARNING: not run as root, can not do hugetlb test\n");
>  		return;
>  	}
>  
> @@ -855,7 +856,7 @@ void expected_pkey_fault(int pkey)
>  
>  #define do_not_expect_pkey_fault(msg)	do {			\
>  	if (last_pkey_faults != pkey_faults)			\
> -		dprintf0("unexpected PKey fault: %s\n", msg);	\
> +		dprintf0("# unexpected PKey fault: %s\n", msg);	\
>  	pkey_assert(last_pkey_faults == pkey_faults);		\
>  } while (0)
>  
> @@ -1753,7 +1754,7 @@ static void run_tests_once(void)
>  		tracing_off();
>  		close_test_fds();
>  
> -		printf("test %s PASSED (iteration %d)\n", pkey_tests[test_nr].name, iteration_nr);
> +		ksft_test_result_pass("test %s (iteration %d)\n", pkey_tests[test_nr].name, iteration_nr);
>  		dprintf1("======================\n\n");
>  	}
>  	iteration_nr++;
> @@ -1773,27 +1774,30 @@ int main(void)
>  
>  	setup_handlers();
>  
> -	printf("has pkeys: %d\n", pkeys_supported);
> +	ksft_print_header();
>  
>  	if (!pkeys_supported) {
>  		int size = PAGE_SIZE;
>  		int *ptr;
>  
> -		printf("running PKEY tests for unsupported CPU/OS\n");
> +		ksft_set_plan(1);
> +		ksft_print_msg("running PKEY tests for unsupported CPU/OS\n");
>  
>  		ptr  = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
>  		assert(ptr != (void *)-1);
>  		test_mprotect_pkey_on_unsupported_cpu(ptr, 1);
> -		exit(0);
> +		ksft_test_result_pass("pkey on unsupported CPU/OS\n");
> +		ksft_finished();
>  	}
>  
> +	ksft_set_plan(ARRAY_SIZE(pkey_tests) * nr_iterations);
> +
>  	pkey_setup_shadow();
> -	printf("startup pkey_reg: %016llx\n", read_pkey_reg());
> +	ksft_print_msg("startup pkey_reg: %016llx\n", read_pkey_reg());
>  	setup_hugetlbfs();
>  
>  	while (nr_iterations-- > 0)
>  		run_tests_once();
>  
> -	printf("done (all tests OK)\n");
> -	return 0;
> +	ksft_finished();
>  }


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 20/54] selftests/mm: va_high_addr_switch: use kselftest framework
       [not found] ` <20260428204240.1924129-21-rppt@kernel.org>
@ 2026-05-06  9:02   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06  9:02 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> Convert va_high_addr_switch test to use kselftest framework for
> reporting and tracking successful and failing runs.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run this test before and after applying the patch. It correctly
converts the test output into KTAP format with no change in results.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  .../selftests/mm/va_high_addr_switch.c        | 41 +++++++++----------
>  1 file changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
> index 51401e081b20..5d38735ea60e 100644
> --- a/tools/testing/selftests/mm/va_high_addr_switch.c
> +++ b/tools/testing/selftests/mm/va_high_addr_switch.c
> @@ -257,40 +257,35 @@ void testcases_init(void)
>  	switch_hint = addr_switch_hint;
>  }
>  
> -static int run_test(struct testcase *test, int count)
> +static void run_test(struct testcase *test, int count)
>  {
>  	void *p;
> -	int i, ret = KSFT_PASS;
> +	int i;
>  
>  	for (i = 0; i < count; i++) {
>  		struct testcase *t = test + i;
>  
>  		p = mmap(t->addr, t->size, PROT_READ | PROT_WRITE, t->flags, -1, 0);
> -
> -		printf("%s: %p - ", t->msg, p);
> -
>  		if (p == MAP_FAILED) {
> -			printf("FAILED\n");
> -			ret = KSFT_FAIL;
> +			ksft_perror("MAP_FAILED");
> +			ksft_test_result_fail("%s\n", t->msg);
>  			continue;
>  		}
>  
>  		if (t->low_addr_required && p >= (void *)(switch_hint)) {
> -			printf("FAILED\n");
> -			ret = KSFT_FAIL;
> +			ksft_print_msg("%p not below switch hint\n", p);
> +			ksft_test_result_fail("%s\n", t->msg);
>  		} else {
>  			/*
>  			 * Do a dereference of the address returned so that we catch
>  			 * bugs in page fault handling
>  			 */
>  			memset(p, 0, t->size);
> -			printf("OK\n");
> +			ksft_test_result_pass("%s\n", t->msg);
>  		}
>  		if (!t->keep_mapped)
>  			munmap(p, t->size);
>  	}
> -
> -	return ret;
>  }
>  
>  #ifdef __aarch64__
> @@ -322,19 +317,23 @@ static int supported_arch(void)
>  
>  int main(int argc, char **argv)
>  {
> -	int ret, hugetlb_ret = KSFT_PASS;
> +	bool run_hugetlb = false;
> +
> +	ksft_print_header();
>  
>  	if (!supported_arch())
> -		return KSFT_SKIP;
> +		ksft_exit_skip("Architecture not supported\n");
> +
> +	if (argc == 2 && !strcmp(argv[1], "--run-hugetlb"))
> +		run_hugetlb = true;
>  
>  	testcases_init();
>  
> -	ret = run_test(testcases, sz_testcases);
> -	if (argc == 2 && !strcmp(argv[1], "--run-hugetlb"))
> -		hugetlb_ret = run_test(hugetlb_testcases, sz_hugetlb_testcases);
> +	ksft_set_plan(sz_testcases + (run_hugetlb ? sz_hugetlb_testcases : 0));
> +
> +	run_test(testcases, sz_testcases);
> +	if (run_hugetlb)
> +		run_test(hugetlb_testcases, sz_hugetlb_testcases);
>  
> -	if (ret == KSFT_PASS && hugetlb_ret == KSFT_PASS)
> -		return KSFT_PASS;
> -	else
> -		return KSFT_FAIL;
> +	ksft_finished();
>  }


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 22/54] selftests/mm: rename thp_settings.[ch] to hugepage_settings.[ch]
       [not found] ` <20260428204240.1924129-23-rppt@kernel.org>
@ 2026-05-06  9:12   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06  9:12 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> ... for upcoming addition of HugeTLB helpers.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/Makefile                           | 4 ++--
>  tools/testing/selftests/mm/cow.c                              | 2 +-
>  tools/testing/selftests/mm/folio_split_race_test.c            | 2 +-
>  tools/testing/selftests/mm/guard-regions.c                    | 2 +-
>  .../selftests/mm/{thp_settings.c => hugepage_settings.c}      | 2 +-
>  .../selftests/mm/{thp_settings.h => hugepage_settings.h}      | 0
>  tools/testing/selftests/mm/khugepaged.c                       | 2 +-
>  tools/testing/selftests/mm/ksm_tests.c                        | 2 +-
>  tools/testing/selftests/mm/migration.c                        | 2 +-
>  tools/testing/selftests/mm/prctl_thp_disable.c                | 2 +-
>  tools/testing/selftests/mm/soft-dirty.c                       | 2 +-
>  tools/testing/selftests/mm/split_huge_page_test.c             | 2 +-
>  tools/testing/selftests/mm/transhuge-stress.c                 | 2 +-
>  tools/testing/selftests/mm/uffd-wp-mremap.c                   | 2 +-
>  14 files changed, 14 insertions(+), 14 deletions(-)
>  rename tools/testing/selftests/mm/{thp_settings.c => hugepage_settings.c} (99%)
>  rename tools/testing/selftests/mm/{thp_settings.h => hugepage_settings.h} (100%)
> 
> diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
> index a6955660a806..a1d103b38485 100644
> --- a/tools/testing/selftests/mm/Makefile
> +++ b/tools/testing/selftests/mm/Makefile
> @@ -186,8 +186,8 @@ TEST_FILES += write_hugetlb_memory.sh
>  
>  include ../lib.mk
>  
> -$(TEST_GEN_PROGS): vm_util.c thp_settings.c
> -$(TEST_GEN_FILES): vm_util.c thp_settings.c
> +$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c
> +$(TEST_GEN_FILES): vm_util.c hugepage_settings.c
>  
>  $(OUTPUT)/uffd-stress: uffd-common.c
>  $(OUTPUT)/uffd-unit-tests: uffd-common.c
> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
> index 6abdcb30aba8..4321f4208fe3 100644
> --- a/tools/testing/selftests/mm/cow.c
> +++ b/tools/testing/selftests/mm/cow.c
> @@ -29,7 +29,7 @@
>  #include "../../../../mm/gup_test.h"
>  #include "kselftest.h"
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  static size_t pagesize;
>  static int pagemap_fd;
> diff --git a/tools/testing/selftests/mm/folio_split_race_test.c b/tools/testing/selftests/mm/folio_split_race_test.c
> index ff026f183ac7..7ede4793c778 100644
> --- a/tools/testing/selftests/mm/folio_split_race_test.c
> +++ b/tools/testing/selftests/mm/folio_split_race_test.c
> @@ -25,7 +25,7 @@
>  #include <unistd.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  uint64_t page_size;
>  uint64_t pmd_pagesize;
> diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
> index 48e8b1539be3..feb50b415f52 100644
> --- a/tools/testing/selftests/mm/guard-regions.c
> +++ b/tools/testing/selftests/mm/guard-regions.c
> @@ -21,7 +21,7 @@
>  #include <sys/uio.h>
>  #include <unistd.h>
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #include "../pidfd/pidfd.h"
>  
> diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
> similarity index 99%
> rename from tools/testing/selftests/mm/thp_settings.c
> rename to tools/testing/selftests/mm/hugepage_settings.c
> index f38ba8a27b30..87ecb309b430 100644
> --- a/tools/testing/selftests/mm/thp_settings.c
> +++ b/tools/testing/selftests/mm/hugepage_settings.c
> @@ -8,7 +8,7 @@
>  #include <unistd.h>
>  
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
>  #define MAX_SETTINGS_DEPTH 4
> diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/hugepage_settings.h
> similarity index 100%
> rename from tools/testing/selftests/mm/thp_settings.h
> rename to tools/testing/selftests/mm/hugepage_settings.h
> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
> index ef3b6464ff3f..7563d7600ce7 100644
> --- a/tools/testing/selftests/mm/khugepaged.c
> +++ b/tools/testing/selftests/mm/khugepaged.c
> @@ -22,7 +22,7 @@
>  #include "linux/magic.h"
>  
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #define BASE_ADDR ((void *)(1UL << 30))
>  static unsigned long hpage_pmd_size;
> diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
> index 752a2c0d06ab..fb355f869401 100644
> --- a/tools/testing/selftests/mm/ksm_tests.c
> +++ b/tools/testing/selftests/mm/ksm_tests.c
> @@ -15,7 +15,7 @@
>  #include "kselftest.h"
>  #include <include/vdso/time64.h>
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/"
>  #define KSM_FP(s) (KSM_SYSFS_PATH s)
> diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c
> index 76e380b74658..0212cd5bde6e 100644
> --- a/tools/testing/selftests/mm/migration.c
> +++ b/tools/testing/selftests/mm/migration.c
> @@ -5,7 +5,7 @@
>   */
>  
>  #include "kselftest_harness.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #include <strings.h>
>  #include <pthread.h>
> diff --git a/tools/testing/selftests/mm/prctl_thp_disable.c b/tools/testing/selftests/mm/prctl_thp_disable.c
> index ca27200596a4..d8d9d1de57b8 100644
> --- a/tools/testing/selftests/mm/prctl_thp_disable.c
> +++ b/tools/testing/selftests/mm/prctl_thp_disable.c
> @@ -14,7 +14,7 @@
>  #include <sys/wait.h>
>  
>  #include "kselftest_harness.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  #include "vm_util.h"
>  
>  #ifndef PR_THP_DISABLE_EXCEPT_ADVISED
> diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
> index bcfcac99b436..c426c4636ef5 100644
> --- a/tools/testing/selftests/mm/soft-dirty.c
> +++ b/tools/testing/selftests/mm/soft-dirty.c
> @@ -9,7 +9,7 @@
>  
>  #include "kselftest.h"
>  #include "vm_util.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  #define PAGEMAP_FILE_PATH "/proc/self/pagemap"
>  #define TEST_ITERATIONS 10000
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index 500d07c4938b..cc99294bdd5a 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -21,7 +21,7 @@
>  #include <time.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  uint64_t pagesize;
>  unsigned int pageshift;
> diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/selftests/mm/transhuge-stress.c
> index 7a9f1035099b..8eb0c5630e7e 100644
> --- a/tools/testing/selftests/mm/transhuge-stress.c
> +++ b/tools/testing/selftests/mm/transhuge-stress.c
> @@ -17,7 +17,7 @@
>  #include <sys/mman.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  
>  int backing_fd = -1;
>  int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
> diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
> index 516c35d236e1..9d67b11c2f28 100644
> --- a/tools/testing/selftests/mm/uffd-wp-mremap.c
> +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
> @@ -8,7 +8,7 @@
>  #include <linux/mman.h>
>  #include <sys/mman.h>
>  #include "kselftest.h"
> -#include "thp_settings.h"
> +#include "hugepage_settings.h"
>  #include "uffd-common.h"
>  
>  static int pagemap_fd;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 23/54] selftests/mm: move HugeTLB helpers to hugepage_settings
       [not found] ` <20260428204240.1924129-24-rppt@kernel.org>
@ 2026-05-06  9:14   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06  9:14 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> Move library functions that abstract HugeTLB /proc and /sysfs access
> from vm_util to hugepage_settings.
> 
> This will help creating common helpers that save and restore HugeTLB and
> THP settings.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/gup_longterm.c     |  1 +
>  tools/testing/selftests/mm/hmm-tests.c        |  2 +-
>  .../testing/selftests/mm/hugepage_settings.c  | 68 +++++++++++++++++++
>  .../testing/selftests/mm/hugepage_settings.h  |  8 +++
>  tools/testing/selftests/mm/hugetlb-madvise.c  |  1 +
>  tools/testing/selftests/mm/hugetlb-mmap.c     |  1 +
>  tools/testing/selftests/mm/hugetlb-vmemmap.c  |  1 +
>  tools/testing/selftests/mm/hugetlb_dio.c      |  1 +
>  .../selftests/mm/hugetlb_fault_after_madv.c   |  1 +
>  .../selftests/mm/hugetlb_madv_vs_map.c        |  1 +
>  tools/testing/selftests/mm/thuge-gen.c        |  1 +
>  tools/testing/selftests/mm/uffd-common.h      |  1 +
>  .../selftests/mm/va_high_addr_switch.c        |  1 +
>  tools/testing/selftests/mm/vm_util.c          | 66 ------------------
>  tools/testing/selftests/mm/vm_util.h          |  3 -
>  15 files changed, 87 insertions(+), 70 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
> index f61150d28eb2..ab4eaf4feb7c 100644
> --- a/tools/testing/selftests/mm/gup_longterm.c
> +++ b/tools/testing/selftests/mm/gup_longterm.c
> @@ -29,6 +29,7 @@
>  #include "../../../../mm/gup_test.h"
>  #include "kselftest.h"
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  static size_t pagesize;
>  static int nr_hugetlbsizes;
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..409b11cad4bc 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -11,6 +11,7 @@
>   */
>  
>  #include "kselftest_harness.h"
> +#include "hugepage_settings.h"
>  
>  #include <errno.h>
>  #include <fcntl.h>
> @@ -27,7 +28,6 @@
>  #include <sys/ioctl.h>
>  #include <sys/time.h>
>  
> -
>  /*
>   * This is a private UAPI to the kernel test module so it isn't exported
>   * in the usual include/uapi/... directory.
> diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
> index 87ecb309b430..ebaa621c45c6 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.c
> +++ b/tools/testing/selftests/mm/hugepage_settings.c
> @@ -1,7 +1,9 @@
>  // SPDX-License-Identifier: GPL-2.0
> +#include <dirent.h>
>  #include <fcntl.h>
>  #include <limits.h>
>  #include <signal.h>
> +#include <stddef.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -396,3 +398,69 @@ bool thp_is_enabled(void)
>  	/* THP is considered enabled if it's either "always" or "madvise" */
>  	return mode == 1 || mode == 3;
>  }
> +
> +int detect_hugetlb_page_sizes(size_t sizes[], int max)
> +{
> +	DIR *dir = opendir("/sys/kernel/mm/hugepages/");
> +	int count = 0;
> +
> +	if (!dir)
> +		return 0;
> +
> +	while (count < max) {
> +		struct dirent *entry = readdir(dir);
> +		size_t kb;
> +
> +		if (!entry)
> +			break;
> +		if (entry->d_type != DT_DIR)
> +			continue;
> +		if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1)
> +			continue;
> +		sizes[count++] = kb * 1024;
> +		ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n",
> +			       kb);
> +	}
> +	closedir(dir);
> +	return count;
> +}
> +
> +unsigned long default_huge_page_size(void)
> +{
> +	unsigned long hps = 0;
> +	char *line = NULL;
> +	size_t linelen = 0;
> +	FILE *f = fopen("/proc/meminfo", "r");
> +
> +	if (!f)
> +		return 0;
> +	while (getline(&line, &linelen, f) > 0) {
> +		if (sscanf(line, "Hugepagesize:       %lu kB", &hps) == 1) {
> +			hps <<= 10;
> +			break;
> +		}
> +	}
> +
> +	free(line);
> +	fclose(f);
> +	return hps;
> +}
> +
> +unsigned long get_free_hugepages(void)
> +{
> +	unsigned long fhp = 0;
> +	char *line = NULL;
> +	size_t linelen = 0;
> +	FILE *f = fopen("/proc/meminfo", "r");
> +
> +	if (!f)
> +		return fhp;
> +	while (getline(&line, &linelen, f) > 0) {
> +		if (sscanf(line, "HugePages_Free:      %lu", &fhp) == 1)
> +			break;
> +	}
> +
> +	free(line);
> +	fclose(f);
> +	return fhp;
> +}
> diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing/selftests/mm/hugepage_settings.h
> index 7748a9009191..320b97e768e8 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.h
> +++ b/tools/testing/selftests/mm/hugepage_settings.h
> @@ -6,6 +6,8 @@
>  #include <stddef.h>
>  #include <stdint.h>
>  
> +/* Transparent Huge Pages (THP) */
> +
>  enum thp_enabled {
>  	THP_NEVER,
>  	THP_ALWAYS,
> @@ -86,4 +88,10 @@ unsigned long thp_shmem_supported_orders(void);
>  bool thp_available(void);
>  bool thp_is_enabled(void);
>  
> +/* HugeTLB */
> +
> +int detect_hugetlb_page_sizes(size_t sizes[], int max);
> +unsigned long default_huge_page_size(void);
> +unsigned long get_free_hugepages(void);
> +
>  #endif /* __THP_SETTINGS_H__ */
> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
> index 4c6c346a3af5..316384d919db 100644
> --- a/tools/testing/selftests/mm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c
> @@ -20,6 +20,7 @@
>  #include <fcntl.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #define MIN_FREE_PAGES	20
>  #define NR_HUGE_PAGES	10	/* common number of pages to map/allocate */
> diff --git a/tools/testing/selftests/mm/hugetlb-mmap.c b/tools/testing/selftests/mm/hugetlb-mmap.c
> index 9f5ea8d6d656..031085cb7d17 100644
> --- a/tools/testing/selftests/mm/hugetlb-mmap.c
> +++ b/tools/testing/selftests/mm/hugetlb-mmap.c
> @@ -18,6 +18,7 @@
>  #include <linux/memfd.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #define LENGTH (256UL*1024*1024)
>  #define PROTECTION (PROT_READ | PROT_WRITE)
> diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> index 485a6978b40f..af5786bebfd1 100644
> --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c
> +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> @@ -11,6 +11,7 @@
>  #include <sys/mman.h>
>  #include <fcntl.h>
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define PAGE_COMPOUND_HEAD	(1UL << 15)
>  #define PAGE_COMPOUND_TAIL	(1UL << 16)
> diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> index 31a054fa8134..81e3f7bc8e76 100644
> --- a/tools/testing/selftests/mm/hugetlb_dio.c
> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> @@ -20,6 +20,7 @@
>  #include <sys/syscall.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #ifndef STATX_DIOALIGN
>  #define STATX_DIOALIGN		0x00002000U
> diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> index b4b257775b74..abc3904c5268 100644
> --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> @@ -10,6 +10,7 @@
>  
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #define INLOOP_ITER 100
>  
> diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> index c7105c6d319b..ac60b4f18784 100644
> --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> @@ -25,6 +25,7 @@
>  #include <unistd.h>
>  
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define INLOOP_ITER 100
>  
> diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
> index 77813d34dcc2..1007bc8aa57c 100644
> --- a/tools/testing/selftests/mm/thuge-gen.c
> +++ b/tools/testing/selftests/mm/thuge-gen.c
> @@ -28,6 +28,7 @@
>  #include <string.h>
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  #if !defined(MAP_HUGETLB)
>  #define MAP_HUGETLB	0x40000
> diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
> index 844a85ab31eb..6c5aca9cb63e 100644
> --- a/tools/testing/selftests/mm/uffd-common.h
> +++ b/tools/testing/selftests/mm/uffd-common.h
> @@ -37,6 +37,7 @@
>  
>  #include "kselftest.h"
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define UFFD_FLAGS	(O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY)
>  
> diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
> index 5d38735ea60e..0b69bd4b901d 100644
> --- a/tools/testing/selftests/mm/va_high_addr_switch.c
> +++ b/tools/testing/selftests/mm/va_high_addr_switch.c
> @@ -11,6 +11,7 @@
>  
>  #include "vm_util.h"
>  #include "kselftest.h"
> +#include "hugepage_settings.h"
>  
>  /*
>   * The hint addr value is used to allocate addresses
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index db94564f4431..e62e2a473123 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -291,53 +291,6 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd)
>  	return -1;
>  }
>  
> -unsigned long default_huge_page_size(void)
> -{
> -	unsigned long hps = 0;
> -	char *line = NULL;
> -	size_t linelen = 0;
> -	FILE *f = fopen("/proc/meminfo", "r");
> -
> -	if (!f)
> -		return 0;
> -	while (getline(&line, &linelen, f) > 0) {
> -		if (sscanf(line, "Hugepagesize:       %lu kB", &hps) == 1) {
> -			hps <<= 10;
> -			break;
> -		}
> -	}
> -
> -	free(line);
> -	fclose(f);
> -	return hps;
> -}
> -
> -int detect_hugetlb_page_sizes(size_t sizes[], int max)
> -{
> -	DIR *dir = opendir("/sys/kernel/mm/hugepages/");
> -	int count = 0;
> -
> -	if (!dir)
> -		return 0;
> -
> -	while (count < max) {
> -		struct dirent *entry = readdir(dir);
> -		size_t kb;
> -
> -		if (!entry)
> -			break;
> -		if (entry->d_type != DT_DIR)
> -			continue;
> -		if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1)
> -			continue;
> -		sizes[count++] = kb * 1024;
> -		ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n",
> -			       kb);
> -	}
> -	closedir(dir);
> -	return count;
> -}
> -
>  int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags)
>  {
>  	size_t count;
> @@ -396,25 +349,6 @@ int uffd_unregister(int uffd, void *addr, uint64_t len)
>  	return ret;
>  }
>  
> -unsigned long get_free_hugepages(void)
> -{
> -	unsigned long fhp = 0;
> -	char *line = NULL;
> -	size_t linelen = 0;
> -	FILE *f = fopen("/proc/meminfo", "r");
> -
> -	if (!f)
> -		return fhp;
> -	while (getline(&line, &linelen, f) > 0) {
> -		if (sscanf(line, "HugePages_Free:      %lu", &fhp) == 1)
> -			break;
> -	}
> -
> -	free(line);
> -	fclose(f);
> -	return fhp;
> -}
> -
>  static bool check_vmflag(void *addr, const char *flag)
>  {
>  	char buffer[MAX_LINE_LENGTH];
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 1a07305ceff4..195bf2e26792 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -94,8 +94,6 @@ bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size);
>  bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size);
>  bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size);
>  int64_t allocate_transhuge(void *ptr, int pagemap_fd);
> -unsigned long default_huge_page_size(void);
> -int detect_hugetlb_page_sizes(size_t sizes[], int max);
>  int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags);
>  
>  int uffd_register(int uffd, void *addr, uint64_t len,
> @@ -103,7 +101,6 @@ int uffd_register(int uffd, void *addr, uint64_t len,
>  int uffd_unregister(int uffd, void *addr, uint64_t len);
>  int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
>  			      bool miss, bool wp, bool minor, uint64_t *ioctls);
> -unsigned long get_free_hugepages(void);
>  bool check_vmflag_io(void *addr);
>  bool check_vmflag_pfnmap(void *addr);
>  bool check_vmflag_guard(void *addr);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 24/54] selftests/mm: hugepage_settings: use unsigned long in detect_hugetlb_page_size
       [not found] ` <20260428204240.1924129-25-rppt@kernel.org>
@ 2026-05-06  9:23   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06  9:23 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> ... instead of size_t to avoid type mismatch in 32 and 64 bit builds.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugepage_settings.c | 2 +-
>  tools/testing/selftests/mm/hugepage_settings.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
> index ebaa621c45c6..8f563315b1fc 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.c
> +++ b/tools/testing/selftests/mm/hugepage_settings.c
> @@ -399,7 +399,7 @@ bool thp_is_enabled(void)
>  	return mode == 1 || mode == 3;
>  }
>  
> -int detect_hugetlb_page_sizes(size_t sizes[], int max)
> +int detect_hugetlb_page_sizes(unsigned long sizes[], int max)
>  {
>  	DIR *dir = opendir("/sys/kernel/mm/hugepages/");
>  	int count = 0;
> diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing/selftests/mm/hugepage_settings.h
> index 320b97e768e8..9357d07e6c1b 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.h
> +++ b/tools/testing/selftests/mm/hugepage_settings.h
> @@ -90,7 +90,7 @@ bool thp_is_enabled(void);
>  
>  /* HugeTLB */
>  
> -int detect_hugetlb_page_sizes(size_t sizes[], int max);
> +int detect_hugetlb_page_sizes(unsigned long sizes[], int max);
>  unsigned long default_huge_page_size(void);
>  unsigned long get_free_hugepages(void);
>  


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 25/54] selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages
       [not found] ` <20260428204240.1924129-26-rppt@kernel.org>
@ 2026-05-06 10:12   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 10:12 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> Add APIs that allow reading and writing of
> 
> /sys/kernel/mm/hugepages/hugepages-NkB/nr_hugepages
> 
> to detect and change the amount of HugeTLB pages of different sizes.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

This patch looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  .../testing/selftests/mm/hugepage_settings.c  | 25 +++++++++++++++++++
>  .../testing/selftests/mm/hugepage_settings.h  | 23 +++++++++++++++++
>  2 files changed, 48 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
> index 8f563315b1fc..5961229b9931 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.c
> +++ b/tools/testing/selftests/mm/hugepage_settings.c
> @@ -464,3 +464,28 @@ unsigned long get_free_hugepages(void)
>  	fclose(f);
>  	return fhp;
>  }
> +
> +static void hugetlb_sysfs_path(char *buf, size_t buflen,
> +			       unsigned long size, const char *attr)
> +{
> +	snprintf(buf, buflen, "/sys/kernel/mm/hugepages/hugepages-%lukB/%s",
> +		 size / 1024, attr);
> +}
> +
> +unsigned long hugetlb_nr_pages(unsigned long size)
> +{
> +	char path[PATH_MAX];
> +
> +	hugetlb_sysfs_path(path, sizeof(path), size, "nr_hugepages");
> +
> +	return read_num(path);
> +}
> +
> +void hugetlb_set_nr_pages(unsigned long size, unsigned long nr)
> +{
> +	char path[PATH_MAX];
> +
> +	hugetlb_sysfs_path(path, sizeof(path), size, "nr_hugepages");
> +
> +	write_num(path, nr);
> +}
> diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing/selftests/mm/hugepage_settings.h
> index 9357d07e6c1b..d6f41a45e8ee 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.h
> +++ b/tools/testing/selftests/mm/hugepage_settings.h
> @@ -94,4 +94,27 @@ int detect_hugetlb_page_sizes(unsigned long sizes[], int max);
>  unsigned long default_huge_page_size(void);
>  unsigned long get_free_hugepages(void);
>  
> +unsigned long hugetlb_nr_pages(unsigned long size);
> +void hugetlb_set_nr_pages(unsigned long size, unsigned long nr);
> +
> +static inline unsigned long hugetlb_nr_default_pages(void)
> +{
> +	unsigned long size = default_huge_page_size();
> +
> +	if (!size)
> +		return 0;
> +
> +	return hugetlb_nr_pages(size);
> +}
> +
> +static inline void hugetlb_set_nr_default_pages(unsigned long nr)
> +{
> +	unsigned long size = default_huge_page_size();
> +
> +	if (!size)
> +		return;
> +
> +	hugetlb_set_nr_pages(size, nr);
> +}
> +
>  #endif /* __THP_SETTINGS_H__ */


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 26/54] selftests/mm: hugepage_settings: rename get_free_hugepages()
       [not found] ` <20260428204240.1924129-27-rppt@kernel.org>
@ 2026-05-06 11:03   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 11:03 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> ... to hugetlb_free_default_hugepages() for consistency with
> hugetlb_nr_default_pages().
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Small nit, the commit message says hugetlb_free_default_hugepages() but
the actual function added is hugetlb_free_default_pages().

This change looks good to me. All modified tests produce the same output
as before the patch.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  .../testing/selftests/mm/hugepage_settings.c  | 28 ++++++-------------
>  .../testing/selftests/mm/hugepage_settings.h  | 12 +++++++-
>  tools/testing/selftests/mm/hugetlb-madvise.c  |  4 +--
>  tools/testing/selftests/mm/hugetlb_dio.c      |  6 ++--
>  .../selftests/mm/hugetlb_fault_after_madv.c   |  2 +-
>  .../selftests/mm/hugetlb_madv_vs_map.c        |  2 +-
>  tools/testing/selftests/mm/uffd-stress.c      |  2 +-
>  7 files changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
> index 5961229b9931..4ae7332b5e1b 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.c
> +++ b/tools/testing/selftests/mm/hugepage_settings.c
> @@ -446,25 +446,6 @@ unsigned long default_huge_page_size(void)
>  	return hps;
>  }
>  
> -unsigned long get_free_hugepages(void)
> -{
> -	unsigned long fhp = 0;
> -	char *line = NULL;
> -	size_t linelen = 0;
> -	FILE *f = fopen("/proc/meminfo", "r");
> -
> -	if (!f)
> -		return fhp;
> -	while (getline(&line, &linelen, f) > 0) {
> -		if (sscanf(line, "HugePages_Free:      %lu", &fhp) == 1)
> -			break;
> -	}
> -
> -	free(line);
> -	fclose(f);
> -	return fhp;
> -}
> -
>  static void hugetlb_sysfs_path(char *buf, size_t buflen,
>  			       unsigned long size, const char *attr)
>  {
> @@ -489,3 +470,12 @@ void hugetlb_set_nr_pages(unsigned long size, unsigned long nr)
>  
>  	write_num(path, nr);
>  }
> +
> +unsigned long hugetlb_free_pages(unsigned long size)
> +{
> +	char path[PATH_MAX];
> +
> +	hugetlb_sysfs_path(path, sizeof(path), size, "free_hugepages");
> +
> +	return read_num(path);
> +}
> diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing/selftests/mm/hugepage_settings.h
> index d6f41a45e8ee..57fbf2f57e13 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.h
> +++ b/tools/testing/selftests/mm/hugepage_settings.h
> @@ -92,10 +92,10 @@ bool thp_is_enabled(void);
>  
>  int detect_hugetlb_page_sizes(unsigned long sizes[], int max);
>  unsigned long default_huge_page_size(void);
> -unsigned long get_free_hugepages(void);
>  
>  unsigned long hugetlb_nr_pages(unsigned long size);
>  void hugetlb_set_nr_pages(unsigned long size, unsigned long nr);
> +unsigned long hugetlb_free_pages(unsigned long size);
>  
>  static inline unsigned long hugetlb_nr_default_pages(void)
>  {
> @@ -117,4 +117,14 @@ static inline void hugetlb_set_nr_default_pages(unsigned long nr)
>  	hugetlb_set_nr_pages(size, nr);
>  }
>  
> +static inline unsigned long hugetlb_free_default_pages(void)
> +{
> +	unsigned long size = default_huge_page_size();
> +
> +	if (!size)
> +		return 0;
> +
> +	return hugetlb_free_pages(size);
> +}
> +
>  #endif /* __THP_SETTINGS_H__ */
> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
> index 316384d919db..3c08eb6db6a2 100644
> --- a/tools/testing/selftests/mm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c
> @@ -27,7 +27,7 @@
>  
>  #define validate_free_pages(exp_free)					\
>  	do {								\
> -		unsigned long fhp = get_free_hugepages();		\
> +		unsigned long fhp = hugetlb_free_default_pages();		\
>  		if (fhp != (exp_free))					\
>  			ksft_exit_fail_msg("Unexpected number of free "	\
>  				"huge pages %ld, expected %ld line %d\n", \
> @@ -68,7 +68,7 @@ int main(int argc, char **argv)
>  	if (!base_page_size)
>  		ksft_exit_fail_msg("Unable to determine base page size\n");
>  
> -	free_hugepages = get_free_hugepages();
> +	free_hugepages = hugetlb_free_default_pages();
>  	if (free_hugepages < MIN_FREE_PAGES)
>  		ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", free_hugepages, MIN_FREE_PAGES);
>  
> diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> index 81e3f7bc8e76..47019433ddaf 100644
> --- a/tools/testing/selftests/mm/hugetlb_dio.c
> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> @@ -93,7 +93,7 @@ static void run_dio_using_hugetlb(int fd, unsigned int start_off,
>  		ksft_exit_fail_perror("lseek failed\n");
>  
>  	/* Get the free huge pages before allocation */
> -	free_hpage_b = get_free_hugepages();
> +	free_hpage_b = hugetlb_free_default_pages();
>  	if (free_hpage_b == 0) {
>  		close(fd);
>  		ksft_exit_skip("No free hugepage, exiting!\n");
> @@ -121,7 +121,7 @@ static void run_dio_using_hugetlb(int fd, unsigned int start_off,
>  	munmap(orig_buffer, h_pagesize);
>  
>  	/* Get the free huge pages after unmap*/
> -	free_hpage_a = get_free_hugepages();
> +	free_hpage_a = hugetlb_free_default_pages();
>  
>  	ksft_print_msg("No. Free pages before allocation : %d\n", free_hpage_b);
>  	ksft_print_msg("No. Free pages after munmap : %d\n", free_hpage_a);
> @@ -142,7 +142,7 @@ int main(void)
>  	ksft_print_header();
>  
>  	/* Check if huge pages are free */
> -	if (!get_free_hugepages())
> +	if (!hugetlb_free_default_pages())
>  		ksft_exit_skip("No free hugepage, exiting\n");
>  
>  	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
> diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> index abc3904c5268..c718dd065d53 100644
> --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> @@ -78,7 +78,7 @@ int main(void)
>  	ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n",
>  		       huge_page_size / 1024);
>  
> -	free_hugepages = get_free_hugepages();
> +	free_hugepages = hugetlb_free_default_pages();
>  	if (free_hugepages != 1) {
>  		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
>  			       free_hugepages);
> diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> index ac60b4f18784..dfbd71a7f709 100644
> --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> @@ -89,7 +89,7 @@ int main(void)
>  	ksft_print_header();
>  	ksft_set_plan(1);
>  
> -	free_hugepages = get_free_hugepages();
> +	free_hugepages = hugetlb_free_default_pages();
>  
>  	if (free_hugepages != 1)
>  		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
> diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
> index e92a85463eb1..7e37cf3d27f6 100644
> --- a/tools/testing/selftests/mm/uffd-stress.c
> +++ b/tools/testing/selftests/mm/uffd-stress.c
> @@ -480,7 +480,7 @@ int main(int argc, char **argv)
>  	 * for racy extra reservation of hugepages.
>  	 */
>  	if (gopts->test_type == TEST_HUGETLB &&
> -	   get_free_hugepages() < 2 * (bytes / gopts->page_size) + gopts->nr_parallel - 1)
> +	   hugetlb_free_default_pages() < 2 * (bytes / gopts->page_size) + gopts->nr_parallel - 1)
>  		ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n");
>  
>  	gopts->nr_pages_per_cpu = bytes / gopts->page_size / gopts->nr_parallel;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 27/54] selftests/mm: hugepage_settings: add APIs for HugeTLB setup and teardown
       [not found] ` <20260428204240.1924129-28-rppt@kernel.org>
       [not found]   ` <2f443474-4448-462e-bc1e-55bc657d70ba@redhat.com>
@ 2026-05-06 11:17   ` Sarthak Sharma
  1 sibling, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 11:17 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> A lot of tests require free HugeTLB pages. Some need just a few default
> huge pages, some need a certain amount of memory available as HugeTLB, and
> some just skip lots of tests if huge pages of all supported sizes are not
> available.
> 
> This all resulted in a huge mess in run_vmtests.sh that sets up some huge
> pages, adjusts them later and restores some of the settings if the stars
> align.
> 
> Add APIs that allow saving the state of HugeTLB and setting up the desired
> amount of HugeTLB pages.
> 
> Saving the state also registers atexit() callback and signal handler that
> will ensure restoration of HugeTLB state.
> 
> Since many tests use both HugeTLB and THP, the atexit() callbacks and
> signal handler are restoring both.
> 
> For kselftest_harness tests that run fixture setups and test in child
> processes add a constructor that will save and restore settings in the main
> process.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 28/54] selftests/mm: move read_file(), read_num() and write_num() to vm_util
       [not found] ` <20260428204240.1924129-29-rppt@kernel.org>
@ 2026-05-06 11:36   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 11:36 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> These are useful helpers for writing and reading sysfs and proc files.
> 
> Make them available to the tests that don't use thp_settings.
> 
> While on it make write_num() use "%lu" instead of "%ld" to match
> 'unsigned long num' argument type.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 29/54] selftests/mm: vm_util: add helpers to set and restore shm limits
       [not found] ` <20260428204240.1924129-30-rppt@kernel.org>
@ 2026-05-06 12:01   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 12:01 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-shm and thuge-gen tests require that limits defined by
> /proc/sys/kernel/{shmmax,shmall} should be higher than certain values.
> 
> Add helpers that allow setting these limits and restoring their settings on
> a test exit.
> 
> They will be used later in hugetlb-shm and thuge-gen.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/vm_util.c | 28 ++++++++++++++++++++++++++++
>  tools/testing/selftests/mm/vm_util.h |  9 +++++++++
>  2 files changed, 37 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index 752566f75c0b..5a89c2d903be 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -761,3 +761,31 @@ void write_num(const char *path, unsigned long num)
>  	sprintf(buf, "%lu", num);
>  	write_file(path, buf, strlen(buf) + 1);
>  }
> +
> +static unsigned long shmall, shmmax;
> +
> +void __shm_limits_restore(void)
> +{
> +	if (shmmax)
> +		write_num("/proc/sys/kernel/shmmax", shmmax);
> +	if (shmall)
> +		write_num("/proc/sys/kernel/shmall", shmall);
> +}
> +
> +void shm_limits_prepare(unsigned long length)
> +{
> +	unsigned long nr = length / psize();
> +	unsigned long val;
> +
> +	val = read_num("/proc/sys/kernel/shmmax");
> +	if (val < length) {
> +		write_num("/proc/sys/kernel/shmmax", length);
> +		shmmax = val;
> +	}
> +
> +	val = read_num("/proc/sys/kernel/shmall");
> +	if (val < nr) {
> +		write_num("/proc/sys/kernel/shmall", nr);
> +		shmall = val;
> +	}
> +}
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 5fc9707f6b9a..ea8fc8fdf0eb 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -168,3 +168,12 @@ void write_file(const char *path, const char *buf, size_t buflen);
>  int read_file(const char *path, char *buf, size_t buflen);
>  unsigned long read_num(const char *path);
>  void write_num(const char *path, unsigned long num);
> +
> +void shm_limits_prepare(unsigned long length);
> +void __shm_limits_restore(void);
> +
> +#define SHM_LIMITS_RESTORE()						\
> +static void __attribute__((destructor)) shm_limits_restore(void)	\
> +{									\
> +	__shm_limits_restore();						\
> +}


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 32/54] selftests/mm: gup_longterm: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-33-rppt@kernel.org>
@ 2026-05-06 12:14   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 12:14 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> gup_longterm tests skips HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, many tests were skipped with the message "need more free huge
pages". After the patch, these tests passed successfully.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/gup_longterm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
> index ab4eaf4feb7c..6e1de12bf28c 100644
> --- a/tools/testing/selftests/mm/gup_longterm.c
> +++ b/tools/testing/selftests/mm/gup_longterm.c
> @@ -510,7 +510,7 @@ int main(int argc, char **argv)
>  	int i;
>  
>  	pagesize = getpagesize();
> -	nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes,
> +	nr_hugetlbsizes = hugetlb_setup(2, hugetlbsizes,
>  						    ARRAY_SIZE(hugetlbsizes));
>  
>  	ksft_print_header();


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 33/54] selftests/mm: gup_test: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-34-rppt@kernel.org>
@ 2026-05-06 12:29   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-06 12:29 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> gup_test fails to run HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the
> original settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I ran the test with the -H flag before and after applying the patch.
Before the patch, the test bailed out with "mmap: Cannot allocate
memory". After the patch, it automatically detects and allocates
hugepages and the test passes successfully.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/gup_test.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftests/mm/gup_test.c
> index fb8f9ae49efa..ddd239a69881 100644
> --- a/tools/testing/selftests/mm/gup_test.c
> +++ b/tools/testing/selftests/mm/gup_test.c
> @@ -14,6 +14,7 @@
>  #include <mm/gup_test.h>
>  #include "kselftest.h"
>  #include "vm_util.h"
> +#include "hugepage_settings.h"
>  
>  #define MB (1UL << 20)
>  
> @@ -94,6 +95,7 @@ int main(int argc, char **argv)
>  	int filed, i, opt, nr_pages = 1, thp = -1, write = 1, nthreads = 1, ret;
>  	int flags = MAP_PRIVATE;
>  	char *file = "/dev/zero";
> +	bool hugetlb = false;
>  	pthread_t *tid;
>  	char *p;
>  
> @@ -168,6 +170,7 @@ int main(int argc, char **argv)
>  			break;
>  		case 'H':
>  			flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
> +			hugetlb = true;
>  			break;
>  		default:
>  			ksft_exit_fail_msg("Wrong argument\n");
> @@ -199,6 +202,15 @@ int main(int argc, char **argv)
>  	}
>  
>  	ksft_print_header();
> +
> +	if (hugetlb) {
> +		unsigned long hp_size = default_huge_page_size();
> +
> +		size = (size + hp_size - 1) & ~(hp_size - 1);
> +		if (!hugetlb_setup_default(size / hp_size))
> +			ksft_exit_skip("Not enough huge pages\n");
> +	}
> +
>  	ksft_set_plan(nthreads);
>  
>  	filed = open(file, O_RDWR|O_CREAT, 0664);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 36/54] selftests/mm: hugetlb_fault_after_madv: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-37-rppt@kernel.org>
@ 2026-05-07  9:53   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07  9:53 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb_fault_after_madv test skips testing if there are no free huge
> pages prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, the test skipped if there was not exactly 1 free hugepage
available. After the patch, it correctly allocates one hugepage and the
test passes successfully, restoring the original hugepage settings on exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugetlb_fault_after_madv.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> index c718dd065d53..481863cc5fda 100644
> --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
> @@ -54,7 +54,6 @@ void *madv(void *unused)
>  
>  int main(void)
>  {
> -	unsigned long free_hugepages;
>  	pthread_t thread1, thread2;
>  	/*
>  	 * On kernel 6.4, we are able to reproduce the problem with ~1000
> @@ -78,10 +77,9 @@ int main(void)
>  	ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n",
>  		       huge_page_size / 1024);
>  
> -	free_hugepages = hugetlb_free_default_pages();
> -	if (free_hugepages != 1) {
> +	if (!hugetlb_setup_default(1)) {
>  		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
> -			       free_hugepages);
> +			       hugetlb_free_default_pages());
>  	}
>  
>  	while (max--) {


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 37/54] selftests/mm: hugetlb-madvise: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-38-rppt@kernel.org>
@ 2026-05-07 10:28   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 10:28 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-madvise test skips testing if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run this test before and after applying the patch. Before the
patch, the test skipped if the required hugepages were not allocated.
After the patch, it correctly allocates the required hugepages and
passes successfully, restoring the original hugepage settings at exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugetlb-madvise.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
> index 3c08eb6db6a2..b20648d025e6 100644
> --- a/tools/testing/selftests/mm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c
> @@ -68,9 +68,9 @@ int main(int argc, char **argv)
>  	if (!base_page_size)
>  		ksft_exit_fail_msg("Unable to determine base page size\n");
>  
> +	if (!hugetlb_setup_default(MIN_FREE_PAGES))
> +		ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", hugetlb_free_default_pages(), MIN_FREE_PAGES);
>  	free_hugepages = hugetlb_free_default_pages();
> -	if (free_hugepages < MIN_FREE_PAGES)
> -		ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", free_hugepages, MIN_FREE_PAGES);
>  
>  	fd = memfd_create(argv[0], MFD_HUGETLB);
>  	if (fd < 0)


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 38/54] selftests/mm: hugetlb_madv_vs_map: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-39-rppt@kernel.org>
@ 2026-05-07 10:32   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 10:32 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb_madv_vs_map test skips testing if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, the test skipped if there was not exactly 1 free hugepage
available. After the patch, it correctly allocates one hugepage and the
test passes successfully, restoring the original hugepage settings on exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> index dfbd71a7f709..6c95dd23ca81 100644
> --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> @@ -77,7 +77,6 @@ void *map_extra(void *unused)
>  int main(void)
>  {
>  	pthread_t thread1, thread2, thread3;
> -	unsigned long free_hugepages;
>  	void *ret;
>  
>  	/*
> @@ -89,11 +88,9 @@ int main(void)
>  	ksft_print_header();
>  	ksft_set_plan(1);
>  
> -	free_hugepages = hugetlb_free_default_pages();
> -
> -	if (free_hugepages != 1)
> +	if (!hugetlb_setup_default(1))
>  		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
> -			       free_hugepages);
> +			       hugetlb_free_default_pages());
>  
>  	mmap_size = default_huge_page_size();
>  


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 39/54] selftests/mm: hugetlb-mmap: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-40-rppt@kernel.org>
@ 2026-05-07 10:38   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 10:38 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-mmap test fails if there are no free huge pages prepared by a
> wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, the test bailed out with mmap error if hugepages were not
preallocated. After the patch, the test correctly allocates the required
hugepages and successfully passes.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugetlb-mmap.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-mmap.c b/tools/testing/selftests/mm/hugetlb-mmap.c
> index 031085cb7d17..f12fc288ef4f 100644
> --- a/tools/testing/selftests/mm/hugetlb-mmap.c
> +++ b/tools/testing/selftests/mm/hugetlb-mmap.c
> @@ -109,16 +109,16 @@ int main(int argc, char **argv)
>  {
>  	size_t hugepage_size;
>  	size_t length = LENGTH;
> -	int shift = 0;
> +	int shift = 0, nr;
>  
>  	ksft_print_header();
> -	ksft_set_plan(2);
>  
>  	if (argc > 1)
>  		length = atol(argv[1]) << 20;
>  	if (argc > 2)
>  		shift = atoi(argv[2]);
>  
> +	hugetlb_save_settings();
>  	if (shift) {
>  		hugepage_size = (1 << shift);
>  		ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10));
> @@ -128,9 +128,14 @@ int main(int argc, char **argv)
>  	}
>  
>  	/* munmap with fail if the length is not page aligned */
> -	if (hugepage_size > length)
> -		length = hugepage_size;
> +	length = (length + hugepage_size - 1) & ~(hugepage_size - 1);
> +	nr = length / hugepage_size;
> +
> +	hugetlb_set_nr_pages(hugepage_size, nr);
> +	if (hugetlb_free_pages(hugepage_size) < nr)
> +		ksft_exit_skip("Not enough %lu Kb pages\n", hugepage_size >> 10);
>  
> +	ksft_set_plan(2);
>  	ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
>  
>  	test_anon_mmap(length, shift);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 43/54] selftests/mm: hugetlb-vmemmap: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-44-rppt@kernel.org>
@ 2026-05-07 11:27   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 11:27 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> hugetlb-vmemmap test fails if there are no free huge pages prepared by a
> wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, the test bailed out with mmap error if there was not exactly 1
free hugepage. After the patch, the test correctly allocates the
hugepage and successfully passes, restoring the hugepage settings at exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/hugetlb-vmemmap.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> index af5786bebfd1..507df78a158d 100644
> --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c
> +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> @@ -97,6 +97,9 @@ int main(int argc, char **argv)
>  	ksft_print_header();
>  	ksft_set_plan(1);
>  
> +	if (!hugetlb_setup_default(1))
> +		ksft_exit_skip("Not enough free huge pages\n");
> +
>  	pagesize  = psize();
>  	maplength = default_huge_page_size();
>  	if (!maplength)


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 44/54] selftests/mm: migration: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-45-rppt@kernel.org>
@ 2026-05-07 11:36   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 11:36 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> migration skips HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Since kselftest_harness runs fixture setup and the tests in child
> processes, use HUGETLB_SETUP_DEFAULT_PAGES() that defines a constructor
> that runs in the main process and add verification that there are enough
> free huge pages to the tests that use them.
> 
> Reset signal handlers to defaults in FIXTURE_SETUP() so that sending
> SIGTERM and SIGHUP during the tests won't cause restoration of HugeTLB
> settings.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, the hugetlb subtests failed with MAP_FAILED because hugepages
were not preallocated. After the patch, those subtests correctly
allocate the required hugepages and pass successfully, restoring the
original settings at exit.

Tested-by: Sarthak Sharma sarthak.sharma@arm.com

> ---
>  tools/testing/selftests/mm/migration.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c
> index 0212cd5bde6e..f212c1b06455 100644
> --- a/tools/testing/selftests/mm/migration.c
> +++ b/tools/testing/selftests/mm/migration.c
> @@ -23,6 +23,8 @@
>  #define MAX_RETRIES	100
>  #define ALIGN(x, a)	(((x) + (a - 1)) & (~((a) - 1)))
>  
> +HUGETLB_SETUP_DEFAULT_PAGES(1)
> +
>  FIXTURE(migration)
>  {
>  	pthread_t *threads;
> @@ -32,10 +34,21 @@ FIXTURE(migration)
>  	int n2;
>  };
>  
> +static void reset_signals(void)
> +{
> +	struct sigaction sa = { .sa_handler = SIG_DFL };
> +
> +	sigemptyset(&sa.sa_mask);
> +	sigaction(SIGTERM, &sa, NULL);
> +	sigaction(SIGHUP, &sa, NULL);
> +}
> +
>  FIXTURE_SETUP(migration)
>  {
>  	int n;
>  
> +	reset_signals();
> +
>  	if (numa_available() < 0)
>  		SKIP(return, "NUMA not available");
>  	self->nthreads = numa_num_task_cpus() - 2;
> @@ -271,6 +284,9 @@ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIME)
>  	if (!hugepage_size)
>  		SKIP(return, "Reading HugeTLB pagesize failed\n");
>  
> +	if (hugetlb_free_default_pages() < 1)
> +		SKIP(return, "Not enough huge pages\n");
> +
>  	ptr = mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE,
>  		MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
>  	ASSERT_NE(ptr, MAP_FAILED);
> @@ -299,6 +315,9 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME)
>  	if (!hugepage_size)
>  		SKIP(return, "Reading HugeTLB pagesize failed\n");
>  
> +	if (hugetlb_free_default_pages() < 1)
> +		SKIP(return, "Not enough huge pages\n");
> +
>  	ptr = mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE,
>  		MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
>  	ASSERT_NE(ptr, MAP_FAILED);


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 45/54] selftests/mm: pagemap_ioctl: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-46-rppt@kernel.org>
@ 2026-05-07 11:41   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 11:41 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> pagemap-ioctl skips HugeTLB tests if there are no free huge pages
> prepared by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I have run the test before and after applying the patch. Before the
patch, 18 HugeTLB subtests were skipped due to no preallocated
hugepages. After the patch, those subtests correctly allocate the
required hugepages and successfully pass.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/pagemap_ioctl.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
> index 7f9428d6062c..e2c62cb6978f 100644
> --- a/tools/testing/selftests/mm/pagemap_ioctl.c
> +++ b/tools/testing/selftests/mm/pagemap_ioctl.c
> @@ -7,8 +7,6 @@
>  #include <sys/mman.h>
>  #include <errno.h>
>  #include <malloc.h>
> -#include "vm_util.h"
> -#include "kselftest.h"
>  #include <linux/types.h>
>  #include <linux/memfd.h>
>  #include <linux/userfaultfd.h>
> @@ -23,6 +21,10 @@
>  #include <sys/ipc.h>
>  #include <sys/shm.h>
>  
> +#include "vm_util.h"
> +#include "kselftest.h"
> +#include "hugepage_settings.h"
> +
>  #define PAGEMAP_BITS_ALL		(PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN |	\
>  					 PAGE_IS_FILE | PAGE_IS_PRESENT |	\
>  					 PAGE_IS_SWAPPED | PAGE_IS_PFNZERO |	\
> @@ -1554,6 +1556,9 @@ int main(int __attribute__((unused)) argc, char *argv[])
>  	if (init_uffd())
>  		ksft_exit_skip("Failed to initialize userfaultfd\n");
>  
> +	if (!hugetlb_setup_default(4))
> +		ksft_exit_skip("Not enough huge pages\n");
> +
>  	ksft_set_plan(117);
>  
>  	page_size = getpagesize();
> @@ -1605,7 +1610,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
>  	}
>  
>  	/* 5. SHM Hugetlb page testing */
> -	mem_size = 2*1024*1024;
> +	mem_size = default_huge_page_size();
>  	mem = gethugetlb_mem(mem_size, &shmid);
>  	if (mem) {
>  		wp_init(mem, mem_size);
> @@ -1633,7 +1638,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
>  	}
>  
>  	/* 7. File Hugetlb testing */
> -	mem_size = 2*1024*1024;
> +	mem_size = default_huge_page_size();
>  	fd = memfd_create("uffd-test", MFD_HUGETLB | MFD_NOEXEC_SEAL);
>  	if (fd < 0)
>  		ksft_exit_fail_msg("uffd-test creation failed %d %s\n", errno, strerror(errno));


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 47/54] selftests/mm: thuge-gen: add setup of HugeTLB pages
       [not found] ` <20260428204240.1924129-48-rppt@kernel.org>
@ 2026-05-07 11:50   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 11:50 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> thuge-gen skips tests if there are no free huge pages prepared by a wrapper
> script and shm liimts in proc are too low.
> 
> Replace custom detection of huge pages with the library functions and add
> setup of HugeTLB pages and shm limits to the test and make sure that the
> original settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---

I have run the test before and after applying the patch. Before the
patch, all test sizes were skipped because hugepages were not
preallocated. After the patch, the test correctly allocates the required
hugepages and all tests pass, with the original settings restored at exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 48/54] selftests/mm: uffd-stress: use hugetlb_save and alloc huge pages
       [not found] ` <20260428204240.1924129-49-rppt@kernel.org>
@ 2026-05-07 11:58   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 11:58 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> uffd-stress skips HugeTLB tests if there are no free huge pages prepared
> by a wrapper script.
> 
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

I ran the test using ./uffd-stress hugetlb 16 20

Before the patch, the test skipped with "not enough hugepages". After
the patch, the test correctly allocates the required hugepages and
passes successfully, restoring the original settings at exit.

Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/uffd-stress.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
> index 7e37cf3d27f6..9693d042f16f 100644
> --- a/tools/testing/selftests/mm/uffd-stress.c
> +++ b/tools/testing/selftests/mm/uffd-stress.c
> @@ -479,9 +479,12 @@ int main(int argc, char **argv)
>  	 * Ensure nr_parallel - 1 hugepages on top of that to account
>  	 * for racy extra reservation of hugepages.
>  	 */
> -	if (gopts->test_type == TEST_HUGETLB &&
> -	   hugetlb_free_default_pages() < 2 * (bytes / gopts->page_size) + gopts->nr_parallel - 1)
> -		ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n");
> +	if (gopts->test_type == TEST_HUGETLB) {
> +		unsigned long nr = 2 * (bytes / gopts->page_size) + gopts->nr_parallel - 1;
> +
> +		if (!hugetlb_setup_default(nr))
> +			ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n");
> +	}
>  
>  	gopts->nr_pages_per_cpu = bytes / gopts->page_size / gopts->nr_parallel;
>  	if (!gopts->nr_pages_per_cpu) {


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 53/54] selftests/mm: run_vmtests.sh: free memory if available memory is low
       [not found] ` <20260428204240.1924129-54-rppt@kernel.org>
@ 2026-05-07 12:07   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 12:07 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> Currently when running THP and HugeTLB tests, if HAVE_HUGEPAGES is set
> run_test() drops caches, compacts memory and runs the test. But if
> HAVE_HUGEPAGES is not set it skips the tests entirely, even if THP tests
> have nothing to do with HAVE_HUGEPAGES.
> 
> Replace the check if HAVE_HUGEPAGES is set with a check of how much memory
> is available. If there is less than 256 MB of available memory, drop caches
> and run compaction and then continue to run a test regardless of
> HAVE_HUGEPAGES value.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

This patch looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

> ---
>  tools/testing/selftests/mm/run_vmtests.sh | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index b9e520194634..b42d19036182 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -99,6 +99,9 @@ EOF
>  	exit 0
>  }
>  
> +mem_available_kb=$(awk '/MemAvailable/ {print $2}' /proc/meminfo)
> +mem_available_Mb=$((mem_available_kb / 1024))
> +
>  RUN_ALL=false
>  RUN_DESTRUCTIVE=false
>  TAP_PREFIX="# "
> @@ -239,15 +242,12 @@ run_test() {
>  		# On memory constrainted systems some tests can fail to allocate hugepages.
>  		# perform some cleanup before the test for a higher success rate.
>  		if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then
> -			if [ "${HAVE_HUGEPAGES}" = "1" ]; then
> -				echo 3 > /proc/sys/vm/drop_caches
> -				sleep 2
> -				echo 1 > /proc/sys/vm/compact_memory
> -				sleep 2
> -			else
> -				echo "hugepages not supported" | tap_prefix
> -				skip=1
> -			fi
> +		    if (( $mem_available_Mb < 256 )); then
> +			echo 3 > /proc/sys/vm/drop_caches
> +			sleep 2
> +			echo 1 > /proc/sys/vm/compact_memory
> +			sleep 2
> +		    fi
>  		fi
>  
>  		local test=$(pretty_name "$*")


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 54/54] selftests/mm: run_vmtests.sh: drop detection and setup of HugeTLB
       [not found] ` <20260428204240.1924129-55-rppt@kernel.org>
@ 2026-05-07 12:10   ` Sarthak Sharma
  0 siblings, 0 replies; 34+ messages in thread
From: Sarthak Sharma @ 2026-05-07 12:10 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, David Hildenbrand
  Cc: Baolin Wang, Barry Song, Dev Jain, Donet Tom, Jason Gunthorpe,
	John Hubbard, Liam R. Howlett, Lance Yang, Leon Romanovsky,
	Lorenzo Stoakes, Luiz Capitulino, Mark Brown, Michal Hocko,
	Nico Pache, Peter Xu, Ryan Roberts, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, Zi Yan, linux-kernel,
	linux-kselftest, linux-mm



On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> All the tests that use HugeTLB can detect and setup HugeTLB pages on
> their own.
> 
> Drop detection and setup of HugeTLB from run_vmtests.sh.
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---

This patch looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 35/54] selftests/mm: hugepage_dio: add setup of HugeTLB pages
  2026-05-04 12:20   ` [PATCH v3 35/54] selftests/mm: hugepage_dio: add setup of HugeTLB pages Sarthak Sharma
@ 2026-05-11  8:25     ` Mike Rapoport
  0 siblings, 0 replies; 34+ messages in thread
From: Mike Rapoport @ 2026-05-11  8:25 UTC (permalink / raw)
  To: Sarthak Sharma
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Barry Song,
	Dev Jain, Donet Tom, Jason Gunthorpe, John Hubbard,
	Liam R. Howlett, Lance Yang, Leon Romanovsky, Lorenzo Stoakes,
	Luiz Capitulino, Mark Brown, Michal Hocko, Nico Pache, Peter Xu,
	Ryan Roberts, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	Zi Yan, linux-kernel, linux-kselftest, linux-mm

Hi Sarthak,

On Mon, May 04, 2026 at 05:50:06PM +0530, Sarthak Sharma wrote:
> On 4/29/26 2:12 AM, Mike Rapoport wrote:
> > @@ -141,8 +135,8 @@ int main(void)
> >  
> >  	ksft_print_header();
> >  
> > -	/* Check if huge pages are free */
> > -	if (!hugetlb_free_default_pages())
> > +	/* request a huge page */
> > +	if (!hugetlb_setup_default(1))
> >  		ksft_exit_skip("No free hugepage, exiting\n");
> 
> Before applying the patch, I get the following output:
> 
> TAP version 13
> 1..4
> # No. Free pages before allocation : 112
> # No. Free pages after munmap : 112
> ok 1 free huge pages from 0-12288
> # No. Free pages before allocation : 112
> # No. Free pages after munmap : 112
> ok 2 free huge pages from 0-10240
> # No. Free pages before allocation : 112
> # No. Free pages after munmap : 112
> ok 3 free huge pages from 2048-12288
> # No. Free pages before allocation : 112
> # No. Free pages after munmap : 112
> ok 4 free huge pages from 2048-14336
> # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> After applying the patch, I get this:
> 
> TAP version 13
> # [INFO] detected hugetlb page size: 2048 KiB
> # [INFO] detected hugetlb page size: 32768 KiB
> # [INFO] detected hugetlb page size: 64 KiB
> # [INFO] detected hugetlb page size: 1048576 KiB
> 1..0 # SKIP No free hugepage, exiting
> 
> even when I have 112 free and 128 total hugepages of size 2MB (default
> for my system).
> 
> Could it be because hugetlb_setup_default(1) here is trying to set the
> default hugetlb pool size to exactly 1, and then checking whether there
> is exactly 1 free hugepage, instead of simply checking whether at least
> 1 free hugepage is available?

I'm going to update hugetlb_setup_default() to check if there are enough
free huge pages and add more if necessary and I will add
hugetlb_setup_default_exact() for tests that require exact number of huge
pages.
 
> >  
> >  	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 42/54] selftests/mm: hugetlb-soft-online: add setup of HugeTLB pages
  2026-05-05  7:15   ` [PATCH v3 42/54] selftests/mm: hugetlb-soft-online: " Sarthak Sharma
@ 2026-05-11  8:25     ` Mike Rapoport
  0 siblings, 0 replies; 34+ messages in thread
From: Mike Rapoport @ 2026-05-11  8:25 UTC (permalink / raw)
  To: Sarthak Sharma
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Barry Song,
	Dev Jain, Donet Tom, Jason Gunthorpe, John Hubbard,
	Liam R. Howlett, Lance Yang, Leon Romanovsky, Lorenzo Stoakes,
	Luiz Capitulino, Mark Brown, Michal Hocko, Nico Pache, Peter Xu,
	Ryan Roberts, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	Zi Yan, linux-kernel, linux-kselftest, linux-mm

Hi Sarthak,

On Tue, May 05, 2026 at 12:45:52PM +0530, Sarthak Sharma wrote:
> Hi Mike!
> 
> On 4/29/26 2:12 AM, Mike Rapoport wrote:
> > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> > 
> > hugetlb-soft-online test uses open coded access to /proc to determine
> > availability of huge pages and fails if there are no enough free huget
> > pages..
> > 
> > Replace open coded access to /proc with hugepage helpers and add setup
> > of HugeTLB pages to the test and make sure that the original settings
> > are restored on the test exit.
> > 
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> 
> The test is hugetlb-soft-offline, so let's change the commit title and
> commit message to say "offine" instead of "online".

Good catch :)
 
> I have run the test before and after applying the patch. Before the
> patch, it failed with an mmap error when hugepages were not
> preallocated. After applying the patch, the test correctly allocates the
> required hugepages and the test passes.
> 
> Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v3 49/54] selftests/mm: uffd-unit-tests: add setup of HugeTLB pages
  2026-05-05 11:48   ` [PATCH v3 49/54] selftests/mm: uffd-unit-tests: " Sarthak Sharma
@ 2026-05-11  8:28     ` Mike Rapoport
  0 siblings, 0 replies; 34+ messages in thread
From: Mike Rapoport @ 2026-05-11  8:28 UTC (permalink / raw)
  To: Sarthak Sharma
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Barry Song,
	Dev Jain, Donet Tom, Jason Gunthorpe, John Hubbard,
	Liam R. Howlett, Lance Yang, Leon Romanovsky, Lorenzo Stoakes,
	Luiz Capitulino, Mark Brown, Michal Hocko, Nico Pache, Peter Xu,
	Ryan Roberts, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	Zi Yan, linux-kernel, linux-kselftest, linux-mm

Hi Sarthak,

On Tue, May 05, 2026 at 05:18:38PM +0530, Sarthak Sharma wrote:
> On 4/29/26 2:12 AM, Mike Rapoport wrote:
> > @@ -1771,7 +1794,7 @@ int main(int argc, char *argv[])
> >  			uffd_test_case_ops = test->test_case_ops;
> >  
> >  			if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE | MEM_HUGETLB)) {
> > -				gopts.page_size = default_huge_page_size();
> > +				gopts.page_size = hugepage_size;
> >  				if (gopts.page_size == 0) {
> >  					uffd_test_skip("huge page size is 0, feature missing?");
> 
> A small nit, after this patch, uffd_setup_hugetlb() can return 0 in 2 cases:
> 
> a) default_huge_page_size() == 0
> b) hugetlb_free_default_pages() < nr_hugepages
> 
> The skip message only covers the first case and would be misleading for
> the second case. Should we differentiate both these using different skip
> messages?

I'm more inclined to have a single "Not enough huge pages" message to keep
the things simple.
 
> >  					continue;
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2026-05-11  8:28 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260428204240.1924129-1-rppt@kernel.org>
     [not found] ` <20260428204240.1924129-36-rppt@kernel.org>
2026-05-04 12:20   ` [PATCH v3 35/54] selftests/mm: hugepage_dio: add setup of HugeTLB pages Sarthak Sharma
2026-05-11  8:25     ` Mike Rapoport
     [not found] ` <20260428204240.1924129-41-rppt@kernel.org>
2026-05-05  6:51   ` [PATCH v3 40/54] selftests/mm: hugetlb-mremap: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-43-rppt@kernel.org>
2026-05-05  7:15   ` [PATCH v3 42/54] selftests/mm: hugetlb-soft-online: " Sarthak Sharma
2026-05-11  8:25     ` Mike Rapoport
     [not found] ` <20260428204240.1924129-51-rppt@kernel.org>
2026-05-05 11:27   ` [PATCH v3 50/54] selftests/mm: uffd-wp-mremap: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-42-rppt@kernel.org>
2026-05-05 11:33   ` [PATCH v3 41/54] selftests/mm: hugetlb-shm: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-50-rppt@kernel.org>
2026-05-05 11:48   ` [PATCH v3 49/54] selftests/mm: uffd-unit-tests: " Sarthak Sharma
2026-05-11  8:28     ` Mike Rapoport
     [not found] ` <20260428204240.1924129-31-rppt@kernel.org>
     [not found]   ` <daa3e21f-0c48-456e-a4a8-198a8c907b9d@arm.com>
2026-05-05 15:26     ` [PATCH v3 30/54] selftests/mm: compaction_test: use HugeTLB helpers Mike Rapoport
     [not found] ` <20260428204240.1924129-18-rppt@kernel.org>
2026-05-06  8:57   ` [PATCH v3 17/54] selftests/mm: protection_keys: use kselftest framework Sarthak Sharma
     [not found] ` <20260428204240.1924129-21-rppt@kernel.org>
2026-05-06  9:02   ` [PATCH v3 20/54] selftests/mm: va_high_addr_switch: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-23-rppt@kernel.org>
2026-05-06  9:12   ` [PATCH v3 22/54] selftests/mm: rename thp_settings.[ch] to hugepage_settings.[ch] Sarthak Sharma
     [not found] ` <20260428204240.1924129-24-rppt@kernel.org>
2026-05-06  9:14   ` [PATCH v3 23/54] selftests/mm: move HugeTLB helpers to hugepage_settings Sarthak Sharma
     [not found] ` <20260428204240.1924129-25-rppt@kernel.org>
2026-05-06  9:23   ` [PATCH v3 24/54] selftests/mm: hugepage_settings: use unsigned long in detect_hugetlb_page_size Sarthak Sharma
     [not found] ` <20260428204240.1924129-26-rppt@kernel.org>
2026-05-06 10:12   ` [PATCH v3 25/54] selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages Sarthak Sharma
     [not found] ` <20260428204240.1924129-27-rppt@kernel.org>
2026-05-06 11:03   ` [PATCH v3 26/54] selftests/mm: hugepage_settings: rename get_free_hugepages() Sarthak Sharma
     [not found] ` <20260428204240.1924129-28-rppt@kernel.org>
     [not found]   ` <2f443474-4448-462e-bc1e-55bc657d70ba@redhat.com>
     [not found]     ` <afTF9RCy8eBoWYaj@kernel.org>
     [not found]       ` <22b1cadc-4b0d-4e2a-987c-e7a7bc2265eb@redhat.com>
     [not found]         ` <afV_WAK56lQKn_z1@kernel.org>
2026-05-04 13:04           ` [PATCH v3 27/54] selftests/mm: hugepage_settings: add APIs for HugeTLB setup and teardown Luiz Capitulino
2026-05-06 11:17   ` Sarthak Sharma
     [not found] ` <20260428204240.1924129-29-rppt@kernel.org>
2026-05-06 11:36   ` [PATCH v3 28/54] selftests/mm: move read_file(), read_num() and write_num() to vm_util Sarthak Sharma
     [not found] ` <20260428204240.1924129-30-rppt@kernel.org>
2026-05-06 12:01   ` [PATCH v3 29/54] selftests/mm: vm_util: add helpers to set and restore shm limits Sarthak Sharma
     [not found] ` <20260428204240.1924129-33-rppt@kernel.org>
2026-05-06 12:14   ` [PATCH v3 32/54] selftests/mm: gup_longterm: add setup of HugeTLB pages Sarthak Sharma
     [not found] ` <20260428204240.1924129-34-rppt@kernel.org>
2026-05-06 12:29   ` [PATCH v3 33/54] selftests/mm: gup_test: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-37-rppt@kernel.org>
2026-05-07  9:53   ` [PATCH v3 36/54] selftests/mm: hugetlb_fault_after_madv: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-38-rppt@kernel.org>
2026-05-07 10:28   ` [PATCH v3 37/54] selftests/mm: hugetlb-madvise: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-39-rppt@kernel.org>
2026-05-07 10:32   ` [PATCH v3 38/54] selftests/mm: hugetlb_madv_vs_map: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-40-rppt@kernel.org>
2026-05-07 10:38   ` [PATCH v3 39/54] selftests/mm: hugetlb-mmap: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-44-rppt@kernel.org>
2026-05-07 11:27   ` [PATCH v3 43/54] selftests/mm: hugetlb-vmemmap: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-45-rppt@kernel.org>
2026-05-07 11:36   ` [PATCH v3 44/54] selftests/mm: migration: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-46-rppt@kernel.org>
2026-05-07 11:41   ` [PATCH v3 45/54] selftests/mm: pagemap_ioctl: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-48-rppt@kernel.org>
2026-05-07 11:50   ` [PATCH v3 47/54] selftests/mm: thuge-gen: " Sarthak Sharma
     [not found] ` <20260428204240.1924129-49-rppt@kernel.org>
2026-05-07 11:58   ` [PATCH v3 48/54] selftests/mm: uffd-stress: use hugetlb_save and alloc huge pages Sarthak Sharma
     [not found] ` <20260428204240.1924129-54-rppt@kernel.org>
2026-05-07 12:07   ` [PATCH v3 53/54] selftests/mm: run_vmtests.sh: free memory if available memory is low Sarthak Sharma
     [not found] ` <20260428204240.1924129-55-rppt@kernel.org>
2026-05-07 12:10   ` [PATCH v3 54/54] selftests/mm: run_vmtests.sh: drop detection and setup of HugeTLB Sarthak Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox