From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out203-205-221-221.mail.qq.com (out203-205-221-221.mail.qq.com [203.205.221.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B629631AF1B for ; Fri, 31 Jul 2026 03:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.221 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785469361; cv=none; b=kNdPfg+pdWbZPob4rm15nVVv0rPSWsN/E2F0reO5vHfsmzP5UqsWo/0B4ME8t/LMOJkLKwr1WSrQn9NkYNNrQg0VcW6hh9X4wl+9FcOt7zArdtKHDpWrpzk7dkPlyM0WUlzKdgaSUWDuURrubdLe+9LH7o9+KB2QYsv9g/3jjh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785469361; c=relaxed/simple; bh=MR8D2Jv9RX8KxGYPyPsyzIO8qRDeSDFwJ4BagEIN4l0=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=M2sS+NU2l6nQCdrcLu4gmmPIODvx923BV+0ocXWNFR7qynnY/QE2Km4rKQgEmmAdDwfW2MBaILbD2jQhDnoRmoEbI5m8Yzfkyu2LKWe6AEEdZHJzqX23BlaueEiYr4AQ0Lb2Mp52Cl6/Vo9VZZ1bFui99E8dIH7ZClRhr/y2GzE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b=G2Zw/aDc; arc=none smtp.client-ip=203.205.221.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="G2Zw/aDc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1785469353; bh=7DyGnTW6xHszUArEM2H3mxuxl8Y8Sg5FCq0hzCIrzNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=G2Zw/aDcH/xHHgBuvBgGQfHbXLPxVbrS+MproHErXmDnkeoxpt/+ksOrMRzVh3P0D Cv5GHyTffy4VCSgkVpiNvAqOVxE11y/g5pvfeA9aKZzbS++NOoP0ohDgXgFp+BD2tw mCYA6b+sz3Cp8/oqyQQv4eqVUA0TR71EbAcVpFWY= Received: from localhost.localdomain ([180.153.160.8]) by newxmesmtplogicsvrszb51-0.qq.com (NewEsmtp) with SMTP id A9F05664; Fri, 31 Jul 2026 11:42:31 +0800 X-QQ-mid: xmsmtpt1785469351t2v64anal Message-ID: X-QQ-XMAILINFO: NC4p7XQIBeahpsOFZyRfInXm1m51IeBT0KqUd63g2Yf4JYNG3+dS9z0Lyin1+D pB47vg1HJONMMuq5hzEEb6JodxPqUUI7fdO/xQGu+q/Ia3Slu5aP0bBNunJSJrY4e9bTxZDq0Unf lw5uGNXDDHeZX0TAGoCmHUkZuisMfncgKmoUiRkpnlqZG6+eS2ep6yzTy11OAcbxZ6+L9GOPN/uS ZSPqnVnOy4zGZNtX/lgreFCHLbKaPKk3aEf0mPJUXIkXsa+sEfo1AOYc14zMCueQhY4b47Dye2DJ 8ljYISheeRdpjsAmXs46U8Bnblm+W+WS5+RrgakrtrGdeOBVjlzVgEQUDlqYi5SG7mRxrEcTABIg hj6tAhxV3q03PqqXP4l+nlvZEM3HliJyDIMqS64V91NUFqVfUPM9nP1aFLnfgU4oR18Bl47g8eUi fecbT2yfCmWHgbCZ5f4ZAFpmq42oD0WY7fac6WNakOCnZQXsyAzdAuip4FkWraqlvk1S5zxj7LMZ m6QVyZLlTr3sxFPYWptnXXyVOOYxRrGfmBqhw0Fcxur19RF2OauyNv9l2Q0eNuDPRai/DMwwmPgO 5J7LU+zCBAX+bKGfw2ubaX7Le40Vv7Mmn+NGLAnCxzJBalMmYCU6LvVQzA/qFQqxjv+eoPt3ctrK ulGH3Sni6g1SLq71Z61Z2IiK874ScC7QA7Hf4xRxYaKaKCk3pkIhda3hLTFNDbJBH1U3sKp5Rp/v 7VdhAcKA8gcyWDudzcaRXQobigoGV0D1K0rVEe0qxvtiLdrQcTDaWg76WXniXBB68RadbaOGmE73 kxNizat12qyaCk6F5BeuB5ZCNzl+0uXnrNp8+eDHHc/DMdmMegwcHzvzkVKJWvIh4AQSzjrjO8Y9 t4ebsHCasiJQBHfJnZI/Gpvr19Cz8NW2vc/hsWmjlUz27VFVjs0ahs//7EeZ+3BWCQFkVH6ojZey KKtySED9CSG8cdOZlehgz3rfHUuYQCQQzBE1Edx41i3VbY3IcI2p0jXKXZ9vAZWED6sca62PDQR5 WMgXL9HaRU9KRRIA/sVql1gDkenr7WEA7kQ7xXp7BiMxfrErC71hk2KMAGeBI= X-QQ-XMRINFO: NI4Ajvh11aEjEMj13RCX7UuhPEoou2bs1g== From: Jianlin Shi To: linux-mm@kvack.org Cc: vbabka@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/page_alloc: only update lowmem_reserve_ratio on sysctl write Date: Fri, 31 Jul 2026 11:42:26 +0800 X-OQ-MSGID: <20260731034227.3036279-1-shijianlin11@foxmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit lowmem_reserve_ratio_sysctl_handler() ignores the return value of proc_dointvec_minmax() and always calls setup_per_zone_lowmem_reserve(), even for read operations. Reading /proc/sys/vm/lowmem_reserve_ratio should not recompute per-zone lowmem_reserve[] and totalreserve_pages. Only do so when the sysctl is written, matching min_free_kbytes and watermark_scale_factor handlers. Also propagate errors from proc_dointvec_minmax() instead of ignoring them. Drop the manual "< 1 -> 0" sanitization loop in the handler and set .extra1 = SYSCTL_ZERO on the ctl_table entry so proc_dointvec_minmax() enforces the minimum on write (suggested by Vlastimil Babka). Compatibility note: Previously a read also sanitized sysctl_lowmem_reserve_ratio[] and called setup_per_zone_lowmem_reserve(), which rewrites each zone's lowmem_reserve[] and recalculates pgdat->totalreserve_pages / totalreserve_pages (visible via /proc/zoneinfo "protection" and used by page allocation fallback and dirty-limit accounting). After this change only a write does that. Documentation describes the meaning of the ratio and the derived protection pages, but does not document any read side-effect. Worst case for odd userspace that treated a read as a refresh of those derived values: lowmem_reserve[] and totalreserve_pages remain at their last written/setup values until the next write of this sysctl, or until another existing updater runs (e.g. adjust_managed_page_count() on managed-page changes, or init/watermark setup paths). Until then, allocation fallback into lower zones and per-node dirtyable memory (node_dirtyable_memory() subtracts pgdat->totalreserve_pages) may not reflect a refresh that such userspace expected from the read alone. Normal readers that only consume the ratio array are unaffected. Changes in v2: - Add .extra1 = SYSCTL_ZERO to the ctl_table entry - Remove the manual sanitization loop (negative writes now return -EINVAL instead of being silently coerced to 0) Link: https://lore.kernel.org/linux-mm/tencent_FFD4F4D728AAE8A8AE0AF277A59854A29A06@qq.com/ Signed-off-by: Jianlin Shi --- mm/page_alloc.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0387d2afd..a7381327d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6683,16 +6683,15 @@ static int sysctl_min_slab_ratio_sysctl_handler(const struct ctl_table *table, i static int lowmem_reserve_ratio_sysctl_handler(const struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos) { - int i; + int rc; - proc_dointvec_minmax(table, write, buffer, length, ppos); + rc = proc_dointvec_minmax(table, write, buffer, length, ppos); + if (rc) + return rc; - for (i = 0; i < MAX_NR_ZONES; i++) { - if (sysctl_lowmem_reserve_ratio[i] < 1) - sysctl_lowmem_reserve_ratio[i] = 0; - } + if (write) + setup_per_zone_lowmem_reserve(); - setup_per_zone_lowmem_reserve(); return 0; } @@ -6791,6 +6790,7 @@ static const struct ctl_table page_alloc_sysctl_table[] = { .maxlen = sizeof(sysctl_lowmem_reserve_ratio), .mode = 0644, .proc_handler = lowmem_reserve_ratio_sysctl_handler, + .extra1 = SYSCTL_ZERO, }, #ifdef CONFIG_NUMA { -- 2.43.0