Skip to contentSkip to conversation

mem/overcommit_memory.c: Fix "CommitLimit < Committed_AS" error in some situations

PATCH New Xiao Yang 3 participants 4 messages Oct 19, 2018 – Dec 20, 2018

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

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
index 82ceac5f6..b92232b8d 100644
@@ -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
#1 lore raw

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 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
----------------------------------------------------------------------

Quoted 6 lines

We try to skip test if setting a small value of overcommit_ratio results in "CommitLimit < Committed_AS".

Fix: #215

Quoted 3 lines
---
 .../kernel/mem/tunable/overcommit_memory.c    | 30 ++++++++++++-------
 1 file changed, 20 insertions(+), 10 deletions(-)

Kind regards,
Petr

#2 lore raw

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 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
----------------------------------------------------------------------

Quoted 7 lines
Quoted 6 lines

We try to skip test if setting a small value of overcommit_ratio results in "CommitLimit < Committed_AS".

Fix: #215

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

#3 lore raw

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
index b92232b8d..07f824328 100644
@@ -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);
 	}
 }