The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: khugepaged: skip swap tests when swap is unavailable
@ 2026-07-15 13:34 Jaeyeon Lee
  2026-07-15 14:09 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 3+ messages in thread
From: Jaeyeon Lee @ 2026-07-15 13:34 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Shuah Khan
  Cc: linux-mm, linux-kselftest, linux-kernel, Jaeyeon Lee

The collapse_swapin_single_pte and collapse_max_ptes_swap tests use
MADV_PAGEOUT to swap out pages before verifying khugepaged collapse
behavior. On systems without swap configured, MADV_PAGEOUT succeeds
but the pages are not actually swapped out, so check_swap() returns
false and the tests report a failure.

These tests cannot run meaningfully without swap, so a missing swap
area is an environment limitation rather than a test failure. Detect
the absence of swap via /proc/swaps and skip the affected tests
instead of failing them.

Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 10e8dedcb087..f9b4ebe733ce 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -100,6 +100,22 @@ static void skip(const char *msg)
 	exit_status = KSFT_SKIP;
 }
 
+static bool swap_available(void)
+{
+	char buf[256];
+	bool ret;
+	FILE *fp = fopen("/proc/swaps", "r");
+
+	if (!fp)
+		return false;
+
+	fgets(buf, sizeof(buf), fp);
+	ret = !!fgets(buf, sizeof(buf), fp);
+
+	fclose(fp);
+	return ret;
+}
+
 static void save_settings(void)
 {
 	ksft_print_msg("Save THP and khugepaged settings...");
@@ -742,6 +758,9 @@ static void collapse_swapin_single_pte(struct collapse_context *c, struct mem_op
 		ksft_exit_fail_perror("madvise(MADV_PAGEOUT)");
 	if (check_swap(p, page_size)) {
 		success("OK");
+	} else if (!swap_available()) {
+		skip("Swap is not available");
+		goto out;
 	} else {
 		fail("Fail");
 		goto out;
@@ -768,6 +787,9 @@ static void collapse_max_ptes_swap(struct collapse_context *c, struct mem_ops *o
 		ksft_exit_fail_perror("madvise(MADV_PAGEOUT)");
 	if (check_swap(p, (max_ptes_swap + 1) * page_size)) {
 		success("OK");
+	} else if (!swap_available()) {
+		skip("Swap is not available");
+		goto out;
 	} else {
 		fail("Fail");
 		goto out;
@@ -785,6 +807,9 @@ static void collapse_max_ptes_swap(struct collapse_context *c, struct mem_ops *o
 			ksft_exit_fail_perror("madvise(MADV_PAGEOUT)");
 		if (check_swap(p, max_ptes_swap * page_size)) {
 			success("OK");
+		} else if (!swap_available()) {
+			skip("Swap is not available");
+			goto out;
 		} else {
 			fail("Fail");
 			goto out;

base-commit: 7081238c5ca29839924f13bf5daa80763bc589f2
-- 
2.43.0


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

* Re: [PATCH] selftests/mm: khugepaged: skip swap tests when swap is unavailable
  2026-07-15 13:34 [PATCH] selftests/mm: khugepaged: skip swap tests when swap is unavailable Jaeyeon Lee
@ 2026-07-15 14:09 ` David Hildenbrand (Arm)
  2026-07-15 14:47   ` Dev Jain
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-15 14:09 UTC (permalink / raw)
  To: Jaeyeon Lee, Andrew Morton, Shuah Khan
  Cc: linux-mm, linux-kselftest, linux-kernel

On 7/15/26 15:34, Jaeyeon Lee wrote:
> The collapse_swapin_single_pte and collapse_max_ptes_swap tests use
> MADV_PAGEOUT to swap out pages before verifying khugepaged collapse
> behavior. On systems without swap configured, MADV_PAGEOUT succeeds
> but the pages are not actually swapped out, so check_swap() returns
> false and the tests report a failure.
> 
> These tests cannot run meaningfully without swap, so a missing swap
> area is an environment limitation rather than a test failure. Detect
> the absence of swap via /proc/swaps and skip the affected tests
> instead of failing them.
> 
> Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
> ---
>  tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
> index 10e8dedcb087..f9b4ebe733ce 100644
> --- a/tools/testing/selftests/mm/khugepaged.c
> +++ b/tools/testing/selftests/mm/khugepaged.c
> @@ -100,6 +100,22 @@ static void skip(const char *msg)
>  	exit_status = KSFT_SKIP;
>  }
>  
> +static bool swap_available(void)
> +{
> +	char buf[256];
> +	bool ret;
> +	FILE *fp = fopen("/proc/swaps", "r");
> +
> +	if (!fp)
> +		return false;
> +
> +	fgets(buf, sizeof(buf), fp);
> +	ret = !!fgets(buf, sizeof(buf), fp);
> +
> +	fclose(fp);
> +	return ret;
> +}
> +

That doesn't mean that swapout will succeed.

Take a look at cow.c where we use pagemap_is_swapped() after MADV_PAGEOUT.

-- 
Cheers,

David

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

* Re: [PATCH] selftests/mm: khugepaged: skip swap tests when swap is unavailable
  2026-07-15 14:09 ` David Hildenbrand (Arm)
@ 2026-07-15 14:47   ` Dev Jain
  0 siblings, 0 replies; 3+ messages in thread
From: Dev Jain @ 2026-07-15 14:47 UTC (permalink / raw)
  To: David Hildenbrand (Arm), Jaeyeon Lee, Andrew Morton, Shuah Khan
  Cc: linux-mm, linux-kselftest, linux-kernel



On 15/07/26 7:39 pm, David Hildenbrand (Arm) wrote:
> On 7/15/26 15:34, Jaeyeon Lee wrote:
>> The collapse_swapin_single_pte and collapse_max_ptes_swap tests use
>> MADV_PAGEOUT to swap out pages before verifying khugepaged collapse
>> behavior. On systems without swap configured, MADV_PAGEOUT succeeds
>> but the pages are not actually swapped out, so check_swap() returns
>> false and the tests report a failure.
>>
>> These tests cannot run meaningfully without swap, so a missing swap
>> area is an environment limitation rather than a test failure. Detect
>> the absence of swap via /proc/swaps and skip the affected tests
>> instead of failing them.
>>
>> Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
>> ---
>>  tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
>>  1 file changed, 25 insertions(+)
>>
>> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
>> index 10e8dedcb087..f9b4ebe733ce 100644
>> --- a/tools/testing/selftests/mm/khugepaged.c
>> +++ b/tools/testing/selftests/mm/khugepaged.c
>> @@ -100,6 +100,22 @@ static void skip(const char *msg)
>>  	exit_status = KSFT_SKIP;
>>  }
>>  
>> +static bool swap_available(void)
>> +{
>> +	char buf[256];
>> +	bool ret;
>> +	FILE *fp = fopen("/proc/swaps", "r");
>> +
>> +	if (!fp)
>> +		return false;
>> +
>> +	fgets(buf, sizeof(buf), fp);
>> +	ret = !!fgets(buf, sizeof(buf), fp);
>> +
>> +	fclose(fp);
>> +	return ret;
>> +}
>> +
> 
> That doesn't mean that swapout will succeed.
> 
> Take a look at cow.c where we use pagemap_is_swapped() after MADV_PAGEOUT.

That suffers from the reverse problem - in case of a real swap bug, cow.c
will skip the test and anyone running the test won't bother.

I think this patch idea is reasonable, we need a way to say "swap definitely
won't succeed because there is no swap device, so skip" vs "swap failed,
need to dig in!" .

> 


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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 13:34 [PATCH] selftests/mm: khugepaged: skip swap tests when swap is unavailable Jaeyeon Lee
2026-07-15 14:09 ` David Hildenbrand (Arm)
2026-07-15 14:47   ` Dev Jain

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