Skip to contentSkip to conversation

mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

PATCH New Li Wang 2 participants 5 messages Jun 21, 2016

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

We occasionally catch errors like:

oom03       0  TINFO  :  start OOM testing for KSM pages.
oom03       0  TINFO  :  expected victim is 3490.
oom03       6  TFAIL  :  mem.c:163: victim unexpectedly ended with retcode: 0, expected: 12
oom03       0  TINFO  :  set overcommit_memory to 0

It cames from the caller testoom(0, 1, ENOMEM, 1). The issue was occurred because child_alloc() go into single(lite == 1) thread mode but successfully finish the memory allocation and return 0. A probably reason is that KSM scan merged same pages and disturbed the OOM test in cgroup.

In this patch, keep KSM scan off to prevent OOM test in cgroup distrubing.

---
 testcases/kernel/mem/lib/mem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/mem/lib/mem.c +3 -1
index 3d853a3..b43b7f8 100644
@@ -230,7 +230,9 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
 	} else {
 		tst_resm(TINFO, "start OOM testing for KSM pages.");
 		SAFE_FILE_SCANF(cleanup, PATH_KSM "run", "%d", &ksm_run_orig);
-		SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
+		/* Let KSM off if lite == 1, since limit_in_bytes may vary from
+		 * run to run, which isn't reliable for oom03 cgroup test.*/
+		if (!lite) SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
 		oom(KSM, lite, retcode, allow_sigkill);
 		SAFE_FILE_PRINTF(cleanup,PATH_KSM "run", "%d", ksm_run_orig);
 	}
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

----- Original Message -----

Quoted 5 lines

From: "Li Wang" <[email protected]>
To: [email protected]
Cc: [email protected]
Sent: Tuesday, 21 June, 2016 5:39:52 AM
Subject: [PATCH] mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

The single thread is not important here, it's how much that allocation contributes to limit_in_bytes. oom01 on 2 CPU system will do all allocations in single thread and KSM won't be turned off.

Quoted 35 lines

We occasionally catch errors like:

oom03       0  TINFO  :  start OOM testing for KSM pages.
oom03       0  TINFO  :  expected victim is 3490.
oom03       6  TFAIL  :  mem.c:163: victim unexpectedly ended with retcode:

0, expected: 12
oom03 0 TINFO : set overcommit_memory to 0

It cames from the caller testoom(0, 1, ENOMEM, 1). The issue was occurred because child_alloc() go into single(lite == 1) thread mode but successfully finish the memory allocation and return 0. A probably reason is that KSM scan merged same pages and disturbed the OOM test in cgroup.

In this patch, keep KSM scan off to prevent OOM test in cgroup distrubing.

---
 testcases/kernel/mem/lib/mem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/mem/lib/mem.c +3 -1
index 3d853a3..b43b7f8 100644
@@ -230,7 +230,9 @@ void testoom(int mempolicy, int lite, int retcode, int
 allow_sigkill)
 	} else {
 		tst_resm(TINFO, "start OOM testing for KSM pages.");
 		SAFE_FILE_SCANF(cleanup, PATH_KSM "run", "%d", &ksm_run_orig);
-		SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
+		/* Let KSM off if lite == 1, since limit_in_bytes may vary from
+		 * run to run, which isn't reliable for oom03 cgroup test.*/
+		if (!lite) SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
 		oom(KSM, lite, retcode, allow_sigkill);
 		SAFE_FILE_PRINTF(cleanup,PATH_KSM "run", "%d", ksm_run_orig);
Quoted 1 line

}

What if KSM was enabled before test started?

I'd skip this entire else block if lite == 1. With KSM off, it's nearly identical to oom(NORMAL).

Regards,
Jan

author
#2 lore raw

PATCH 1/1 mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

Quoted 4 lines · Jan Stancek

The single thread is not important here, it's how much that allocation contributes to limit_in_bytes. oom01 on 2 CPU system will do all allocations in single thread and KSM won't be turned off.

Ah, I forgot that situation. yes, it's not about the single thread, it depends on the parameter 'lite' equal 1 or 0. I'd like to rewrite these description.

Quoted 10 lines

testcases/kernel/mem/lib/mem.c void testoom(int mempolicy, int lite, int retcode, int allow_sigkill) · line 238

Quoted 8 lines
testcases/kernel/mem/lib/mem.c +3 -1
 		SAFE_FILE_SCANF(cleanup, PATH_KSM "run", "%d", &ksm_run_orig);
-		SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
+		/* Let KSM off if lite == 1, since limit_in_bytes may vary from
+		 * run to run, which isn't reliable for oom03 cgroup test.*/
+		if (!lite) SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
 		oom(KSM, lite, retcode, allow_sigkill);
 		SAFE_FILE_PRINTF(cleanup,PATH_KSM "run", "%d", ksm_run_orig);
 	}

What if KSM was enabled before test started?

From what I know about KSM, if a memory area affected by function madvise(..., MADV_MERGEABLE), the samepages located in that merory will be easily merged by ksmd as long as we turn it on (echo 1 >/sys/kernel/mm/ksm/run).

And the ".../ksm/run" default value is 0, it means if we just affect the memory area by madvise() function but with ksmd off, there won't have any samepages be merged.

So, I add a conditional jugement as 'if (!lite)' before starting the ksmd. There will be only enable the ksmd while lite == 0, the memory allocated function go into infinite loop with so many parallel threads. And ksmd doing samepages merge work but cann't stop OOM occur at the moment.

Am I right in thinking above?

Quoted 3 lines

I'd skip this entire else block if lite == 1. With KSM off, it's nearly identical to oom(NORMAL).

Hmm, actually there still have a little bit difference from oom(NORMALNORMAL).

In alloc_mem() function, if testcase == KSM, the memory area will do madvise operation like:
madvise(s, length, MADV_MERGEABLE)

That's the reason why I did not skip KSM but just keep it off.

Regards,
Li WANG

#3 lore raw

PATCH 1/1 mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

----- Original Message -----

Quoted 7 lines

From: "Li Wang" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 21 June, 2016 9:56:13 AM
Subject: Re: [PATCH] mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

Quoted 1 line

What if KSM was enabled before test started?

Quoted 8 lines

From what I know about KSM, if a memory area affected by function madvise(..., MADV_MERGEABLE), the samepages located in that merory will be easily merged by ksmd as long as we turn it on (echo 1

Quoted 1 line

/sys/kernel/mm/ksm/run).

And the ".../ksm/run" default value is 0, it means if we just affect the memory area by madvise() function but with ksmd off, there won't have any samepages be merged.

True, but there's no guarantee that every distro and every user will keep the default set to 0. As I recall IBM's PowerKVM has KSM enabled by default.

Quoted 9 lines
Quoted 2 lines

I'd skip this entire else block if lite == 1. With KSM off, it's nearly identical to oom(NORMAL).

Hmm, actually there still have a little bit difference from oom(NORMALNORMAL).

In alloc_mem() function, if testcase == KSM, the memory area will do madvise operation like:
madvise(s, length, MADV_MERGEABLE)

That's what I meant by "nearly identical". Looking at kernel, only ksm seems to care about that flag, and we turn KSM off:

$ grep -l MADV_MERGEABLE -r mm/
mm/Kconfig
mm/madvise.c
mm/ksm.c

Regards,
Jan

author
#4 lore raw

PATCH 1/1 mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

Quoted 13 lines · Jan Stancek

----- Original Message -----

Quoted 12 lines

From: "Li Wang" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 21 June, 2016 9:56:13 AM
Subject: Re: [PATCH] mem/lib: Keep KSM off when child_alloc() allocate memory in single thread

Quoted 1 line

What if KSM was enabled before test started?

From what I know about KSM, if a memory area affected by function madvise(..., MADV_MERGEABLE), the samepages located in that merory will be easily merged by ksmd as long as we turn it on (echo 1

Quoted 1 line

/sys/kernel/mm/ksm/run).

Quoted 7 lines
Quoted 3 lines

And the ".../ksm/run" default value is 0, it means if we just affect the memory area by madvise() function but with ksmd off, there won't have any samepages be merged.

True, but there's no guarantee that every distro and every user will keep the default set to 0. As I recall IBM's PowerKVM has KSM enabled by default.

Okay, that sounds more reasonable.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I'd skip this entire else block if lite == 1. With KSM off, it's nearly identical to oom(NORMAL).

Hmm, actually there still have a little bit difference from oom(NORMALNORMAL).

Quoted 6 lines
Quoted 3 lines

In alloc_mem() function, if testcase == KSM, the memory area will do madvise operation like:
madvise(s, length, MADV_MERGEABLE)

That's what I meant by "nearly identical". Looking at kernel, only ksm seems to care about that flag, and we turn KSM off:

Seems like skip oom(KSM) here is better than turn it off. :)

I'll rewrite a new one. Thanks!

Regards,
Li WANG