[PATCH 2/3] mm: add KUnit coverage for mappingless swapcache folios
From: Shivam Kalra via B4 Relay
Date: Wed Aug 05 2026 - 07:28:41 EST
From: Shivam Kalra <shivamkalra98@xxxxxxxxxxx>
Add focused coverage for the folio_check_splittable() eligibility checks.
Verify that an ordinary mappingless folio is rejected, a mappingless
swapcache folio is accepted, and unsupported target orders and split types
remain rejected.
Build the test only when KUnit is built in because
folio_check_splittable() is intentionally not exported.
Signed-off-by: Shivam Kalra <shivamkalra98@xxxxxxxxxxx>
---
mm/Kconfig | 14 ++++++++++++
mm/Makefile | 1 +
mm/tests/folio_split_kunit.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+)
diff --git a/mm/Kconfig b/mm/Kconfig
index 331daf7fcfab..164dc1438900 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1503,6 +1503,20 @@ config LAZY_MMU_MODE_KUNIT_TEST
If unsure, say N.
+config FOLIO_SPLIT_KUNIT_TEST
+ bool "KUnit tests for folio splitting" if !KUNIT_ALL_TESTS
+ depends on KUNIT=y
+ depends on TRANSPARENT_HUGEPAGE
+ depends on SWAP
+ default KUNIT_ALL_TESTS
+ help
+ Enable this option to test folio split eligibility checks. The tests
+ verify support for mappingless folios in the swap cache and ensure
+ that unsupported target orders and split types are still rejected.
+ The tests are built into the kernel and run during KUnit execution.
+
+ If unsure, say N.
+
source "mm/damon/Kconfig"
endmenu
diff --git a/mm/Makefile b/mm/Makefile
index ab37ef428d98..f09057b40e1a 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -146,4 +146,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
obj-$(CONFIG_EXECMEM) += execmem.o
obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o
obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o
+obj-$(CONFIG_FOLIO_SPLIT_KUNIT_TEST) += tests/folio_split_kunit.o
obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
diff --git a/mm/tests/folio_split_kunit.c b/mm/tests/folio_split_kunit.c
new file mode 100644
index 000000000000..f91c1a320bbf
--- /dev/null
+++ b/mm/tests/folio_split_kunit.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <kunit/test.h>
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/huge_mm.h>
+#include <linux/module.h>
+#include <linux/pagemap.h>
+
+static void folio_check_splittable_mappingless_swapcache(struct kunit *test)
+{
+ struct folio *folio;
+ int ret;
+
+ folio = folio_alloc(GFP_KERNEL, 2);
+ KUNIT_ASSERT_NOT_NULL(test, folio);
+ folio_lock(folio);
+
+ KUNIT_EXPECT_PTR_EQ(test, folio->mapping, NULL);
+ ret = folio_check_splittable(folio, 0, SPLIT_TYPE_UNIFORM);
+ KUNIT_EXPECT_EQ(test, ret, -EBUSY);
+
+ /* Only the eligibility check is exercised here. */
+ folio_set_swapbacked(folio);
+ folio_set_swapcache(folio);
+
+ ret = folio_check_splittable(folio, 0, SPLIT_TYPE_UNIFORM);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ ret = folio_check_splittable(folio, 1, SPLIT_TYPE_UNIFORM);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+ ret = folio_check_splittable(folio, 0, SPLIT_TYPE_NON_UNIFORM);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+ folio_clear_swapcache(folio);
+ folio_clear_swapbacked(folio);
+ folio_unlock(folio);
+ folio_put(folio);
+}
+
+static struct kunit_case folio_split_test_cases[] = {
+ KUNIT_CASE(folio_check_splittable_mappingless_swapcache),
+ {}
+};
+
+static struct kunit_suite folio_split_test_suite = {
+ .name = "folio_split",
+ .test_cases = folio_split_test_cases,
+};
+
+kunit_test_suite(folio_split_test_suite);
+
+MODULE_DESCRIPTION("Tests for folio splitting");
+MODULE_LICENSE("GPL");
--
2.43.0