[PATCH] mm/util: Fix meminfo CommitLimit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On a machine with 8GB memory, no any swap device, the /proc/meminfo
CommitLimit shows 4070944KB regardless of overcommit_memory being set to
0/1/2. This patch fixes this bug, and the final effect is as follows:

- when overcommit_memory being set to 0  ## OVERCOMMIT_GUESS
CommitLimit:     8141884 kB
- when overcommit_memory being set to 1  ## OVERCOMMIT_ALWAYS
CommitLimit:           0 kB
- when overcommit_memory being set to 2  ## OVERCOMMIT_NEVER
  and overcommit_ratio 50
CommitLimit:     4070940 kB

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Vernon Yang <vernon2gm@xxxxxxxxx>
---
 mm/util.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index bd283e2132e0..4ee93c11dd62 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -932,12 +932,21 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu
 }
 
 /*
- * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
+ * Committed virtual memory limit
+ *
+ * return 0 if OVERCOMMIT_ALWAYS policy is used, otherwise return committed
+ * memory limit enforced if OVERCOMMIT_GUESS or OVERCOMMIT_NEVER policy is used.
  */
 unsigned long vm_commit_limit(void)
 {
 	unsigned long allowed;
 
+	if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS)
+		return 0;
+
+	if (sysctl_overcommit_memory == OVERCOMMIT_GUESS)
+		return totalram_pages() + total_swap_pages;
+
 	if (sysctl_overcommit_kbytes)
 		allowed = sysctl_overcommit_kbytes >> (PAGE_SHIFT - 10);
 	else

base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
-- 
2.34.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux