Skip to contentSkip to conversation

selftests/mm: Move default_huge_page_size to vm_util.c

PATCH In review Leon Hwang 4 participants 11 messages Oct 22, 2025

Subsystems (2)
lore
Share & tools
lore

Leon Hwang

author
#0 lore raw

PATCH 1/1 selftests/mm: Move default_huge_page_size to vm_util.c

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)
tools/testing/selftests/vm/Makefile +1 -0
index 192ea3725c5c..ed90deebef0d 100644
@@ -100,6 +100,7 @@ $(OUTPUT)/madv_populate: vm_util.c
 $(OUTPUT)/soft-dirty: vm_util.c
 $(OUTPUT)/split_huge_page_test: vm_util.c
 $(OUTPUT)/userfaultfd: vm_util.c
+$(OUTPUT)/map_hugetlb: vm_util.c
 
 ifeq ($(MACHINE),x86_64)
 BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
tools/testing/selftests/vm/userfaultfd.c +0 -24
index 297f250c1d95..4751b28eba18 100644
@@ -1674,30 +1674,6 @@ static int userfaultfd_stress(void)
 		|| userfaultfd_events_test() || userfaultfd_minor_test();
 }
 
-/*
- * Copied from mlock2-tests.c
- */
-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;
-}
-
 static void set_test_type(const char *type)
 {
 	if (!strcmp(type, "anon")) {
tools/testing/selftests/vm/vm_util.c +21 -0
index fc5743bc1283..613cc61602c9 100644
@@ -161,6 +161,27 @@ bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size)
 	return __check_huge(addr, "ShmemPmdMapped:", nr_hpages, hpage_size);
 }
 
+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;
+}
+
 static bool check_vmflag(void *addr, const char *flag)
 {
 	char buffer[MAX_LINE_LENGTH];
tools/testing/selftests/vm/vm_util.h +1 -0
index 470f85fe9594..a4439db0d6f8 100644
@@ -11,4 +11,5 @@ uint64_t read_pmd_pagesize(void);
 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);
+unsigned long default_huge_page_size(void);
 bool softdirty_supported(void);
Signature · 1 line
2.43.0
#1 lore raw

+Cc: Greg

Quoted 110 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

    79 |         hugepage_size = default_huge_page_size();
       |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

---
  tools/testing/selftests/vm/Makefile      |  1 +
  tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
  tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
  tools/testing/selftests/vm/vm_util.h     |  1 +
  4 files changed, 23 insertions(+), 24 deletions(-)
tools/testing/selftests/vm/Makefile +1 -0
index 192ea3725c5c..ed90deebef0d 100644
@@ -100,6 +100,7 @@ $(OUTPUT)/madv_populate: vm_util.c
  $(OUTPUT)/soft-dirty: vm_util.c
  $(OUTPUT)/split_huge_page_test: vm_util.c
  $(OUTPUT)/userfaultfd: vm_util.c
+$(OUTPUT)/map_hugetlb: vm_util.c
 
  ifeq ($(MACHINE),x86_64)
  BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
tools/testing/selftests/vm/userfaultfd.c +0 -24
index 297f250c1d95..4751b28eba18 100644
@@ -1674,30 +1674,6 @@ static int userfaultfd_stress(void)
  		|| userfaultfd_events_test() || userfaultfd_minor_test();
  }
 
-/*
- * Copied from mlock2-tests.c
- */
-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;
-}
-
  static void set_test_type(const char *type)
  {
  	if (!strcmp(type, "anon")) {
tools/testing/selftests/vm/vm_util.c +21 -0
index fc5743bc1283..613cc61602c9 100644
@@ -161,6 +161,27 @@ bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size)
  	return __check_huge(addr, "ShmemPmdMapped:", nr_hpages, hpage_size);
  }
 
+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;
+}
+
  static bool check_vmflag(void *addr, const char *flag)
  {
  	char buffer[MAX_LINE_LENGTH];
tools/testing/selftests/vm/vm_util.h +1 -0
index 470f85fe9594..a4439db0d6f8 100644
@@ -11,4 +11,5 @@ uint64_t read_pmd_pagesize(void);
  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);
+unsigned long default_huge_page_size(void);
  bool softdirty_supported(void);
maintainer
#2 lore raw
Quoted 1 line · Lance Yang

+Cc: Greg

I have no context here at all :(

author
#3 lore raw
Quoted 4 lines · Greg KH
Quoted 1 line · Lance Yang

+Cc: Greg

I have no context here at all :(

Hi Greg,

This patch fixes a build error in the 6.1.y tree.

The mm selftests failed to build, likely because some patches were missed during backporting. I believe it's better to fix it directly here.

Thanks,
Leon

maintainer
#4 lore raw
Quoted 6 lines · Leon Hwang
Quoted 3 lines · Greg KH
Quoted 1 line · Lance Yang

+Cc: Greg

Quoted 8 lines
Quoted 1 line

I have no context here at all :(

Hi Greg,

This patch fixes a build error in the 6.1.y tree.

The mm selftests failed to build, likely because some patches were missed during backporting. I believe it's better to fix it directly here.

Why not take the original patches instead? That's almost always the proper thing to do.

thanks,

greg k-h

#5 lore raw
In reply to Leon Hwang
Quoted 12 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

Quoted 8 lines
---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)

What commit id does this fix? And again, why not just take the original commits instead?

thanks,

greg k-h

author
#6 lore raw
Quoted 23 lines · Greg KH
Quoted 12 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

Quoted 8 lines
---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)
Quoted 1 line

What commit id does this fix? And again, why not just take the original

Let me check which commit introduced the fix.

Quoted 1 line

commits instead?

I agree that taking the original commits would be preferable.

However, it might involve quite a few patches to backport, which could be a bit of work.

If the backport turns out to be too complex, I think it’s acceptable to leave the build error as-is for now.

Thanks,
Leon

Quoted 4 lines

thanks,

greg k-h

#7 lore raw
Quoted 28 lines · Leon Hwang
Quoted 23 lines · Greg KH
Quoted 12 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

Quoted 8 lines
---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)
Quoted 1 line

What commit id does this fix? And again, why not just take the original

Quoted 8 lines

Let me check which commit introduced the fix.

Quoted 1 line

commits instead?

I agree that taking the original commits would be preferable.

However, it might involve quite a few patches to backport, which could be a bit of work.

We can easily take lots of patches, don't worry about the quantity. But it would be good to figure out what caused this to break here, and not in other branches.

thanks,

greg k-h

author
#8 lore raw
Quoted 33 lines · Greg KH
Quoted 32 lines · Leon Hwang
Quoted 23 lines · Greg KH
Quoted 12 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

Quoted 8 lines
---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)
Quoted 1 line

What commit id does this fix? And again, why not just take the original

Let me check which commit introduced the fix.

Quoted 1 line

commits instead?

Quoted 9 lines
Quoted 4 lines

I agree that taking the original commits would be preferable.

However, it might involve quite a few patches to backport, which could be a bit of work.

We can easily take lots of patches, don't worry about the quantity. But it would be good to figure out what caused this to break here, and not in other branches.

Hi Greg,

After checking with 'git blame map_hugetlb.c', the issue was introduced by commit a584c7734a4d (“selftests: mm: fix map_hugetlb failure on 64K page size systems”), which corresponds to upstream commit 91b80cc5b39f. This change appears to have caused the build error in the 6.1.y tree.

Comparing several stable trees shows the following:

- 6.0.y: not backported*
- 6.1.y: backported
- 6.2.y: not backported*
- 6.3.y: not backported*
- 6.4.y: not backported*
- 6.5.y: not backported*
- 6.6.y: backported
- 6.7.y: backported

Given this, it might be preferable to revert a584c7734a4d in 6.1.y for consistency with the other stable trees (6.0.y, 6.2–6.5.y).

WDYT?

Thanks,
Leon

#9 lore raw
Quoted 64 lines · Leon Hwang
Quoted 33 lines · Greg KH
Quoted 32 lines · Leon Hwang
Quoted 23 lines · Greg KH
Quoted 12 lines · Leon Hwang

Fix the build error:

map_hugetlb.c: In function 'main':
map_hugetlb.c:79:25: warning: implicit declaration of function 'default_huge_page_size' [-Wimplicit-function-declaration]

   79 |         hugepage_size = default_huge_page_size();
      |                         ^~~~~~~~~~~~~~~~~~~~~~

/usr/bin/ld: /tmp/ccYOogvJ.o: in function 'main':
map_hugetlb.c:(.text+0x114): undefined reference to 'default_huge_page_size'

According to the latest selftests, 'default_huge_page_size' has been moved to 'vm_util.c'. So fix the error by the same way.

Quoted 8 lines
---
 tools/testing/selftests/vm/Makefile      |  1 +
 tools/testing/selftests/vm/userfaultfd.c | 24 ------------------------
 tools/testing/selftests/vm/vm_util.c     | 21 +++++++++++++++++++++
 tools/testing/selftests/vm/vm_util.h     |  1 +
 4 files changed, 23 insertions(+), 24 deletions(-)
Quoted 1 line

What commit id does this fix? And again, why not just take the original

Let me check which commit introduced the fix.

Quoted 1 line

commits instead?

Quoted 9 lines
Quoted 4 lines

I agree that taking the original commits would be preferable.

However, it might involve quite a few patches to backport, which could be a bit of work.

We can easily take lots of patches, don't worry about the quantity. But it would be good to figure out what caused this to break here, and not in other branches.

Hi Greg,

After checking with 'git blame map_hugetlb.c', the issue was introduced by commit a584c7734a4d (“selftests: mm: fix map_hugetlb failure on 64K page size systems”), which corresponds to upstream commit 91b80cc5b39f. This change appears to have caused the build error in the 6.1.y tree.

Comparing several stable trees shows the following:

- 6.0.y: not backported*
- 6.1.y: backported
- 6.2.y: not backported*
- 6.3.y: not backported*
- 6.4.y: not backported*
- 6.5.y: not backported*
- 6.6.y: backported
- 6.7.y: backported

Quoted 2 lines

Given this, it might be preferable to revert a584c7734a4d in 6.1.y for consistency with the other stable trees (6.0.y, 6.2–6.5.y).

Ah, yeah, it looks like this commit was reverted from other stable releases, as it shows up in the following releases:

	4.19.310 4.19.315 5.4.272 5.4.277 5.10.213 5.10.218 5.15.152 5.15.160 6.1.82 6.6.18 6.7.6

So a revert would be fine, want to submit it?

thanks,

greg k-h

author
#10 lore raw
Quoted 4 lines · Greg KH
Quoted 3 lines · Leon Hwang

On 2025/10/22 16:20, Greg KH wrote:

[...]

Quoted 22 lines
Quoted 19 lines

Hi Greg,

After checking with 'git blame map_hugetlb.c', the issue was introduced by commit a584c7734a4d (“selftests: mm: fix map_hugetlb failure on 64K page size systems”), which corresponds to upstream commit 91b80cc5b39f. This change appears to have caused the build error in the 6.1.y tree.

Comparing several stable trees shows the following:

- 6.0.y: not backported*
- 6.1.y: backported
- 6.2.y: not backported*
- 6.3.y: not backported*
- 6.4.y: not backported*
- 6.5.y: not backported*
- 6.6.y: backported
- 6.7.y: backported

Quoted 2 lines

Given this, it might be preferable to revert a584c7734a4d in 6.1.y for consistency with the other stable trees (6.0.y, 6.2–6.5.y).

Quoted 7 lines

Ah, yeah, it looks like this commit was reverted from other stable releases, as it shows up in the following releases:

	4.19.310 4.19.315 5.4.272 5.4.277 5.10.213 5.10.218 5.15.152 5.15.160 6.1.82 6.6.18 6.7.6

So a revert would be fine, want to submit it?

Got it. I'll send a patch to revert it later.

Thanks,
Leon