Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: make libnuma-dependent tests optional
@ 2026-07-30 14:27 Jiangshan Yi
  2026-07-30 14:43 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 3+ messages in thread
From: Jiangshan Yi @ 2026-07-30 14:27 UTC (permalink / raw)
  To: akpm, david, shuah
  Cc: ljs, liam, vbabka, rppt, surenb, mhocko, linux-mm,
	linux-kselftest, linux-kernel, 13667453960, Jiangshan Yi

The mm selftests Makefile unconditionally builds three test binaries
that depend on libnuma (migration, ksm_tests, rmap). When libnuma-dev
is not installed, the build fails with a hard error, inconsistent with
how the optional liburing dependency is already handled via
check_config.sh.

These three tests hard-depend on libnuma at both compile time
(#include <numa.h>) and link time (-lnuma), confirmed by grepping all
.c files under tools/testing/selftests/mm/ for numa.h/numaif.h, which
matches exactly ksm_tests.c, migration.c, and rmap.c.

Extend check_config.sh to probe for libnuma via a compile-plus-link
check (the link check needs a main() symbol), gate the three tests in
TEST_GEN_FILES behind NUMA_EXTRA_LIBS, and print a warning when
libnuma is missing. The liburing section is switched from ">" to ">>"
writes and both output files are truncated once at the top, so the new
libnuma section can append without overwriting the liburing section.

Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
 tools/testing/selftests/mm/Makefile        | 21 +++++++++--
 tools/testing/selftests/mm/check_config.sh | 44 +++++++++++++++++++---
 2 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index e6df968f0971..235c8ec788a7 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -75,7 +75,9 @@ ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64 loongarch32 loongarch64)
 TEST_GEN_FILES += memfd_secret
 endif
 TEST_GEN_FILES += memory-failure
+ifneq ($(NUMA_EXTRA_LIBS),)
 TEST_GEN_FILES += migration
+endif
 TEST_GEN_FILES += mkdirty
 TEST_GEN_FILES += mlock-random-test
 TEST_GEN_FILES += mlock2-tests
@@ -94,7 +96,9 @@ TEST_GEN_FILES += uffd-stress
 TEST_GEN_FILES += uffd-unit-tests
 TEST_GEN_FILES += uffd-wp-mremap
 TEST_GEN_FILES += split_huge_page_test
+ifneq ($(NUMA_EXTRA_LIBS),)
 TEST_GEN_FILES += ksm_tests
+endif
 TEST_GEN_FILES += ksm_functional_tests
 TEST_GEN_FILES += mdwe_test
 TEST_GEN_FILES += hugetlb_fault_after_madv
@@ -103,7 +107,9 @@ TEST_GEN_FILES += hugetlb_dio
 TEST_GEN_FILES += droppable
 TEST_GEN_FILES += guard-regions
 TEST_GEN_FILES += merge
+ifneq ($(NUMA_EXTRA_LIBS),)
 TEST_GEN_FILES += rmap
+endif
 TEST_GEN_FILES += folio_split_race_test
 
 ifneq ($(ARCH),arm64)
@@ -256,11 +262,11 @@ $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
 
 $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
 
-$(OUTPUT)/ksm_tests: LDLIBS += -lnuma
+$(OUTPUT)/ksm_tests: LDLIBS += $(NUMA_EXTRA_LIBS)
 
-$(OUTPUT)/migration: LDLIBS += -lnuma
+$(OUTPUT)/migration: LDLIBS += $(NUMA_EXTRA_LIBS)
 
-$(OUTPUT)/rmap: LDLIBS += -lnuma
+$(OUTPUT)/rmap: LDLIBS += $(NUMA_EXTRA_LIBS)
 
 local_config.mk local_config.h: check_config.sh
 	$(call msg,CHK,config,$@)
@@ -277,6 +283,15 @@ warn_missing_liburing:
 	echo
 endif
 
+ifeq ($(NUMA_EXTRA_LIBS),)
+all: warn_missing_libnuma
+
+warn_missing_libnuma:
+	@echo ; \
+	echo "Warning: missing libnuma support. Some tests (migration, ksm_tests, rmap) will be skipped." ; \
+	echo
+endif
+
 ifneq ($(PAGE_FRAG_WARNING),)
 all: warn_missing_page_frag
 
diff --git a/tools/testing/selftests/mm/check_config.sh b/tools/testing/selftests/mm/check_config.sh
index 32beaefe279e..8e6d1616561b 100755
--- a/tools/testing/selftests/mm/check_config.sh
+++ b/tools/testing/selftests/mm/check_config.sh
@@ -7,10 +7,17 @@
 OUTPUT_H_FILE=local_config.h
 OUTPUT_MKFILE=local_config.mk
 
+# Truncate output files so that re-running this script does not
+# accumulate duplicate content (all writes below use append ">>").
+: > $OUTPUT_H_FILE
+: > $OUTPUT_MKFILE
+
 tmpname=$(mktemp)
 tmpfile_c=${tmpname}.c
 tmpfile_o=${tmpname}.o
 
+trap 'rm -f ${tmpname} ${tmpname}.*' EXIT
+
 # liburing
 echo "#include <sys/types.h>"        > $tmpfile_c
 echo "#include <liburing.h>"        >> $tmpfile_c
@@ -19,12 +26,39 @@ echo "int func(void) { return 0; }" >> $tmpfile_c
 $CC $CFLAGS -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1
 
 if [ -f $tmpfile_o ]; then
-    echo "#define LOCAL_CONFIG_HAVE_LIBURING 1"  > $OUTPUT_H_FILE
-    echo "IOURING_EXTRA_LIBS = -luring"          > $OUTPUT_MKFILE
+    echo "#define LOCAL_CONFIG_HAVE_LIBURING 1"  >> $OUTPUT_H_FILE
+    echo "IOURING_EXTRA_LIBS = -luring"          >> $OUTPUT_MKFILE
 else
-    echo "// No liburing support found"          > $OUTPUT_H_FILE
-    echo "# No liburing support found, so:"      > $OUTPUT_MKFILE
+    echo "// No liburing support found"          >> $OUTPUT_H_FILE
+    echo "# No liburing support found, so:"      >> $OUTPUT_MKFILE
     echo "IOURING_EXTRA_LIBS = "                >> $OUTPUT_MKFILE
 fi
 
-rm ${tmpname}.*
+rm -f $tmpfile_o
+
+# libnuma
+echo "#include <numa.h>"            > $tmpfile_c
+echo "#include <numaif.h>"         >> $tmpfile_c
+echo "int func(void) { return 0; }" >> $tmpfile_c
+echo "int main(void) { return 0; }" >> $tmpfile_c
+
+$CC $CFLAGS -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1
+
+if [ -f $tmpfile_o ]; then
+    tmplink=${tmpname}.bin
+    # Also check linking, not just compilation, because <numa.h> may be
+    # available without the shared library (libnuma-dev vs libnuma)
+    if $CC $CFLAGS $tmpfile_c -o $tmplink -lnuma >/dev/null 2>&1; then
+        echo "#define LOCAL_CONFIG_HAVE_LIBNUMA 1"  >> $OUTPUT_H_FILE
+        echo "NUMA_EXTRA_LIBS = -lnuma"             >> $OUTPUT_MKFILE
+    else
+        echo "// No libnuma support found"          >> $OUTPUT_H_FILE
+        echo "# No libnuma support found, so:"      >> $OUTPUT_MKFILE
+        echo "NUMA_EXTRA_LIBS = "                   >> $OUTPUT_MKFILE
+    fi
+else
+    echo "// No libnuma support found"              >> $OUTPUT_H_FILE
+    echo "# No libnuma support found, so:"          >> $OUTPUT_MKFILE
+    echo "NUMA_EXTRA_LIBS = "                       >> $OUTPUT_MKFILE
+fi
+
-- 
2.25.1



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

* Re: [PATCH] selftests/mm: make libnuma-dependent tests optional
  2026-07-30 14:27 [PATCH] selftests/mm: make libnuma-dependent tests optional Jiangshan Yi
@ 2026-07-30 14:43 ` David Hildenbrand (Arm)
  2026-07-30 15:33   ` Jiangshan Yi
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-30 14:43 UTC (permalink / raw)
  To: Jiangshan Yi, akpm, shuah
  Cc: ljs, liam, vbabka, rppt, surenb, mhocko, linux-mm,
	linux-kselftest, linux-kernel, 13667453960

On 7/30/26 16:27, Jiangshan Yi wrote:
> The mm selftests Makefile unconditionally builds three test binaries
> that depend on libnuma (migration, ksm_tests, rmap). When libnuma-dev
> is not installed, the build fails with a hard error, inconsistent with
> how the optional liburing dependency is already handled via
> check_config.sh.
> 
> These three tests hard-depend on libnuma at both compile time
> (#include <numa.h>) and link time (-lnuma), confirmed by grepping all
> .c files under tools/testing/selftests/mm/ for numa.h/numaif.h, which
> matches exactly ksm_tests.c, migration.c, and rmap.c.

Hi!

IIRC, liburing was not universally easily available when we added these changes.
libnuma is fairly old. (I might have added that :) )

So why should we bother about setups that don't just want to install libnuma +
headers? The real motivation is lacking.

-- 
Cheers,

David


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

* Re: Re: [PATCH] selftests/mm: make libnuma-dependent tests optional
  2026-07-30 14:43 ` David Hildenbrand (Arm)
@ 2026-07-30 15:33   ` Jiangshan Yi
  0 siblings, 0 replies; 3+ messages in thread
From: Jiangshan Yi @ 2026-07-30 15:33 UTC (permalink / raw)
  To: david
  Cc: 13667453960, akpm, liam, linux-kernel, linux-kselftest, linux-mm,
	ljs, mhocko, rppt, shuah, surenb, vbabka, yijiangshan

Hi David,

Thanks for the review and the historical context — very helpful.

You're right that the situations aren't parallel: liburing was made optional
because it wasn't universally easy to obtain at the time, whereas libnuma is
well established and trivial to install on most setups. My cover letter leaned
too heavily on that analogy without articulating the actual motivation — my
mistake.

The scenario I'm trying to address is the *minimal container / cross-build*
one: some CI images and embedded build environments deliberately omit
libnuma-dev to keep the footprint small, or because the target has no NUMA
topology. There, `migration`, `ksm_tests`, and `rmap` fail at **compile** time
(`#include <numa.h>` not found), and `make` exits non-zero — so the CI step is
judged failed even though the dozens of NUMA-independent tests would build
fine. The goal isn't to spare users the install, but to stop a missing optional
library from failing the whole `make`.

That said, your comment makes me reconsider whether silent skipping is the
right policy for selftests. I'd be happy to switch to: keep the tests
enabled-by-default, but on missing libnuma print a clear notice ("install
libnuma-dev to enable NUMA-dependent tests") and continue building the rest,
rather than aborting. This stays closer to the "run as much as possible"
philosophy while still guiding the user to the missing dependency.

If neither direction is of interest, I'll drop the patch — no point adding
maintenance surface for a problem that isn't real in practice. But if the
minimal-container scenario resonates, I'll respin a v2 with proper motivation
in the commit message.

Thanks again for the patience.

Best regards,
Jiangshan Yi


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

end of thread, other threads:[~2026-07-30 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-30 14:27 [PATCH] selftests/mm: make libnuma-dependent tests optional Jiangshan Yi
2026-07-30 14:43 ` David Hildenbrand (Arm)
2026-07-30 15:33   ` Jiangshan Yi

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