mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vernon Yang <vernon2gm@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Vernon Yang <vernon2gm@gmail.com>
Subject: [PATCH] mm/util: Fix meminfo CommitLimit
Date: Mon, 19 Aug 2024 19:36:19 +0800	[thread overview]
Message-ID: <20240819113619.1267937-1-vernon2gm@gmail.com> (raw)

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


                 reply	other threads:[~2024-08-19 11:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240819113619.1267937-1-vernon2gm@gmail.com \
    --to=vernon2gm@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®