madvise06: Allow for kmem and memsw counters being disabled
PATCH 1/1 madvise06: Allow for kmem and memsw counters being disabled
These may be missing and we only access them for printing diagnostic info.
--- testcases/kernel/syscalls/madvise/madvise06.c | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/madvise/madvise06.c +14 -8
@@ -64,14 +64,16 @@ static void check_path(const char *path) }#define READ_CGMEM (item) \ - ({long tst_rval; \ - SAFE_FILE_LINES_SCANF(MNT_NAME"/"GROUP_NAME"/memory."item, \ - "%ld", \ - &tst_rval); \ + ({long tst_rval = 0; \ + const char *cgpath = MNT_NAME"/"GROUP_NAME"/memory."item; \ + if (!access(cgpath, R_OK)) \ + SAFE_FILE_LINES_SCANF(cgpath, "%ld", &tst_rval); \ tst_rval;})static void meminfo_diag (const char *point) { +long rval; +FILE_PRINTF ("/proc/sys/vm/stat_refresh" ,"1" );tst_res (TINFO ,"%s" , point); tst_res(TINFO, "\tSwap: %ld Kb",
@@ -82,10 +84,14 @@ static void meminfo_diag(const char *point) SAFE_READ_MEMINFO("Cached:") - init_cached);tst_res (TINFO ,"\tcgmem.usage_in_bytes: %ld Kb" ,READ_CGMEM ("usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , -READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , -READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ); + + rval =READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , rval); + + rval =READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , rval); }static void setup (void )
Signature · 1 line
2.29.1
PATCH 1/1 madvise06: Allow for kmem and memsw counters being disabled
Hi Richard,
This one looks good to me.
Quoted 5 lines · Richard Palethorpe
These may be missing and we only access them for printing diagnostic info.
Signed-off-by Richard Palethorpe <[email protected]>
Quoted 55 lines
--- testcases/kernel/syscalls/madvise/madvise06.c | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-)testcases/kernel/syscalls/madvise/madvise06.c +14
-8@@ -64,14 +64,16 @@ static void check_path(const char *path) }#define READ_CGMEM (item) \ - ({long tst_rval; \ - SAFE_FILE_LINES_SCANF(MNT_NAME"/"GROUP_NAME"/memory."item, \ - "%ld", \ - &tst_rval); \ + ({long tst_rval = 0; \ + const char *cgpath = MNT_NAME"/"GROUP_NAME"/memory."item; \ + if (!access(cgpath, R_OK)) \ + SAFE_FILE_LINES_SCANF(cgpath, "%ld", &tst_rval); \ tst_rval;})static void meminfo_diag (const char *point) { +long rval; +FILE_PRINTF ("/proc/sys/vm/stat_refresh" ,"1" );tst_res (TINFO ,"%s" , point); tst_res(TINFO, "\tSwap: %ld Kb",@@ -82,10 +84,14 @@ static void meminfo_diag(const char *point) SAFE_READ_MEMINFO("Cached:") - init_cached);tst_res (TINFO ,"\tcgmem.usage_in_bytes: %ld Kb" ,READ_CGMEM ("usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , -READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , -READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ); + + rval =READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , rval); + + rval =READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , rval); }static void setup(void)
--
2.29.1
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20201117/4729d55c/attachment.htm>
PATCH v2 1/1 madvise06: Allow for kmem and memsw counters being disabled
In reply to Richard PalethorpeThese may be missing in which case we can not read them for diagnostic info or set the swap limit to a value which is known to be large enough. However if there is no swap counter then there is no swap limit, so we just try to set the limit if the counter exists.
---
V2: Check if the memsw limit exists before writing to it. This
replaces another patch which removed it altogether.
testcases/kernel/syscalls/madvise/madvise06.c | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/madvise/madvise06.c +19 -10
@@ -65,14 +65,16 @@ static void check_path(const char *path) }#define READ_CGMEM (item) \ - ({long tst_rval; \ - SAFE_FILE_LINES_SCANF(MNT_NAME"/"GROUP_NAME"/memory."item, \ - "%ld", \ - &tst_rval); \ + ({long tst_rval = 0; \ + const char *cgpath = MNT_NAME"/"GROUP_NAME"/memory."item; \ + if (!access(cgpath, R_OK)) \ + SAFE_FILE_LINES_SCANF(cgpath, "%ld", &tst_rval); \ tst_rval;})static void meminfo_diag (const char *point) { +long rval; +FILE_PRINTF ("/proc/sys/vm/stat_refresh" ,"1" );tst_res (TINFO ,"%s" , point); tst_res(TINFO, "\tSwap: %ld Kb",
@@ -83,10 +85,14 @@ static void meminfo_diag(const char *point) SAFE_READ_MEMINFO("Cached:") - init_cached);tst_res (TINFO ,"\tcgmem.usage_in_bytes: %ld Kb" ,READ_CGMEM ("usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , -READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ); -tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , -READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ); + + rval =READ_CGMEM ("memsw.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.memsw.usage_in_bytes: %ld Kb" , rval); + + rval =READ_CGMEM ("kmem.usage_in_bytes" ) /1024 ; +if (rval) +tst_res (TINFO ,"\tcgmem.kmem.usage_in_bytes: %ld Kb" , rval); }static void setup (void )
@@ -124,8 +130,11 @@ static void setup(void)SAFE_FILE_PRINTF ("/proc/self/oom_score_adj" ,"%d" ,-1000 );SAFE_FILE_PRINTF (MNT_NAME "/" GROUP_NAME "/memory.limit_in_bytes" ,"%ld\n" ,MEM_LIMIT ); -SAFE_FILE_PRINTF (MNT_NAME "/" GROUP_NAME "/memory.memsw.limit_in_bytes" ,"%ld\n" , -MEMSW_LIMIT ); + +if (!access (MNT_NAME "/" GROUP_NAME "/memory.memsw.limit_in_bytes" ,W_OK )) { +SAFE_FILE_PRINTF (MNT_NAME "/" GROUP_NAME "/memory.memsw.limit_in_bytes" , +"%ld\n" ,MEMSW_LIMIT ); + }SAFE_FILE_PRINTF (MNT_NAME "/" GROUP_NAME "/memory.swappiness" ,"60" );SAFE_FILE_PRINTF (MNT_NAME "/" GROUP_NAME "/tasks" ,"%d\n" ,getpid ());
Signature · 1 line
2.29.1
Li Wang
AppliedPATCH v2 1/1 madvise06: Allow for kmem and memsw counters being disabled
Quoted 5 lines · Richard Palethorpe
These may be missing in which case we can not read them for diagnostic info or set the swap limit to a value which is known to be large enough. However if there is no swap counter then there is no swap limit, so we just try to set the limit if the counter exists.
Quoted 7 lines
Signed-off-by Richard Palethorpe <[email protected]>Reviewed-by Li Wang <[email protected]>---
V2: Check if the memsw limit exists before writing to it. This
replaces another patch which removed it altogether.
Merged, thanks.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20201118/786c43a7/attachment-0001.htm>