Skip to contentSkip to conversation

mem: disable KSM smart scan for ksm tests

PATCH Superseded Stefan Roesch 3 participants 9 messages Nov 27, 2023 – Dec 1, 2023 Memory management

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mem: disable KSM smart scan for ksm tests

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/mem/lib/mem.c +4 -0
index fbfeef026..ef274a3ac 100644
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
 	       {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d', size*MB},
 	};
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");
+
 	ps = sysconf(_SC_PAGE_SIZE);
 	pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
 
 	tst_res(TINFO, "stop KSM.");
 	SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");
 	final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
 	while (waitpid(-1, &status, 0) > 0)

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e

Signature · 1 line
2.39.3
#1 lore raw

Hi Stefan,

Quoted 4 lines

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 11 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/mem/lib/mem.c +0 -0
index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +2 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
 	       {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d', size*MB},
 	};
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan' for writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like this. It's already used in ksm01.c, you need just to add this line:

	{"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

(instead of both SAFE_FILE_PRINTF)

See:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

I wonder if ksm01.c is the only ksm test which needs to disable this.

also nit: there is a wrong indent (spaces instead of tabs), please be consistent with the file content.

NOTE: while this fixes problem on 6.7.0-rc1-2.g86e46c2-default (openSUSE), it does not fixes other problem on 6.5.10 on Debian (16 errors like these below):

mem.c:252: TFAIL: pages_shared is not 2 but 5038. mem.c:252: TFAIL: pages_sharing is not 98302 but 593629. mem.c:252: TFAIL: pages_volatile is not 0 but 391. mem.c:252: TFAIL: pages_unshared is not 0 but 149157.

I have no idea if this is a real bug which needs to be fixed or test false positive to be fixed, or whether the problem has already been fixed in newer kernels.

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 532

Quoted 9 lines
testcases/kernel/mem/lib/mem.c +2 -0
+
 	ps = sysconf(_SC_PAGE_SIZE);
 	pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
 
 	tst_res(TINFO, "stop KSM.");
 	SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");

nit: Again, wrong indent. You could have seen it also in the generated patch.

Kind regards,
Petr

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +0 -0
 	final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
 	while (waitpid(-1, &status, 0) > 0)

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e

#2 lore raw

Hi Stefan, Petr,

Quoted 30 lines · Petr Vorel

Hi Stefan,

Quoted 4 lines

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 2 lines

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Review

Quoted 5 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 454

Quoted 5 lines

index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c +0 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',

size*MB},

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 4 lines
testcases/kernel/mem/lib/mem.c +2 -0
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

Quoted 9 lines

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan' for
writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like this. It's already used in ksm01.c, you need just to add this line:

        {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO' as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file exists. It will
ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not
exist
TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

Quoted 8 lines

(instead of both SAFE_FILE_PRINTF)

See:

https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

I wonder if ksm01.c is the only ksm test which needs to disable this.

I think all of the ksm0*.c tests should disable it by the config. The smart_scan
will impact all the tests with invoke key function create_same_memory().

Quoted 14 lines

also nit: there is a wrong indent (spaces instead of tabs), please be consistent
with the file content.

NOTE: while this fixes problem on 6.7.0-rc1-2.g86e46c2-default (openSUSE), it does not fixes other problem on 6.5.10 on Debian (16 errors like these below):

mem.c:252: TFAIL: pages_shared is not 2 but 5038. mem.c:252: TFAIL: pages_sharing is not 98302 but 593629. mem.c:252: TFAIL: pages_volatile is not 0 but 391. mem.c:252: TFAIL: pages_unshared is not 0 but 149157.

Quoted 5 lines

I have no idea if this is a real bug which needs to be fixed or test false positive to be fixed, or whether the problem has already been fixed in newer
kernels.

It is more like a real bug, the Debain kernel-6.5.10 does not contain this smart_scan feature. Or you may try to build the latest kernel on your platform to see if it can be reproduced as well.

Quoted 7 lines
Quoted 6 lines
testcases/kernel/mem/lib/mem.c +1 -0
+
      ps = sysconf(_SC_PAGE_SIZE);
      pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
Quoted 16 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 532

Quoted 3 lines
testcases/kernel/mem/lib/mem.c +1 -0
      tst_res(TINFO, "stop KSM.");
      SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");

nit: Again, wrong indent. You could have seen it also in the generated patch.

Kind regards,
Petr

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +0 -0
      final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
      while (waitpid(-1, &status, 0) > 0)
 

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e

One more comment not related to this patch:

@Stefan, do you have a test (or plan to) verify the 'smart_scan' feture works?
As we do disables it for all ksm* tests in LTP, so, it would be great to have one
for testing in enable mode. What do you think?

Signature · 2 lines
Regards,
Li Wang
#3 lore raw

Hi Stefan, Li,

Quoted 63 lines

Hi Stefan, Petr,

Quoted 30 lines · Petr Vorel

Hi Stefan,

Quoted 4 lines

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 2 lines

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Review

Quoted 5 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 454

Quoted 5 lines

index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c +0 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',

size*MB},

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 4 lines
testcases/kernel/mem/lib/mem.c +2 -0
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

Quoted 8 lines

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan' for
writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like this. It's already used in ksm01.c, you need just to add this line:

        {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO' as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file exists. It will
ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not
exist
TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

Quoted 3 lines

(instead of both SAFE_FILE_PRINTF)

See:

Quoted 8 lines
Quoted 3 lines

https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

I wonder if ksm01.c is the only ksm test which needs to disable this.

I think all of the ksm0*.c tests should disable it by the config. The smart_scan
will impact all the tests with invoke key function create_same_memory().

ksm05.c and ksm06.c does not use create_same_memory(). Or did I overlook something?

Quoted 19 lines
Quoted 13 lines

also nit: there is a wrong indent (spaces instead of tabs), please be consistent
with the file content.

NOTE: while this fixes problem on 6.7.0-rc1-2.g86e46c2-default (openSUSE), it does not fixes other problem on 6.5.10 on Debian (16 errors like these below):

mem.c:252: TFAIL: pages_shared is not 2 but 5038. mem.c:252: TFAIL: pages_sharing is not 98302 but 593629. mem.c:252: TFAIL: pages_volatile is not 0 but 391. mem.c:252: TFAIL: pages_unshared is not 0 but 149157.

Quoted 4 lines

I have no idea if this is a real bug which needs to be fixed or test false positive to be fixed, or whether the problem has already been fixed in newer
kernels.

Quoted 3 lines

It is more like a real bug, the Debain kernel-6.5.10 does not contain this smart_scan feature. Or you may try to build the latest kernel on your platform to see if it can be reproduced as well.

I'll try to reproduce this on mainline kernel 6.5, 6.6 and 6.7.

Quoted 23 lines
Quoted 6 lines
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +1 -0
+
      ps = sysconf(_SC_PAGE_SIZE);
      pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
Quoted 14 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 532

Quoted 3 lines
testcases/kernel/mem/lib/mem.c +1 -0
      tst_res(TINFO, "stop KSM.");
      SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");

nit: Again, wrong indent. You could have seen it also in the generated patch.

Kind regards,
Petr

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +0 -0
      final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
      while (waitpid(-1, &status, 0) > 0)
 

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e

Quoted 7 lines

One more comment not related to this patch:

@Stefan, do you have a test (or plan to) verify the 'smart_scan' feture works?
As we do disables it for all ksm* tests in LTP, so, it would be great to have one
for testing in enable mode. What do you think?

This makes perfect sense even if I'm not that ksm05.c and ksm06.c also needs to disable smart_scan.

Kind regards,
Petr

#4 lore raw
Quoted 77 lines · Petr Vorel

Hi Stefan, Li,

Quoted 7 lines

Hi Stefan, Petr,

Quoted 3 lines · Petr Vorel

Hi Stefan,

Quoted 1 line

This disables the "smart scan" KSM feature to make sure that the

volatile

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 2 lines

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int

Quoted 4 lines

index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c +0 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int

unit)

Quoted 9 lines
Quoted 9 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int · line 454

Quoted 1 line
testcases/kernel/mem/lib/mem.c +0 -0
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',

size*MB},

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 4 lines
testcases/kernel/mem/lib/mem.c +2 -0
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan'

for

Quoted 5 lines
Quoted 5 lines

writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like

this.

Quoted 7 lines
Quoted 2 lines

It's already used in ksm01.c, you need just to add this line:

        {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO' as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file

exists.

Quoted 17 lines

It will
ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not
exist
TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

Quoted 5 lines

(instead of both SAFE_FILE_PRINTF)

See:

https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

Quoted 1 line
Quoted 1 line

I wonder if ksm01.c is the only ksm test which needs to disable this.

Quoted 7 lines
Quoted 3 lines

I think all of the ksm0*.c tests should disable it by the config. The smart_scan
will impact all the tests with invoke key function create_same_memory().

ksm05.c and ksm06.c does not use create_same_memory(). Or did I overlook something?

Good catch, I looked into these tests, seems only ksm05 is debatable for disabling smart_scan, as a simple regression, it suggests disabling ksm daemon to avoid disturb according to some workload.
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/ksm/ksm05.c#L30

ksm06 is definitely need disable smart_scan, it tests KSM in different 'run' state for merge_accros_nodes.

To be on the safe side, I would suggest applying the patch to all ksm* tests,
and write a new single for smart_scan if needed.

Signature · 2 lines
Regards,
Li Wang
#5 lore raw
Quoted 87 lines · Petr Vorel
Quoted 78 lines

Hi Stefan, Li,

Quoted 7 lines

Hi Stefan, Petr,

Quoted 3 lines · Petr Vorel

Hi Stefan,

Quoted 1 line

This disables the "smart scan" KSM feature to make sure that the

volatile

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 2 lines

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int

Quoted 4 lines

index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c +0 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int

unit)

Quoted 9 lines
Quoted 9 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int · line 454

Quoted 1 line
testcases/kernel/mem/lib/mem.c +0 -0
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',

size*MB},

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 4 lines
testcases/kernel/mem/lib/mem.c +2 -0
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan'

for

Quoted 5 lines
Quoted 5 lines

writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like

this.

Quoted 7 lines
Quoted 2 lines

It's already used in ksm01.c, you need just to add this line:

        {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO' as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file

exists.

Quoted 15 lines

It will
ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not
exist
TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

Quoted 3 lines

(instead of both SAFE_FILE_PRINTF)

See:

https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

Quoted 1 line
Quoted 1 line

I wonder if ksm01.c is the only ksm test which needs to disable this.

Quoted 6 lines
Quoted 3 lines

I think all of the ksm0*.c tests should disable it by the config. The smart_scan
will impact all the tests with invoke key function create_same_memory().

ksm05.c and ksm06.c does not use create_same_memory(). Or did I overlook something?

Quoted 7 lines

Good catch, I looked into these tests, seems only ksm05 is debatable for disabling smart_scan, as a simple regression, it suggests disabling ksm daemon to avoid disturb according to some workload.
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/ksm/ksm05.c#L30

ksm06 is definitely need disable smart_scan, it tests KSM in different 'run' state for merge_accros_nodes.

Thanks for having a look.

Quoted 3 lines

To be on the safe side, I would suggest applying the patch to all ksm* tests,
and write a new single for smart_scan if needed.

Agree. I vote for new single for smart_scan related test.

Kind regards,
Petr

#6 lore raw
Quoted 95 lines · Petr Vorel
Quoted 87 lines · Petr Vorel
Quoted 78 lines

Hi Stefan, Li,

Quoted 7 lines

Hi Stefan, Petr,

Quoted 3 lines · Petr Vorel

Hi Stefan,

Quoted 1 line

This disables the "smart scan" KSM feature to make sure that the

volatile

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 2 lines

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int

Quoted 4 lines

index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c +0 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int

unit)

Quoted 9 lines
Quoted 9 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int · line 454

Quoted 1 line
testcases/kernel/mem/lib/mem.c +0 -0
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',

size*MB},

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 4 lines
testcases/kernel/mem/lib/mem.c +2 -0
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan'

for

Quoted 5 lines
Quoted 5 lines

writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like

this.

Quoted 7 lines
Quoted 2 lines

It's already used in ksm01.c, you need just to add this line:

        {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO' as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file

exists.

Quoted 15 lines

It will
ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not
exist
TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

Quoted 3 lines

(instead of both SAFE_FILE_PRINTF)

See:

https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

Quoted 1 line
Quoted 1 line

I wonder if ksm01.c is the only ksm test which needs to disable this.

Quoted 6 lines
Quoted 3 lines

I think all of the ksm0*.c tests should disable it by the config. The smart_scan
will impact all the tests with invoke key function create_same_memory().

ksm05.c and ksm06.c does not use create_same_memory(). Or did I overlook something?

Quoted 7 lines

Good catch, I looked into these tests, seems only ksm05 is debatable for disabling smart_scan, as a simple regression, it suggests disabling ksm daemon to avoid disturb according to some workload.
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/ksm/ksm05.c#L30

ksm06 is definitely need disable smart_scan, it tests KSM in different 'run' state for merge_accros_nodes.

Quoted 8 lines

Thanks for having a look.

Quoted 3 lines

To be on the safe side, I would suggest applying the patch to all ksm* tests,
and write a new single for smart_scan if needed.

Agree. I vote for new single for smart_scan related test.

I'll add a new test.

Quoted 2 lines

Kind regards,
Petr

#7 lore raw
In reply to Li Wang
Quoted 101 lines · Li Wang

Hi Stefan, Petr,

On Tue, Nov 28, 2023 at 3:46 PM Petr Vorel <[email protected]> wrote:

Hi Stefan,

Quoted 4 lines

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Quoted 11 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/mem/lib/mem.c +0 -0
index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +2 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
             {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d', size*MB},
      };
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan' for writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like this. It's already used in ksm01.c, you need just to add this line:

         {"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I guess we need to set 'TST_SR_SKIP_MISSING | TST_SR_TBROK_RO'
as the last field. Because TST_SR_SKIP will continue the test without writing '0' to the smart_scan file, that's not correct if the file exists. It will ignore a kernel bug (smart_scan can't be written) by that config.

Per the Doc Petr pointed below:
TST_SR_SKIP_MISSING – Continue without saving the file if it does not exist TST_SR_TBROK_RO – End test with TBROK if the file is read-only TST_SR_SKIP_RO – Continue without saving the file if it is read-only TST_SR_SKIP – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'

(instead of both SAFE_FILE_PRINTF)

See:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

I wonder if ksm01.c is the only ksm test which needs to disable this.

I think all of the ksm0*.c tests should disable it by the config. The smart_scan will impact all the tests with invoke key function create_same_memory().

also nit: there is a wrong indent (spaces instead of tabs), please be consistent with the file content.

NOTE: while this fixes problem on 6.7.0-rc1-2.g86e46c2-default (openSUSE), it does not fixes other problem on 6.5.10 on Debian (16 errors like these below):

mem.c:252: TFAIL: pages_shared is not 2 but 5038. mem.c:252: TFAIL: pages_sharing is not 98302 but 593629. mem.c:252: TFAIL: pages_volatile is not 0 but 391. mem.c:252: TFAIL: pages_unshared is not 0 but 149157.

I have no idea if this is a real bug which needs to be fixed or test false positive to be fixed, or whether the problem has already been fixed in newer kernels.

It is more like a real bug, the Debain kernel-6.5.10 does not contain this smart_scan feature. Or you may try to build the latest kernel on your platform to see if it can be reproduced as well.

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 532

Quoted 9 lines
testcases/kernel/mem/lib/mem.c +2 -0
+
      ps = sysconf(_SC_PAGE_SIZE);
      pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
 
      tst_res(TINFO, "stop KSM.");
      SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");

nit: Again, wrong indent. You could have seen it also in the generated patch.

Kind regards,
Petr

Quoted 3 lines
testcases/kernel/mem/lib/mem.c +0 -0
      final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
      while (waitpid(-1, &status, 0) > 0)
Quoted 8 lines
Quoted 1 line

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e

One more comment not related to this patch:

@Stefan, do you have a test (or plan to) verify the 'smart_scan' feture works? As we do disables it for all ksm* tests in LTP, so, it would be great to have one for testing in enable mode. What do you think?

In the next version of the patch I'll add a new test case specifically to test smart scan.

#8 lore raw
In reply to Petr Vorel
Quoted 9 lines · Petr Vorel

Hi Stefan,

Quoted 4 lines

This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0.

Signed-off-by Stefan Roesch <devkernel.io>

nit: you forgot 'shr@'

Thanks, will be fixed with the next version.

Quoted 18 lines
Quoted 11 lines
---
 testcases/kernel/mem/lib/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/mem/lib/mem.c +0 -0
index fbfeef026..ef274a3ac 100644

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 458

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +2 -0
@@ -454,6 +454,9 @@ void create_same_memory(int size, int num, int unit)
 	       {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d', size*MB},
 	};
 
+  /* Disable smart scan for correct volatile counts. */
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "0");

NOTE, this fails on the systems without /sys/kernel/mm/ksm/smart_scan:

Quoted 8 lines

mem.c:458: TBROK: Failed to open FILE '/sys/kernel/mm/ksm/smart_scan' for writing: EACCES (13)

NOTE, we normally handle the setup like this in test setup function.

But new API has .save_restore which is more robust for tasks like this. It's already used in ksm01.c, you need just to add this line:

	{"/sys/kernel/mm/ksm/smart_scan", "0", TST_SR_SKIP},

I'll add it with the next version

Quoted 7 lines

(instead of both SAFE_FILE_PRINTF)

See:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#127-saving--restoring-procsys-values

I wonder if ksm01.c is the only ksm test which needs to disable this.

Other tests will also need it. They also use the create_same_memory() function.

Quoted 6 lines

also nit: there is a wrong indent (spaces instead of tabs), please be consistent with the file content.

NOTE: while this fixes problem on 6.7.0-rc1-2.g86e46c2-default (openSUSE), it does not fixes other problem on 6.5.10 on Debian (16 errors like these below):

Quoted 9 lines

mem.c:252: TFAIL: pages_shared is not 2 but 5038. mem.c:252: TFAIL: pages_sharing is not 98302 but 593629. mem.c:252: TFAIL: pages_volatile is not 0 but 391. mem.c:252: TFAIL: pages_unshared is not 0 but 149157.

I have no idea if this is a real bug which needs to be fixed or test false positive to be fixed, or whether the problem has already been fixed in newer kernels.

This is a different problem. "Smart scan was introduced with 6.7"

Quoted 19 lines

testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 532

Quoted 9 lines
testcases/kernel/mem/lib/mem.c +2 -0
+
 	ps = sysconf(_SC_PAGE_SIZE);
 	pages = MB / ps;
 
@@ -526,6 +529,7 @@ void create_same_memory(int size, int num, int unit)
 
 	tst_res(TINFO, "stop KSM.");
 	SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+  SAFE_FILE_PRINTF(PATH_KSM "smart_scan", "1");

nit: Again, wrong indent. You could have seen it also in the generated patch.

Kind regards,
Petr

Quoted 5 lines
testcases/kernel/mem/lib/mem.c +0 -0
 	final_group_check(0, 0, 0, 0, 0, 0, size * pages * num);
 
 	while (waitpid(-1, &status, 0) > 0)

base-commit: 8c89ef3d451087ed6e18750bd5eedd10e5ab3d2e