From patchwork Mon Aug 19 11:36:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vernon Yang X-Patchwork-Id: 13768199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED888C3DA4A for ; Mon, 19 Aug 2024 11:36:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 721026B007B; Mon, 19 Aug 2024 07:36:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D11B6B0082; Mon, 19 Aug 2024 07:36:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C02C6B0083; Mon, 19 Aug 2024 07:36:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3F47E6B007B for ; Mon, 19 Aug 2024 07:36:32 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ADCCD1410CB for ; Mon, 19 Aug 2024 11:36:31 +0000 (UTC) X-FDA: 82468792182.22.F82C1AA Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf28.hostedemail.com (Postfix) with ESMTP id 0622BC0016 for ; Mon, 19 Aug 2024 11:36:29 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HhftLMjg; spf=pass (imf28.hostedemail.com: domain of vernon2gm@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=vernon2gm@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724067329; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=+WiREMffi25nyyIzqdE8W4yA++e1IQrLgdZzBEOgG4c=; b=vJXCw4air0hv7M8DFW/TVv8qHYsDV5dHBFl08+RXTOlQzotw70Hk0Yr2LsKxW+wmfuYKsg jWe+00gc6UF4Cwgt0rIoKaHLXphmaNjVZ1HcUWReWO2+xgAiGWvRKe9/ls/aUtIiLL9zhM WOL977ZEfIrQyflhnBC2SrCVbyIHWlM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HhftLMjg; spf=pass (imf28.hostedemail.com: domain of vernon2gm@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=vernon2gm@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724067329; a=rsa-sha256; cv=none; b=DM1WCsjzYpG01JtMF1s+ZOsC3Ttlb7Egc/ZZDy4D+V2fUHsZwee/SKQOE4PGhro8d9fdty E6bSq6ZwExW2GrGdTSRS06WqOeitO+TdSx5lvCnoG5qV6dkCGhpWo4K9LckHAb5djB9eSv ncAWqC5b5VFdQFsEUaS/URrSg6iCkeU= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20202df1c2fso19286085ad.1 for ; Mon, 19 Aug 2024 04:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724067389; x=1724672189; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+WiREMffi25nyyIzqdE8W4yA++e1IQrLgdZzBEOgG4c=; b=HhftLMjgwosrGjEf3EcslX4isVwtPHxzk1Di+dpHdCron1nMR+Z23GOLRMRs94uzB5 nVDYWb9CZ4BK5VUdSbvzzp/8SNN1gmQHnxKGdAmPOUQZlBWQcXu/OAp5GNmRO+3I5d8N /q5EmaI24w5uJJlPG9lrXigRVEz9YEAFC07H4bHMAOn/nnHbxPsbKZZDFfgRZ5PN2ol3 +Jln20GtqMSVqUkCxoegPb3i6FbXn7+5vT7qdNyHryDENvVyQhx/yIPTTTGNnfBwva5f mW6Gz6IpRiXrJvMM/h+dphW1Z1NwRr993HMXpdUstAmA+ltTCSZk8xRCtrmn6aQxB8fy QZwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724067389; x=1724672189; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+WiREMffi25nyyIzqdE8W4yA++e1IQrLgdZzBEOgG4c=; b=PkiF7IB8o899FwT186biSdv33a2GFGvd1zOCoiDZwCYMJ3gpZIp+0w/0exvp6RAMTL 97lfJyqe94sCi6VHWEhuVUKRcg549PpJ0WGusqRVpRC1BSLAAotUE+a9ioonp00awYMk yVMxcnlxfB0NlTl1OPa//T019qCm1I2YlxknVoQGgT8y4YQLfX2uZu48qLC2CxvWjzFw zpbJpkXz/Yw8LwM93l59eFMia6uT9hGRDzYyAUaUHMwnXYqAbwDeXVPDNmxFQdIyk8k+ 3JkUBUfQ+9V8HKWhJZVZrvHwp1s/SSDBbEFQ4f+2DCVNu/kYEfNLYbbrwvTQ4ba8tH7A m6/A== X-Gm-Message-State: AOJu0YzZjbj8qg0g0Y4PrqomYXr8xNStIrZ3gWMjl73+Rp+/cciwokdg Y6jH5g6wSyXetiL3IhtybspH3c1Ach/KielCldRsYVWpDWOiMG9N X-Google-Smtp-Source: AGHT+IHGh02cvfBz2W5qfnXKONV2HpC6aEUYbSAynA7KDT1UIEitJ0Iyq8mXZoWh7adSZXcMLQbKYg== X-Received: by 2002:a17:903:35c4:b0:201:eb46:1be5 with SMTP id d9443c01a7336-20206162588mr139288285ad.3.1724067388543; Mon, 19 Aug 2024 04:36:28 -0700 (PDT) Received: from vernon-pc.. ([121.232.96.69]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f0319683sm61362135ad.67.2024.08.19.04.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 04:36:27 -0700 (PDT) From: Vernon Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vernon Yang Subject: [PATCH] mm/util: Fix meminfo CommitLimit Date: Mon, 19 Aug 2024 19:36:19 +0800 Message-Id: <20240819113619.1267937-1-vernon2gm@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: rrxzcg3zna46gxn6prg58nhfugpuum35 X-Rspam-User: X-Rspamd-Queue-Id: 0622BC0016 X-Rspamd-Server: rspam02 X-HE-Tag: 1724067389-317425 X-HE-Meta: U2FsdGVkX1+tJXDSnTZkVeKFD60dQB01FrwlwM8KBkDe3GJapWglDnnpwMm/XBKpjK5t4BBxR7XoA9ruvzXptRcOFSgztUVHmflhE1VWHqxDwjHO9xIsKCjavvKh3wxBzhLc+xF1NtAN8gmwTORzA2KUFnBfij2oU7xNpackww02F6PO3CgBR6NiCkHctEdOOcys+BwwJyAxUcHoOVWFTa6V3cXaMfXfDn9HAjZEjHYSWgTEPSk8GR3hJMDLjhEEbPX9SEZ8OxGpePApvL62JQUVq9TSio2yO9F4A/Y6xX05nv4jpIag8U/a3G6imG4fabVVexXu1kzlVZKgQ+pO9Rfi0JzgO8ik1GynGicPPrWESox9LheNlhrOqvbKAWJ9N6m7F8jP9uiobMUTCR7q0H+DcGKqyJIt0I9H0agW3XYl8e2pCMZ27wynUz8f7e0n2Xe86AHsdKBxqCB54ItoMpqDXMukcmYB1fanzC2BbdRYx/ry/Ddd2CsmncPLZB/jS2Flvo6GJHLnl2ZP4NZ1GXJhgXBN/2sEVktT1h1S9hNtCcXIE6nQ9J+8xCr48QvXyuEgiTVBaNq5neoZ+DuJiOQ0IUMQsvcbP3nbp5bs2aYcOn22xuAFOHpJLJeCXNeqPEyUSjayYIgCmc0aqCQ86Dk6phg9qQrg1aPfDFNVzT3k+Tx5kYkwiigEiOfCkyrq0c0Ew/z75PhpbrEXXE2fHS3F1RZZQTjpVPC5U/lUATXF+oBuLaOcGewir78L+ZzQdmkOowjZqF8hHES0vcD9+f1c0cbBslaa4rq8VHlb4IYeb73p5JcrKgilir9pMQm9f7J2QyEI7bq3o739ldO6a37GCBje2xvgsDuGnEpPqa7D6Ol9X3Wj3X9WVcsVv5pXgULGs7jyQ1OKVsXVBenTmWajxWomAGetLJBAMjB8vSblgI5F7i8UvOJD85AkiJ7Lt6DE9afnGd/s4ayejFa S694ys2q wYEmGKmGEJ5B/usFGxjdXPxpfc9Q+5XWYj1134lf98e73IJktC8Le1kUkOk28YiLamJvdqXe88z5CCD27PmQjCBtSXs/jOjhmPb5LVYaKN1OjNLaxuWt31JyfvRxSZNmSzOu99z3JhSHiSggJMWJ3cF730dFWH0jla4Yk/Ig/aHUUt+j7fQvf5MHKz4Bts1Ugges9esR0EI0SYKb/TPcTVmgU4NZGGmHpkRdUBHYjoi+nMATOpiBSEdFUlcio/8J1eGOcJlX84fJm9I34Rz0kQnCzf1k8i2D0C1Tx3STsfukwdYzfG7YV681YYYrcrtozpeAcfRDMkb0fS1zK4uH8D48PjYNb/QQYIlzd X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- mm/util.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) base-commit: 47ac09b91befbb6a235ab620c32af719f8208399 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