mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/util: Fix meminfo CommitLimit
@ 2024-08-19 11:36 Vernon Yang
  0 siblings, 0 replies; only message in thread
From: Vernon Yang @ 2024-08-19 11:36 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Vernon Yang

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@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-19 11:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 11:36 [PATCH] mm/util: Fix meminfo CommitLimit Vernon Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®