From nobody Fri Oct 2 10:08:52 2026 Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.49]) (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 83E573BBA1D for ; Sun, 2 Aug 2026 14:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=43.163.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785682713; cv=none; b=o1g0y5B+FkBBIDsOxMaljF7j+8HyElRrxvqeeD53dsC6of04JDJqT6Vbyl9XcgZNSa89kPYGHP+fUf15NyUhZvfSAqVVHfx68+MSu6Rz3bg2xvX2X9k7SZRXWH+1UHHpyRpO4CvCbXhj7A16kfE5pX3URIxPUvtHHpwfk8RhH0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785682713; c=relaxed/simple; bh=0fBgNk7RY9eW7GMNjuK3QVJMIzXqfAk3kh4IRyFKBfk=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=ZIBlFwb0OOcWww+zy+9XyyRP/HCSmZDEHb52dd/+4qeYXCM0dpD2ytSALTvBFhE3E3vDPwdWsx0lX4YUk/ELM1iFx3ARsDM5vqH2OeaF5DlqEGh0ikFjy3egHEV1BrSWIA5B/JKK6SLXm6PVKeJAXfDAbk5Zt/bBoEEHBiMc1Lg= 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=d1KOKBJb; arc=none smtp.client-ip=43.163.128.49 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="d1KOKBJb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1785682700; bh=+MqEBL3My6pzXchmMKapwn70BV5PXSqCNR2sBzFd4dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d1KOKBJbDElpOpmwxSMhnSVHrTdYJjv8etqoRp9va6s0l12SUGqR8zqPJFUpLge/b J2VBR/ISBVsQmq8rx8c00VE0czjWTs4SaoAvRFW7eqMto64jMi7dMLC5Wi+kirknEx TS7yBOOjDClodobQ0S6rbjqOkX3APePRr5qsgBNw= Received: from localhost.localdomain ([180.153.160.8]) by newxmesmtplogicsvrsza63-0.qq.com (NewEsmtp) with SMTP id E480182F; Sun, 02 Aug 2026 22:57:08 +0800 X-QQ-mid: xmsmtpt1785682628t0xgiphrl Message-ID: X-QQ-XMAILINFO: MZtEYADUG4Ag1wOFoiyyQzdTBXQBZ4sivjcfqzojsikiLzeK9s8IFIa+eBKFjh td1yfGy/QuTThCWIE/PMAkLbxrvrNeD4RzLvC6jhzAViIWzBFJcuXNoPkhzECd1bmir9hiPHwxLq VXgaMt+3YPbpv8xsqkVdIBTvtK7QLliQLbZ/CwCP1/TRfbagUCY9Jrm4sBN70+hWiU9kWnefZqNJ F7K2Rrk9uTtUObOEVLYVVpaTtT+9wM+Q2/aMGZtlHyLV4mVoBnthVDVwUzrtwfjci+s6vrG4xY1D gUE2c3Zb2n2HtqK+N/L1P6FWBB0FKOsy3Xxj8QM0BzVzvNBQBeNOUDO9LxKJnDz90KtTXRzIL1mw CM3swJ2G6CIQGGWjuqrfG+3ABmC8Am5kr7jyWt5fvATX3WQtwhLl+uApaVjuA6ay8fSbI2B30yVP GvzM6vaxMtGLvXZCwG9RgL/2pZ612qoPeOEiHwANKQdS9vQPoS+bv+Mr821zQROm0gy8daFurWwB YNL5N88gPWnYAoOnZzoPoDRxMi762aBu86SrvEGrNPS/vAFbrci2XS3iZDVWL98vme4IaoCeGl5z mHMUi7eYQXY7xI339q7FKE5kU1JdEv8f+VQZ6+le/Wyakv+wdtlodvWgePtFQhkYHvHqy+rTEdqG v8zYHWyLwPADtO3YM3ozTLI8IWvWkOm39KIrwuUYW4H7LgE5piE/GQMtOKifsa8YrELg7Dfi9Yam EHiT3l8cVZ4EOGFZUpdCHpBkoBsm6BrMmdTo9kl7q1mVWmwIooM1P+upayGFFpYpKd/Q5/azd6lw yqLLgu74gT0FaezBMocYniunoOr0FnzMZAvx4nVp21/VUWZK1p3sSB5y+hMkuQjRo+XwxS/OWpgW tJLlSauPtvUDvHgX4g+dZPO7eUIqfXC8yBU8MRAtkgvSVPB1qLFJwRU4o6gyVy6ugNSsAO8JAgYr 6yYA7Dnv8G0kG4Lu1LqoGh1y7SOqsHFDWJJPIsYnhlqWjv0aSHFLbTALt5Y9Ky+lq/szcPlHfLuB V0kWEQ9///fQADixY7ENg7ZaFRw5QKRSG7rxj3wVUz78LindtXsfCdlTBqUGU= X-QQ-XMRINFO: MSVp+SPm3vtSI1QTLgDHQqIV1w2oNKDqfg== From: Jianlin Shi To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, vbabka@kernel.org, hannes@cmpxchg.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, ziy@nvidia.com, linux-kernel@vger.kernel.org Subject: [PATCH v4] mm/page_alloc: only update lowmem_reserve_ratio on sysctl write Date: Sun, 2 Aug 2026 22:57:07 +0800 X-OQ-MSGID: <20260802145708.1727189-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Fix three issues: 1. Propagate errors from proc_dointvec_minmax() instead of always returning success. For example, writing non-integer garbage to the sysctl now returns an error instead of silently succeeding with unchanged values. 2. Only call setup_per_zone_lowmem_reserve() when the sysctl is actually written, matching the write-only refresh pattern of min_free_kbytes and watermark_scale_factor handlers. 3. On write, parse into a temporary ratio[] array and only copy into sysctl_lowmem_reserve_ratio[] and refresh derived state after the full vector is validated. This avoids leaving the ratio array partially updated while skipping setup when proc_dointvec_minmax() returns an error on a later element (suggested by Andrew Morton). Drop the manual "< 1 -> 0" sanitization loop and set .extra1 =3D SYSCTL_ZERO on the ctl_table entry so proc_dointvec_minmax() enforces the minimum on write; negative values now return -EINVAL instead of being silently coerced to 0 (suggested by Vlastimil Babka). Link: https://lore.kernel.org/linux-mm/tencent_FFD4F4D728AAE8A8AE0AF277A598= 54A29A06@qq.com/ Signed-off-by: Jianlin Shi --- Changes in v4: - Parse writes into a temporary ratio[] array; commit and setup only on full success (Andrew Morton) - Update handler comment: proc_dointvec_minmax() and write-only setup Changes in v3: - Rewrite commit log to focus on the two tangible fixes as suggested by Johannes Weiner. Changes in v2: - Add .extra1 =3D SYSCTL_ZERO to ctl_table entry - Remove manual sanitization loop; negative writes now return -EINVAL v1: https://lore.kernel.org/linux-mm/tencent_FFD4F4D728AAE8A8AE0AF277A59854= A29A06@qq.com/ mm/page_alloc.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0387d2afd..13fabb062 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6673,8 +6673,8 @@ static int sysctl_min_slab_ratio_sysctl_handler(const= struct ctl_table *table, i =20 /* * lowmem_reserve_ratio_sysctl_handler - just a wrapper around - * proc_dointvec() so that we can call setup_per_zone_lowmem_reserve() - * whenever sysctl_lowmem_reserve_ratio changes. + * proc_dointvec_minmax() so that we can call + * setup_per_zone_lowmem_reserve() when the sysctl is written. * * The reserve ratio obviously has absolutely no relation with the * minimum watermarks. The lowmem reserve ratio can only make sense @@ -6683,16 +6683,23 @@ static int sysctl_min_slab_ratio_sysctl_handler(con= st struct ctl_table *table, i static int lowmem_reserve_ratio_sysctl_handler(const struct ctl_table *tab= le, int write, void *buffer, size_t *length, loff_t *ppos) { - int i; + struct ctl_table tmp =3D *table; + int ratio[MAX_NR_ZONES]; + int rc; =20 - proc_dointvec_minmax(table, write, buffer, length, ppos); + if (!write) + return proc_dointvec_minmax(table, write, buffer, length, ppos); =20 - for (i =3D 0; i < MAX_NR_ZONES; i++) { - if (sysctl_lowmem_reserve_ratio[i] < 1) - sysctl_lowmem_reserve_ratio[i] =3D 0; - } + memcpy(ratio, sysctl_lowmem_reserve_ratio, sizeof(ratio)); + tmp.data =3D ratio; =20 + rc =3D proc_dointvec_minmax(&tmp, write, buffer, length, ppos); + if (rc) + return rc; + + memcpy(sysctl_lowmem_reserve_ratio, ratio, sizeof(ratio)); setup_per_zone_lowmem_reserve(); + return 0; } =20 @@ -6791,6 +6798,7 @@ static const struct ctl_table page_alloc_sysctl_table= [] =3D { .maxlen =3D sizeof(sysctl_lowmem_reserve_ratio), .mode =3D 0644, .proc_handler =3D lowmem_reserve_ratio_sysctl_handler, + .extra1 =3D SYSCTL_ZERO, }, #ifdef CONFIG_NUMA { --=20 2.43.0