From nobody Fri Oct 2 01:56:56 2026 Received: from out203-205-221-239.mail.qq.com (out203-205-221-239.mail.qq.com [203.205.221.239]) (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 480553F7867 for ; Thu, 6 Aug 2026 08:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.239 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786004880; cv=none; b=bjQTwVs2UTOvQHdLIyYirwRx52biaKeid6/Sywx3V7UhzyWfhOgknQKRN2XTkcS48Wm5okCMhcVIDHbHSmTBadyVlwqx8oWi+jzD2sC7WTtHmShPkgeBzL+UUcAbKomZgcwlyW2WSeQmidTiH3SRkB6lpnyghvC3CuzXezhVWVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786004880; c=relaxed/simple; bh=JZJSgSEu3MLb0iR6x81g7PBiuH4KutPX36sTEg1VJts=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=jEbN4/LHBwHUGTvcmeDJz/3A2Tv+6uEbbIcnyfX4O41tJbsPdsP/hK23/EPqvnB1ug8fxn/vE5exKB0MG9lbuiawQWcZpKZRXeFSANOt35YXNWn/tV8lxd/amo7whqZ/woyFy3fsguedw6Vgx50aY/LXxeW0clhCGgMh6aOnE10= 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=nKiD0sVT; arc=none smtp.client-ip=203.205.221.239 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="nKiD0sVT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1786004860; bh=E+OtdBdwv6/MFc4NjNIl3j6uDNWCdxI8dJnJUIXFKfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nKiD0sVTT+CECEZtTEkeIpZ/DhGjc0Tft++o/B7F0k1vajhoKVnAvceYbKwrxukNY +RA7rPVNcZPugKxMenospauMOz5GtuFHWfoZ/k5jP57ykpTrg4OGn9CJzbzyPTt1hx 3TZyOqQoXxJbSg6mAc4214CUERuIY13Xt5OAaSz0= Received: from localhost.localdomain ([180.153.160.8]) by newxmesmtplogicsvrsza73-0.qq.com (NewEsmtp) with SMTP id 6E52AE75; Thu, 06 Aug 2026 16:27:37 +0800 X-QQ-mid: xmsmtpt1786004857ton0dzvq5 Message-ID: X-QQ-XMAILINFO: OFArnyxfXusvqWmUHm7xnqL8RhD5NT+vOE+qOy9jAdtH9TEY+dGOrEvZLJHXQm Ko+m9ZDmJ6zK9g0F2c/TZ4/hdm+wUBH2/tFi41bbEoY36eu0U1fwFDFEH1RKGCsOMuZEX6/ETnm9 vLXl8l6QAJc0iuz0b2ZBiMsfp6vmDhHMH+O7yjt0dKoVaFwPnFFyrhVhUHkANcMOmFAAlIeE12/K sxkePuCWyjxMXjqiiR0Hx1PJai37QB9I7tLSVLt/rds+rywS9WP+Uxk971ptmvyrE5dbUI8B/enh 2Bd3eM/VUJ8RDgoJTReBIRgvr4EjmVzIfwqrSVWNeLa+5bfYjpDnGhbltHtoVM7Zg2XV4vdRDpBS LEZEfc80pCHSXAN6FpNvnd+Rv7D5RmKGflNVBpIhi3ORAR/8epDTvmU1128zQXlyDTBBxpPwIlMv q4t+PEJHyxXEjXF6+t1cjTg9M4CFdYE8eS2NxszcRjL/KXaLZbKT1V1svzH1GjLZBP17LHzc38Ns 1lquQJS8EwH+S6p5AY8s0FXgusdP8BsqFINSEw1LR9DdEHV6sd4o++K4E3co+f9NAehG8DoPITI+ HoODs3JqG8qOcPIfule1Av8iiXZldLGiesZGxrYqQ/pw/L2yxK75tQPDCHL5L47XVRUMjMgmutiU RSTtasM+1WbQpfDLsio4sjOCXgpMOBTi3SU7o0+y7ZojHpPdXORPOjvyRlhwZCs01RHHR0SHu152 f9uoFkSaDz+rohCbhxhBplnvkHEO5bysdZ+dxUU8++rTnUk1fCaeC9oRs9brJgqdTVR2U2aiNc5p PWjTAnW2bZhx2w+2lgLwP3HlO8LJnHArX3GHsix1JReY5pHiOb1duCyXDYSY8Kk40OhNhWYV/0I5 11y64AUOnp2kQsDczyeR/WcrYCT/0xtGquaWcu1GlMIGllCsyZl2CHpP0TbSYLJdEkLN+YBmIEGo gy8kwTMZvpHZ8dyg1ffgU5l7R2mgQQkr1HNSBeQ7SSzTfooWDZamRbxXtU+FPCsr8/vKAqSz8zSS p/SHKRtN+EsB4yFHSHz3fQdKBCjDyvlnbNXMQZxU8aPBDr32uB X-QQ-XMRINFO: OD9hHCdaPRBwH5bRRRw8tsiH4UAatJqXfg== 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 v5] mm/page_alloc: only update lowmem_reserve_ratio on sysctl write Date: Thu, 6 Aug 2026 16:27:34 +0800 X-OQ-MSGID: <20260806082734.595622-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 Acked-by: Johannes Weiner Acked-by: Vlastimil Babka (SUSE) --- Changes in v5: - Size temporary ratio[] with ARRAY_SIZE(sysctl_lowmem_reserve_ratio) (Andrew Morton) 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 0387d2afd535..51f35e44132a 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[ARRAY_SIZE(sysctl_lowmem_reserve_ratio)]; + 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