mem/oom, tunable: perform cleanup actions only when they are actually required
PATCH 1/1 mem/oom, tunable: perform cleanup actions only when they are actually required
In these test cases setup() may call tst_brk(TCONF) and so on we need to make cleanup() "revert" only those actions which had been actually performed in setup() before it called tst_brk(TCONF).
--- testcases/kernel/mem/lib/mem.c | 2 ++ testcases/kernel/mem/oom/oom01.c | 3 ++- testcases/kernel/mem/oom/oom02.c | 3 ++- testcases/kernel/mem/oom/oom03.c | 9 +++++++-- testcases/kernel/mem/oom/oom04.c | 9 +++++++-- testcases/kernel/mem/oom/oom05.c | 14 +++++++++++--- testcases/kernel/mem/tunable/max_map_count.c | 10 ++++++---- testcases/kernel/mem/tunable/min_free_kbytes.c | 10 ++++++---- testcases/kernel/mem/tunable/overcommit_memory.c | 10 ++++++---- 9 files changed, 49 insertions(+), 21 deletions(-)
testcases/kernel/mem/lib/mem.c +2 -0
@@ -27,6 +27,8 @@/* OOM */ +long overcommit =-1 ; +static int alloc_mem (long int length,int testcase) {char *s;
testcases/kernel/mem/oom/oom01.c +2 -1
@@ -55,7 +55,8 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); }static struct tst_test test = {
testcases/kernel/mem/oom/oom02.c +2 -1
@@ -62,7 +62,8 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); }static struct tst_test test = {
testcases/kernel/mem/oom/oom03.c +7 -2
@@ -35,6 +35,8 @@#ifdef HAVE_NUMA_V2 +static int memcg_mounted; +static void verify_oom (void ) {#if __WORDSIZE ==32
@@ -71,12 +73,15 @@ static void setup(void) overcommit =get_sys_tune ("overcommit_memory" );set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("memcg" ,"cgroup" ,"memory" ,MEMCG_PATH ,MEMCG_PATH_NEW ); + memcg_mounted =1 ; }static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (memcg_mounted) +umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); }static struct tst_test test = {
testcases/kernel/mem/oom/oom04.c +7 -2
@@ -35,6 +35,8 @@#ifdef HAVE_NUMA_V2 +static int cpuset_mounted; +static void verify_oom (void ) {#if __WORDSIZE ==32
@@ -67,6 +69,7 @@ static void setup(void)set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("cpuset" ,"cpuset" ,NULL ,CPATH ,CPATH_NEW ); + cpuset_mounted =1 ;/* * Some nodes do not contain memory, so use
@@ -83,8 +86,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (CPATH ,CPATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (cpuset_mounted) +umount_mem (CPATH ,CPATH_NEW ); }static struct tst_test test = {
testcases/kernel/mem/oom/oom05.c +11 -3
@@ -35,6 +35,9 @@#ifdef HAVE_NUMA_V2 +static int memcg_mounted; +static int cpuset_mounted; +static void verify_oom (void ) {int swap_acc_on =1 ;
@@ -90,7 +93,9 @@ void setup(void)set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("memcg" ,"cgroup" ,"memory" ,MEMCG_PATH ,MEMCG_PATH_NEW ); + memcg_mounted =1 ;mount_mem ("cpuset" ,"cpuset" ,NULL ,CPATH ,CPATH_NEW ); + cpuset_mounted =1 ;write_memcg ();/*
@@ -108,9 +113,12 @@ void setup(void)void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (CPATH ,CPATH_NEW ); -umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (cpuset_mounted) +umount_mem (CPATH ,CPATH_NEW ); +if (memcg_mounted) +umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); }static struct tst_test test = {
testcases/kernel/mem/tunable/max_map_count.c +6 -4
@@ -53,8 +53,8 @@#define MAP_COUNT_DEFAULT 1024#define MAX_MAP_COUNT 65536L -static long old_max_map_count; -static long old_overcommit; +static long old_max_map_count =-1 ; +static long old_overcommit =-1 ;static struct utsname un;static void setup (void )
@@ -73,8 +73,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , old_overcommit,0 ); -set_sys_tune ("max_map_count" , old_max_map_count,0 ); +if (old_overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , old_overcommit,0 ); +if (old_max_map_count !=-1 ) +set_sys_tune ("max_map_count" , old_max_map_count,0 ); }/* This is a filter to exclude map entries which aren't accounted
testcases/kernel/mem/tunable/min_free_kbytes.c +6 -4
@@ -39,8 +39,8 @@#define MAP_SIZE (1UL<<20)volatile int end; -static unsigned long default_tune; -static unsigned long orig_overcommit; +static long default_tune =-1 ; +static long orig_overcommit =-1 ;static unsigned long total_mem;static void test_tune (unsigned long overcommit_policy);
@@ -221,8 +221,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("min_free_kbytes" , default_tune,0 ); -set_sys_tune ("overcommit_memory" , orig_overcommit,0 ); +if (default_tune !=-1 ) +set_sys_tune ("min_free_kbytes" , default_tune,0 ); +if (orig_overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , orig_overcommit,0 ); }static struct tst_test test = {
testcases/kernel/mem/tunable/overcommit_memory.c +6 -4
@@ -81,8 +81,8 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; -static long old_overcommit_memory; -static long old_overcommit_ratio; +static long old_overcommit_memory =-1 ; +static long old_overcommit_ratio =-1 ;static long overcommit_ratio;static long sum_total;static long free_total;
@@ -136,8 +136,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , old_overcommit_memory,0 ); -set_sys_tune ("overcommit_ratio" , old_overcommit_ratio,0 ); +if (old_overcommit_memory !=-1 ) +set_sys_tune ("overcommit_memory" , old_overcommit_memory,0 ); +if (old_overcommit_ratio !=-1 ) +set_sys_tune ("overcommit_ratio" , old_overcommit_ratio,0 ); }static void overcommit_memory_test (void )
Signature · 1 line
1.7.1
PATCH 1/1 mem/oom, tunable: perform cleanup actions only when they are actually required
Hi!
Could anybody have a look at this patch, please?
Thanks.
Quoted 248 lines · Stanislav Kholmanskikh
In these test cases
setup()may calltst_brk(TCONF)and so on we need to makecleanup()"revert" only those actions which had been actually performed insetup()before it calledtst_brk(TCONF).Signed-off-by Stanislav Kholmanskikh <[email protected]>--- testcases/kernel/mem/lib/mem.c | 2 ++ testcases/kernel/mem/oom/oom01.c | 3 ++- testcases/kernel/mem/oom/oom02.c | 3 ++- testcases/kernel/mem/oom/oom03.c | 9 +++++++-- testcases/kernel/mem/oom/oom04.c | 9 +++++++-- testcases/kernel/mem/oom/oom05.c | 14 +++++++++++--- testcases/kernel/mem/tunable/max_map_count.c | 10 ++++++---- testcases/kernel/mem/tunable/min_free_kbytes.c | 10 ++++++---- testcases/kernel/mem/tunable/overcommit_memory.c | 10 ++++++---- 9 files changed, 49 insertions(+), 21 deletions(-)testcases/kernel/mem/lib/mem.c +2
-0@@ -27,6 +27,8 @@/* OOM */ +long overcommit =-1 ; +static int alloc_mem (long int length,int testcase) {char *s;testcases/kernel/mem/oom/oom01.c +2
-1@@ -55,7 +55,8 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); }static struct tst_test test = {testcases/kernel/mem/oom/oom02.c +2
-1@@ -62,7 +62,8 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); }static struct tst_test test = {testcases/kernel/mem/oom/oom03.c +7
-2@@ -35,6 +35,8 @@#ifdef HAVE_NUMA_V2 +static int memcg_mounted; +static void verify_oom (void ) {#if __WORDSIZE ==32 @@ -71,12 +73,15 @@ static void setup(void) overcommit =get_sys_tune ("overcommit_memory" );set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("memcg" ,"cgroup" ,"memory" ,MEMCG_PATH ,MEMCG_PATH_NEW ); + memcg_mounted =1 ; }static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (memcg_mounted) +umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); }static struct tst_test test = {testcases/kernel/mem/oom/oom04.c +7
-2@@ -35,6 +35,8 @@#ifdef HAVE_NUMA_V2 +static int cpuset_mounted; +static void verify_oom (void ) {#if __WORDSIZE ==32 @@ -67,6 +69,7 @@ static void setup(void)set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("cpuset" ,"cpuset" ,NULL ,CPATH ,CPATH_NEW ); + cpuset_mounted =1 ;/* * Some nodes do not contain memory, so use @@ -83,8 +86,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (CPATH ,CPATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (cpuset_mounted) +umount_mem (CPATH ,CPATH_NEW ); }static struct tst_test test = {testcases/kernel/mem/oom/oom05.c +11
-3@@ -35,6 +35,9 @@#ifdef HAVE_NUMA_V2 +static int memcg_mounted; +static int cpuset_mounted; +static void verify_oom (void ) {int swap_acc_on =1 ;@@ -90,7 +93,9 @@ void setup(void)set_sys_tune ("overcommit_memory" ,1 ,1 );mount_mem ("memcg" ,"cgroup" ,"memory" ,MEMCG_PATH ,MEMCG_PATH_NEW ); + memcg_mounted =1 ;mount_mem ("cpuset" ,"cpuset" ,NULL ,CPATH ,CPATH_NEW ); + cpuset_mounted =1 ;write_memcg ();/* @@ -108,9 +113,12 @@ void setup(void)void cleanup (void ) { -set_sys_tune ("overcommit_memory" , overcommit,0 ); -umount_mem (CPATH ,CPATH_NEW ); -umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); +if (overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , overcommit,0 ); +if (cpuset_mounted) +umount_mem (CPATH ,CPATH_NEW ); +if (memcg_mounted) +umount_mem (MEMCG_PATH ,MEMCG_PATH_NEW ); }static struct tst_test test = {testcases/kernel/mem/tunable/max_map_count.c +6
-4@@ -53,8 +53,8 @@#define MAP_COUNT_DEFAULT 1024#define MAX_MAP_COUNT 65536L -static long old_max_map_count; -static long old_overcommit; +static long old_max_map_count =-1 ; +static long old_overcommit =-1 ;static struct utsname un;static void setup (void )@@ -73,8 +73,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , old_overcommit,0 ); -set_sys_tune ("max_map_count" , old_max_map_count,0 ); +if (old_overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , old_overcommit,0 ); +if (old_max_map_count !=-1 ) +set_sys_tune ("max_map_count" , old_max_map_count,0 ); }/* This is a filter to exclude map entries which aren't accounted testcases/kernel/mem/tunable/min_free_kbytes.c +6
-4@@ -39,8 +39,8 @@#define MAP_SIZE (1UL<<20)volatile int end; -static unsigned long default_tune; -static unsigned long orig_overcommit; +static long default_tune =-1 ; +static long orig_overcommit =-1 ;static unsigned long total_mem;static void test_tune (unsigned long overcommit_policy);@@ -221,8 +221,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("min_free_kbytes" , default_tune,0 ); -set_sys_tune ("overcommit_memory" , orig_overcommit,0 ); +if (default_tune !=-1 ) +set_sys_tune ("min_free_kbytes" , default_tune,0 ); +if (orig_overcommit !=-1 ) +set_sys_tune ("overcommit_memory" , orig_overcommit,0 ); }static struct tst_test test = {testcases/kernel/mem/tunable/overcommit_memory.c +6
-4@@ -81,8 +81,8 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; -static long old_overcommit_memory; -static long old_overcommit_ratio; +static long old_overcommit_memory =-1 ; +static long old_overcommit_ratio =-1 ;static long overcommit_ratio;static long sum_total;static long free_total;@@ -136,8 +136,10 @@ static void setup(void)static void cleanup (void ) { -set_sys_tune ("overcommit_memory" , old_overcommit_memory,0 ); -set_sys_tune ("overcommit_ratio" , old_overcommit_ratio,0 ); +if (old_overcommit_memory !=-1 ) +set_sys_tune ("overcommit_memory" , old_overcommit_memory,0 ); +if (old_overcommit_ratio !=-1 ) +set_sys_tune ("overcommit_ratio" , old_overcommit_ratio,0 ); }static void overcommit_memory_test (void )
PATCH 1/1 mem/oom, tunable: perform cleanup actions only when they are actually required
Hi!
Quoted 1 line
Could anybody have a look at this patch, please?
Looks good to me.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 mem/oom, tunable: perform cleanup actions only when they are actually required
Quoted 5 lines · Cyril Hrubis
Hi!
Quoted 1 line
Could anybody have a look at this patch, please?
Looks good to me.
Thank you very much. Pushed.