Skip to contentSkip to conversation

selftests/proc: use RSS in /proc/pid/smaps_rollup tearing tests

PATCH Superseded Suren Baghdasaryan 3 participants 6 messages Oct 28 – Nov 1

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/proc: use RSS in /proc/pid/smaps_rollup tearing tests

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")
---
 tools/testing/selftests/proc/proc-maps-race.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/proc/proc-maps-race.c +4 -7
index bf4c5073f6fc..b6d88afb252b 100644
@@ -528,13 +528,10 @@ static bool compare_smaps_rollup(FIXTURE_DATA(proc_maps_race) *self,
 		struct smaps_rollup_stats *actual)
 {
 	/*
-	 * Clean/dirty metrics might change but Pss-related ones
-	 * should stay constant.
+	 * Clean/dirty metrics might change. Pss depends on map count and might
+	 * change as well. Rss should stay constant.
 	 */
-	if (cmp_smaps_rollup_stat(expected, actual, Pss) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_Anon) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_File) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_Shmem))
+	if (cmp_smaps_rollup_stat(expected, actual, Rss))
 		return true;
 
 	print_smaps_rollup_stats("Expected stats:", self, expected);
@@ -759,7 +756,7 @@ FIXTURE_SETUP(proc_maps_race)
 
 		for (i = 0; i < mod_info->vma_count; i++) {
 			mod_info->child_mapped_addr[i] = mmap(NULL, self->page_size * 3, prot,
-					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+					MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
 			ASSERT_NE(mod_info->child_mapped_addr[i], MAP_FAILED);
 			/* change protection in adjacent maps to prevent merging */
 			prot ^= PROT_WRITE;

base-commit: 39274b454e9993cea319f4ac342a8082a9ee1730

Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Suren Baghdasaryan

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")

Seems sensible, I gather in general PSS is a less than ideal measure in these stats anyway :)

Quoted 35 lines
---
 tools/testing/selftests/proc/proc-maps-race.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/proc/proc-maps-race.c +4 -7
index bf4c5073f6fc..b6d88afb252b 100644
@@ -528,13 +528,10 @@ static bool compare_smaps_rollup(FIXTURE_DATA(proc_maps_race) *self,
 		struct smaps_rollup_stats *actual)
 {
 	/*
-	 * Clean/dirty metrics might change but Pss-related ones
-	 * should stay constant.
+	 * Clean/dirty metrics might change. Pss depends on map count and might
+	 * change as well. Rss should stay constant.
 	 */
-	if (cmp_smaps_rollup_stat(expected, actual, Pss) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_Anon) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_File) &&
-	    cmp_smaps_rollup_stat(expected, actual, Pss_Shmem))
+	if (cmp_smaps_rollup_stat(expected, actual, Rss))
 		return true;
 
 	print_smaps_rollup_stats("Expected stats:", self, expected);
@@ -759,7 +756,7 @@ FIXTURE_SETUP(proc_maps_race)
 
 		for (i = 0; i < mod_info->vma_count; i++) {
 			mod_info->child_mapped_addr[i] = mmap(NULL, self->page_size * 3, prot,
-					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+					MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
 			ASSERT_NE(mod_info->child_mapped_addr[i], MAP_FAILED);
 			/* change protection in adjacent maps to prevent merging */
 			prot ^= PROT_WRITE;
Quoted 4 lines

base-commit: 39274b454e9993cea319f4ac342a8082a9ee1730 --
2.56.0.307.g5fe7bd680c-goog

--
Cheers, Lorenzo

Reviewed-by on v1 1/1
#2 lore raw
In reply to Suren Baghdasaryan
Quoted 9 lines · Suren Baghdasaryan

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")
Signature · 1 line
Pedro
#3 lore raw
Quoted 6 lines · Pedro Falcato
Quoted 5 lines · Suren Baghdasaryan

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Quoted 6 lines
Quoted 4 lines
Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")

Actually, now I'm wondering: isn't Rss also flaky if memory pressure occurs?

Signature · 1 line
Pedro
#4 lore raw
Quoted 8 lines · Pedro Falcato
Quoted 6 lines · Pedro Falcato
Quoted 5 lines · Suren Baghdasaryan

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")

Actually, now I'm wondering: isn't Rss also flaky if memory pressure occurs?

True. Sashiko's findings are also interesting, so I'll need to figure out more robust ways to test smaps_rollup. I will post an update once I figure it out.
Andrew, if this test failure is causing issues in the meantime, please feel free to remove the ca5480fb53fa patch until I get a better version out.
Thanks!

Quoted 3 lines

--
Pedro

#5 lore raw
Quoted 15 lines · Suren Baghdasaryan
Quoted 13 lines · Pedro Falcato
Quoted 11 lines · Pedro Falcato
Quoted 9 lines · Suren Baghdasaryan

Pss metrics can be affected by map count even if VMA tree stays unchanged, therefore test checking VMA tree integrity can't use them. Use Rss instead and pre-populate the VMAs so that Rss changes if a VMA gets skipped or double-counted.

Fixes ca5480fb53fa ("selftests/proc: add /proc/pid/smaps_rollup tearing tests")
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Actually, now I'm wondering: isn't Rss also flaky if memory pressure occurs?

True. Sashiko's findings are also interesting, so I'll need to figure out more robust ways to test smaps_rollup. I will post an update once I figure it out.

I posted an updated version at
https://lore.kernel.org/all/[email protected]/
It should work under memory pressure and also address Sahiko's concerns.

Quoted 8 lines

Andrew, if this test failure is causing issues in the meantime, please feel free to remove the ca5480fb53fa patch until I get a better version out.
Thanks!

Quoted 3 lines

--
Pedro