Skip to contentSkip to conversation

selftests/mm: khugepaged: skip swap tests when swap is unavailable

PATCH In review Jaeyeon Lee 3 participants 5 messages Jul 15 – Jul 16

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/mm: khugepaged: skip swap tests when swap is unavailable

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.

---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/mm/khugepaged.c +25 -0
index 10e8dedcb087..f9b4ebe733ce 100644
@@ -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

Signature · 1 line
2.43.0
#1 lore raw
Quoted 30 lines · 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.

---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/mm/khugepaged.c +6 -0
index 10e8dedcb087..f9b4ebe733ce 100644
@@ -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");
+

tools/testing/selftests/mm/khugepaged.c static void skip(const char *msg) · line 118

Quoted 10 lines
tools/testing/selftests/mm/khugepaged.c +10 -0
+	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.

Signature · 3 lines
Cheers,

David
reviewer
#2 lore raw
Quoted 44 lines · David Hildenbrand (Arm)
Quoted 30 lines · 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.

---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/mm/khugepaged.c +6 -0
index 10e8dedcb087..f9b4ebe733ce 100644
@@ -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");
+

tools/testing/selftests/mm/khugepaged.c static void skip(const char *msg) · line 118

Quoted 10 lines
tools/testing/selftests/mm/khugepaged.c +10 -0
+	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.

Quoted 1 line

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!" .

Quoted 1 line
#3 lore raw
Quoted 47 lines · Dev Jain
Quoted 44 lines · David Hildenbrand (Arm)
Quoted 30 lines · 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.

---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/mm/khugepaged.c +6 -0
index 10e8dedcb087..f9b4ebe733ce 100644
@@ -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");
+

tools/testing/selftests/mm/khugepaged.c static void skip(const char *msg) · line 118

Quoted 10 lines
tools/testing/selftests/mm/khugepaged.c +10 -0
+	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.

Quoted 4 lines
Quoted 1 line

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.

Yes, because there could be other reasons why MADV_PAGEOUT would not be successful (speculative page references, out of swap space).

Quoted 4 lines

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!" .

I would not pack a "let's test if swapping in the system even works" into a khugeapged test.

I think we can reasonably assume here "swap subsystem is not completely broken".

And if we want to check for that, have a separate test that stresses swapping, if available.

Signature · 3 lines
Cheers,

David
#4 lore raw
Quoted 4 lines

I would not pack a "let's test if swapping in the system even works" into a khugeapged test.

I think we can reasonably assume here "swap subsystem is not completely broken".

I understand the point. I won't pursue this further. Thank you for taking the time to review.

Quoted 74 lines · David Hildenbrand (Arm)
Quoted 47 lines · Dev Jain
Quoted 44 lines · David Hildenbrand (Arm)
Quoted 30 lines · 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.

---
 tools/testing/selftests/mm/khugepaged.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/mm/khugepaged.c +6 -0
index 10e8dedcb087..f9b4ebe733ce 100644
@@ -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");
+

tools/testing/selftests/mm/khugepaged.c static void skip(const char *msg) · line 118

Quoted 10 lines
tools/testing/selftests/mm/khugepaged.c +10 -0
+   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.

Quoted 4 lines
Quoted 1 line

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.

Yes, because there could be other reasons why MADV_PAGEOUT would not be successful (speculative page references, out of swap space).

Quoted 4 lines

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!" .

I would not pack a "let's test if swapping in the system even works" into a khugeapged test.

I think we can reasonably assume here "swap subsystem is not completely broken".

And if we want to check for that, have a separate test that stresses swapping, if available.

--
Cheers,

David