mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations
PATCH 1/1 mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations
By default, system with overcommit_memory=2 will ensure "CommitLimit >= Committed_AS" when setting overcommit_ratio. But we change overcommit_ratio to a random value forcely, so it's possible to decrease CommitLimit less than current Committed_AS when setting overcommit_ratio to a quite small value(e.g. 0).
For example, there are 5G physical memory, 4G swap and 5G allocated memory (i.e. Committed_AS) on system, and then running overcommit_memory02(i.e. overcommit_memory -R 0) always triggers the "CommitLimit < Committed_AS" error:
----------------------------------------------------------------------
mem.c:839: INFO: set overcommit_ratio to 0
mem.c:839: INFO: set overcommit_memory to 2 overcommit_memory.c:235: INFO: CommitLimit is 4194300, Committed_AS is 5405908 overcommit_memory.c:237: BROK: Unexpected error: CommitLimit < Committed_AS
----------------------------------------------------------------------
We try to skip test if setting a small value of overcommit_ratio results in "CommitLimit < Committed_AS".
Fix: #215
--- .../kernel/mem/tunable/overcommit_memory.c | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-)
testcases/kernel/mem/tunable/overcommit_memory.c +20 -10
@@ -92,6 +92,7 @@ static long commit_left;static int heavy_malloc (long size);static void alloc_and_check (long size,int expect_result);static void update_mem (void ); +static void update_mem_commit (void );static void setup (void ) {
@@ -151,10 +152,10 @@ static void overcommit_memory_test(void)/* start to test overcommit_memory=2 */ set_sys_tune ("overcommit_memory" ,2 ,1 ); -update_mem (); +update_mem_commit ();alloc_and_check (commit_left *2 ,EXPECT_FAIL );alloc_and_check (commit_limit,EXPECT_FAIL ); -update_mem (); +update_mem_commit ();alloc_and_check (commit_left /2 ,EXPECT_PASS );/* start to test overcommit_memory=0 */
@@ -219,23 +220,32 @@ static void alloc_and_check(long size, int expect_result)static void update_mem (void ) {long mem_free, swap_free; -long committed; mem_free =SAFE_READ_MEMINFO ("MemFree:" ); swap_free =SAFE_READ_MEMINFO ("SwapFree:" ); free_total = mem_free + swap_free; +} + +static void update_mem_commit (void ) +{ +long committed; + commit_limit =SAFE_READ_MEMINFO ("CommitLimit:" ); + committed =SAFE_READ_MEMINFO ("Committed_AS:" ); + commit_left = commit_limit - committed; -if (get_sys_tune ("overcommit_memory" ) ==2 ) { - committed =SAFE_READ_MEMINFO ("Committed_AS:" ); - commit_left = commit_limit - committed; +if (commit_left <0 ) { +tst_res (TINFO ,"CommitLimit is %ld, Committed_AS is %ld" , + commit_limit, committed); -if (commit_left <0 ) { -tst_res (TINFO ,"CommitLimit is %ld, Committed_AS" -" is %ld" , commit_limit, committed); +if (overcommit_ratio > old_overcommit_ratio) {tst_brk (TBROK ,"Unexpected error: " -"CommitLimit < Committed_AS" ); +"CommitLimit < Committed_AS" ); } + +tst_brk (TCONF ,"Specified overcommit_ratio %ld < default %ld, " +"so it's possible for CommitLimit < Committed_AS and " +"skip test" , overcommit_ratio, old_overcommit_ratio); } }
Signature · 1 line
2.17.0
PATCH 1/1 mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations
Hi Xiao,
Quoted 17 lines
By default, system with overcommit_memory=2 will ensure "CommitLimit >=
Committed_AS" when settingovercommit_ratio. But we changeovercommit_ratioto a random value forcely, so it's possible to decrease CommitLimit less than currentCommitted_ASwhen settingovercommit_ratioto a quite small value(e.g. 0).For example, there are 5G physical memory, 4G swap and 5G allocated memory (i.e.
Committed_AS) on system, and then running overcommit_memory02(i.e.overcommit_memory-R 0) always triggers the "CommitLimit <Committed_AS" error:
----------------------------------------------------------------------
mem.c:839: INFO: setovercommit_ratioto 0
mem.c:839: INFO: setovercommit_memoryto 2 overcommit_memory.c:235: INFO: CommitLimit is 4194300,Committed_ASis 5405908 overcommit_memory.c:237: BROK: Unexpected error: CommitLimit <Committed_AS
----------------------------------------------------------------------
Quoted 6 lines
We try to skip test if setting a small value of
overcommit_ratioresults in "CommitLimit <Committed_AS".Fix: #215
Signed-off-by Xiao Yang <[email protected]>
Quoted 3 lines
--- .../kernel/mem/tunable/overcommit_memory.c | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-)
Kind regards,
Petr
PATCH 1/1 mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations
Hi
Quoted 19 lines · Petr Vorel
Hi Xiao,
Quoted 16 lines
By default, system with overcommit_memory=2 will ensure "CommitLimit >=
Committed_AS" when settingovercommit_ratio. But we changeovercommit_ratioto a random value forcely, so it's possible to decrease CommitLimit less than currentCommitted_ASwhen settingovercommit_ratioto a quite small value(e.g. 0).For example, there are 5G physical memory, 4G swap and 5G allocated memory (i.e.
Committed_AS) on system, and then running overcommit_memory02(i.e.overcommit_memory-R 0) always triggers the "CommitLimit <Committed_AS" error:
----------------------------------------------------------------------
mem.c:839: INFO: setovercommit_ratioto 0
mem.c:839: INFO: setovercommit_memoryto 2 overcommit_memory.c:235: INFO: CommitLimit is 4194300,Committed_ASis 5405908 overcommit_memory.c:237: BROK: Unexpected error: CommitLimit <Committed_AS
----------------------------------------------------------------------
Quoted 7 lines
Quoted 6 lines
We try to skip test if setting a small value of
overcommit_ratioresults in "CommitLimit <Committed_AS".Fix: #215
Signed-off-by Xiao Yang <[email protected]>Reviewed-by Petr Vorel <[email protected]>
Any chance this reviewed/fixed patch will be merged soon ?
Thanks
Cristian
Quoted 9 lines
Quoted 4 lines
--- .../kernel/mem/tunable/overcommit_memory.c | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-)Kind regards,
Petr
PATCH 1/1 mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations
Hi Xiao, Cristian,
Quoted 1 line
Any chance this reviewed/fixed patch will be merged soon ?
Thanks for pointing out. Pushed, with following diff bellow. (TCONF is for <=, not <).
Quoted 3 lines
Thanks
Cristian
Kind regards,
Petr
kernel/mem/tunable/overcommit_memory.c +3 -3
@@ -243,9 +243,9 @@ static void update_mem_commit(void) "CommitLimit < Committed_AS"); } -tst_brk (TCONF ,"Specified overcommit_ratio %ld < default %ld, " -"so it's possible for CommitLimit < Committed_AS and " -"skip test" , overcommit_ratio, old_overcommit_ratio); +tst_brk (TCONF ,"Specified overcommit_ratio %ld <= default %ld, " +"so it's possible for CommitLimit < Committed_AS and skip test" , + overcommit_ratio, old_overcommit_ratio); } }