From nobody Fri Oct 2 11:44:19 2026 Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.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 9F95739A054 for ; Sat, 1 Aug 2026 15:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785597218; cv=none; b=sSkpnRIii5psEhqO9NW9CSoS+Vf82Atui8dCnEJz7HxhaZp4KP4onxR7xSJYJzRWaHN59lG4wxN37A2MYIzdKxRydRli4/NbMSJQhs2YlO5gLND1B1PnqgWHZsL6bNomB3eQQ3+P01eR0CY5XAS/E++D0GkRYckABa5FY+1J4Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785597218; c=relaxed/simple; bh=sZWYZKFU+Bgrib6LMOVorg0iYWXGPA1x1aKuej0wzZ4=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=akqy0DhELwSLJj0q/IK4v1FpmvTn3Cn/yVB+QOIzZvE/IBeiRKNgP9pCXah9RTwPvUptowmyhsbKt0A4ZmNsr4XRpf5K3GWZslfgX9cQRIdTDWK+dNMxPgumSb3x5gK8FELLiFW5gVU6wMP2Bds/uIlvZlM3tKvVk1cuSLd1piA= 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=tePQoFKs; arc=none smtp.client-ip=162.62.57.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="tePQoFKs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1785597203; bh=L8KJpPgs1pFmPJSB2oTg3KxAlZCQDx3NADdq1AQIhHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tePQoFKsYJfzp8kh5ZTRYrmdQVRSKyfj54FmTCCdbWc+kZKWiaacMIZeHhRjZO8Nk z2bM5z/Kykn3XGdLVQVMH/XqwweIXb3MbrydBKHbhvFPYLfRh3KRQRmSxqog3FSPz3 AGJ4I//AHZpaTwCexVaWSnMFgIpHu9qLWnQipMNY= Received: from localhost.localdomain ([180.153.160.8]) by newxmesmtplogicsvrsza63-0.qq.com (NewEsmtp) with SMTP id 35496495; Sat, 01 Aug 2026 23:13:20 +0800 X-QQ-mid: xmsmtpt1785597200tvxm2mojy Message-ID: X-QQ-XMAILINFO: NT7uTz3cNku29fmGKhNOjgMH5Yv9qyArDKhTzIxjqvuMZVUnIug0IEOmnI6HLL Xc3DwecFRJeT8HT5mjdrGnB8B/orChHopaUErTbdrv4OxETuSe3usR4MPnYWumrTeD26/VfhqUGj 3k6ZYT/zt/rL/VaUvYLrUjNtbIQTmYfMEmpzgoVLZ/VSxnNVv9SG4ZJhP3Fn1a7xhB+rSrMHZUVT YL/OaNroemiUA9gx7MCt6NvGlpJMDC7f9NUMSuYrVDenIuy5HKSLbGMshLznrXfAlfTCpgqWYiSZ T2WZA+w1A9MznBUImMcv0HhmRDzArE8Px0Lp6zZCtVpFsNZAhrtrl/8HmDB6pPXg4N15sUpyqA/0 K1NeYv3LBwAefjS+GuwO4NygfFMo6EDg2t8McAXMb3ILFsBMjZI2D2jnsBmLX2nrvRZtK7mCTr3V tPyDFk2GuMty8sEXxXlxPgmGz6rVcusLtWpo4cFL9W+YpfYXDCCW9SGE8tNp2qEgWj6/DTXLHFk9 ykUb8Zv26xXjvnp1lB/wvFfL4nvBeML3qmPaBkFFGT9TmfqOyMo0vJgDA4pI5/n2h990Z6hvr83U fGkZnmN9FMwlhpLLD+EFSC8OHG/nS6tplp4wh3mIbcu+vw/fwli7PD2/CV6JgS6MciUABr5ogD/9 Oaz3/RjDNVTyNvdbsryxSCNExsF34H+KRp2dcIqEsHjwb3Ol5jeLbEYzEqy+k9faOdtAX6fFbA2G ps/665GQdFRYLhJ+nwW7780qlTNoaqTdmHyzmTX5yS28pTKK5CoUzBZ3+qO+Y9zdLDEwVrvWmoxU Plxbl/Alq/GbhUeE32/yVjT3vQDsvXqPIY7kmOIkgL6FE2bE5d5PNvdF2t7fQFgxH+TrisAcFhcu iW/67jL4v46t6bBzNtBaTk1COfKBlNacScZ5Wvh3ylt7EAeS+LrBrRlcRXUjevl5t2LM12/nJ3AI 0M/sFeTelICiUww8wrt8d1uD86mjtI+hy7+blVUIzPxbcoYTsqBTHipjLvt7QYjWhAKVGlHz5fgZ mhMaRi4TDdGVoHjwILe56AyG05fOJzCzDr1z2sIOlYWrIcqieY 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 v3] mm/page_alloc: only update lowmem_reserve_ratio on sysctl write Date: Sat, 1 Aug 2026 23:11:25 +0800 X-OQ-MSGID: <20260801151125.50603-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 two 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. Reading /proc/sys/vm/lowmem_reserve_ratio should not recompute derived lowmem_reserve[] and totalreserve_pages when the inputs did not change, matching min_free_kbytes and watermark_scale_factor handlers. 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/ Reviewed-by: Vlastimil Babka (SUSE) Acked-by: Johannes Weiner Signed-off-by: Jianlin Shi --- Changes in v3: - Rewrite commit log to focus on the two tangible fixes as suggested by Johannes Weiner. - Code remains unchanged versus v2; retain previously obtained tags. 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 | 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(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; + int rc; =20 - proc_dointvec_minmax(table, write, buffer, length, ppos); + rc =3D proc_dointvec_minmax(table, write, buffer, length, ppos); + if (rc) + return rc; =20 - for (i =3D 0; i < MAX_NR_ZONES; i++) { - if (sysctl_lowmem_reserve_ratio[i] < 1) - sysctl_lowmem_reserve_ratio[i] =3D 0; - } + if (write) + setup_per_zone_lowmem_reserve(); =20 - setup_per_zone_lowmem_reserve(); return 0; } =20 @@ -6791,6 +6790,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