madvise06: Fix segfault
PATCH 1/2 madvise06: Fix segfault
Test required update after 687f0cbc00 to use struct tst_path_val. While at it, move the initialization to struct tst_path_val.
---
Is it ok to define it earlier? i.e. before calling sync() ?
testcases/kernel/syscalls/madvise/madvise06.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/madvise/madvise06.c +4 -4
@@ -54,6 +54,7 @@#define MEMSW_LIMIT (2 * CHUNK_SZ)#define PASS_THRESHOLD (CHUNK_SZ / 4)#define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024) +#define SWAPPINESS "60"static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static int pg_sz, stat_refresh_sup;
@@ -123,10 +124,9 @@ static void setup(void)SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT );if (SAFE_CG_HAS (tst_cg,"memory.swappiness" )) { -SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,"60" ); +SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,SWAPPINESS ); }else {check_path ("/proc/sys/vm/swappiness" ); -SAFE_FILE_PRINTF ("/proc/sys/vm/swappiness" ,"%d" ,60 ); }SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());
@@ -229,8 +229,8 @@ static struct tst_test test = { .min_kver = "3.10.0", .needs_tmpdir = 1, .needs_root = 1, - .save_restore = (const char *const []) { -"?/proc/sys/vm/swappiness" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/vm/swappiness" ,SWAPPINESS },NULL }, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 madvise06: Move oom_score_adj initialization to struct tst_path_val
---
Is it ok to define it earlier? i.e. before calling sync() ?
testcases/kernel/syscalls/madvise/madvise06.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/madvise/madvise06.c +2 -3
@@ -55,6 +55,7 @@#define PASS_THRESHOLD (CHUNK_SZ / 4)#define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024)#define SWAPPINESS "60" +#define OOM_SCORE_ADJ "-1000"static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static int pg_sz, stat_refresh_sup;
@@ -116,9 +117,6 @@ static void setup(void) 2 * CHUNK_SZ); } -check_path ("/proc/self/oom_score_adj" ); -SAFE_FILE_PRINTF ("/proc/self/oom_score_adj" ,"%d" ,-1000 ); -SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%ld" ,MEM_LIMIT );if (SAFE_CG_HAS (tst_cg,"memory.swap.max" ))SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT );
@@ -231,6 +229,7 @@ static struct tst_test test = { .needs_root = 1, .save_restore = (const struct tst_path_val const []) { {"?/proc/sys/vm/swappiness" ,SWAPPINESS }, + {"/proc/self/oom_score_adj" ,OOM_SCORE_ADJ },NULL }, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] madvise06: Move oom_score_adj initialization to struct tst_path_val
Hi!
Quoted 30 lines
Signed-off-by Petr Vorel <[email protected]>---
Is it ok to define it earlier? i.e. before callingsync()?testcases/kernel/syscalls/madvise/madvise06.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)testcases/kernel/syscalls/madvise/madvise06.c +1
-3@@ -55,6 +55,7 @@#define PASS_THRESHOLD (CHUNK_SZ / 4)#define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024)#define SWAPPINESS "60" +#define OOM_SCORE_ADJ "-1000"static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static int pg_sz, stat_refresh_sup;@@ -116,9 +117,6 @@ static void setup(void) 2 * CHUNK_SZ); } -check_path ("/proc/self/oom_score_adj" ); -SAFE_FILE_PRINTF ("/proc/self/oom_score_adj" ,"%d" ,-1000 ); -SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%ld" ,MEM_LIMIT );if (SAFE_CG_HAS (tst_cg,"memory.swap.max" ))SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT );
testcases/kernel/syscalls/madvise/madvise06.c static struct tst_test test = { · line 232
Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise06.c +1
-0@@ -231,6 +229,7 @@ static struct tst_test test = { .needs_root = 1, .save_restore = (const struct tst_path_val const []) { {"?/proc/sys/vm/swappiness" ,SWAPPINESS }, + {"/proc/self/oom_score_adj" ,OOM_SCORE_ADJ },
I do not think that this is even correct, after this change the file is being written to by the test library and the 'self' points to a different process as far as I can tell.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] madvise06: Move oom_score_adj initialization to struct tst_path_val
Quoted 19 lines · Cyril Hrubis
Hi!
Review
Quoted 8 lines
Signed-off-by Petr Vorel <[email protected]>---
Is it ok to define it earlier? i.e. before callingsync()?testcases/kernel/syscalls/madvise/madvise06.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/testcases/kernel/syscalls/madvise/madvise06.cQuoted 9 lines
index
b21f2cc7de..15171442cb100644testcases/kernel/syscalls/madvise/madvise06.c +1
-0@@ -55,6 +55,7 @@#define PASS_THRESHOLD (CHUNK_SZ / 4)#define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024)#define SWAPPINESS "60" +#define OOM_SCORE_ADJ "-1000"
Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise06.c static void setup(void) · line 120
Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise06.c +0
-2static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static int pg_sz, stat_refresh_sup;@@ -116,9 +117,6 @@ static void setup(void) 2 * CHUNK_SZ); } -check_path ("/proc/self/oom_score_adj" ); -SAFE_FILE_PRINTF ("/proc/self/oom_score_adj" ,"%d" ,-1000 );
Maybe use tst_enable_oom_protection(0) here is better.
Quoted 5 lines
-
testcases/kernel/syscalls/madvise/madvise06.c static void setup(void)
Quoted 3 lines
testcases/kernel/syscalls/madvise/madvise06.c +0
-0SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%ld" ,MEM_LIMIT );if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%ld",
MEMSW_LIMIT);
Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c static struct tst_test test = { · line 232
Quoted 5 lines
testcases/kernel/syscalls/madvise/madvise06.c +1
-0@@ -231,6 +229,7 @@ static struct tst_test test = { .needs_root = 1, .save_restore = (const struct tst_path_val const []) { {"?/proc/sys/vm/swappiness" ,SWAPPINESS }, + {"/proc/self/oom_score_adj" ,OOM_SCORE_ADJ },I do not think that this is even correct, after this change the file is being written to by the test library and the 'self' points to a different process as far as I can tell.
That's right. But from the code logic, seems it try to protect the madvise06 from being killed by OOM. So enabling the oom protection in the test library also has the same effect because children(madvise06) will inherit the score.
However, I agree that we shouldn't add the oom_score_adj" knob in .svae_restore since that might bring more confusion to users.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 25 lines
Test required update after
687f0cbc00to use structtst_path_val. While at it, move the initialization to structtst_path_val.Fixes 687f0cbc00 ("lib: enhance .save_restore to support set expected value")Signed-off-by Petr Vorel <[email protected]>---
Is it ok to define it earlier? i.e. before callingsync()?testcases/kernel/syscalls/madvise/madvise06.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)testcases/kernel/syscalls/madvise/madvise06.c +1
-0@@ -54,6 +54,7 @@#define MEMSW_LIMIT (2 * CHUNK_SZ)#define PASS_THRESHOLD (CHUNK_SZ / 4)#define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024) +#define SWAPPINESS "60"static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static int pg_sz, stat_refresh_sup;
testcases/kernel/syscalls/madvise/madvise06.c static void setup(void) · line 130
Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise06.c +1
-2@@ -123,10 +124,9 @@ static void setup(void)SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT );if (SAFE_CG_HAS (tst_cg,"memory.swappiness" )) { -SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,"60" ); +SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,SWAPPINESS ); }else {check_path ("/proc/sys/vm/swappiness" ); -SAFE_FILE_PRINTF ("/proc/sys/vm/swappiness" ,"%d" ,60 ); }
I'm not sure if we want to set the "/proc/sys/vm/swappiness" unconditinally in the .save_restore as previously we set it only if the cgroup was missing the swappines knob.
So maybe we should go for a minimal fix here, just change the save_restore to match the new format and don't set the value there.
testcases/kernel/syscalls/madvise/madvise06.c static struct tst_test test = { · line 234
Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c +2
-2SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());@@ -229,8 +229,8 @@ static struct tst_test test = { .min_kver = "3.10.0", .needs_tmpdir = 1, .needs_root = 1, - .save_restore = (const char *const []) { -"?/proc/sys/vm/swappiness" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/vm/swappiness" ,SWAPPINESS },NULL
This has to be terminated by {} now.
Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise06.c +0
-0}, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
...
Quoted 12 lines
testcases/kernel/syscalls/madvise/madvise06.c static void setup(void) · line 130
Quoted 7 lines
testcases/kernel/syscalls/madvise/madvise06.c +1
-2if (SAFE_CG_HAS (tst_cg,"memory.swappiness" )) { -SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,"60" ); +SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,SWAPPINESS ); }else {check_path ("/proc/sys/vm/swappiness" ); -SAFE_FILE_PRINTF ("/proc/sys/vm/swappiness" ,"%d" ,60 ); }I'm not sure if we want to set the "
/proc/sys/vm/swappiness" unconditinally in the .save_restore as previously we set it only if the cgroup was missing the swappines knob.
Quoted 2 lines
So maybe we should go for a minimal fix here, just change the
save_restoreto match the new format and don't set the value there.
Make sense.
Quoted 4 lines
Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise06.c +0
-0SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());@@ -229,8 +229,8 @@ static struct tst_test test = { .min_kver = "3.10.0", .needs_tmpdir = 1,
Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise06.c static struct tst_test test = { · line 234
Quoted 6 lines
testcases/kernel/syscalls/madvise/madvise06.c +2
-2.needs_root = 1, - .save_restore = (const char *const []) { -"?/proc/sys/vm/swappiness" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/vm/swappiness" ,SWAPPINESS },NULL This has to be terminated by {} now.
Ah, thx!
Anyway, merged only minimal change with your Reviewed-by: tag.
Thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp