From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 609A73BB4A for ; Thu, 6 Aug 2026 13:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786024222; cv=none; b=s7ZFuNOFGFkIUierB46DQODKeN7ybgMeZOtsAh6Z4s36cJuSuu27znPXAXkhm+foplzbiw9/jID8sup7l8OxyacEbSQzZ2jxnzteM2C7VAlrDrVsKTh/w9P2SKT86F7hpkXWGkuzf4Jx+D+I2T/WaEcfis90pjzWoHQFjS/B8fQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786024222; c=relaxed/simple; bh=GLltClXSWckXhLVbLM4P/8QXPLhoG1rg5PnLcWv3p+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pj4dsh/FbyEh1bc7Z8MnL9vcU4V92J6XPY2eIggl+Wcgm16Rh6KGzRAyHN8ZfGBplwINJsMkSJ/iYOoDZ0m7DiupJyzW0JR1jfOoh8TWjzYPxvKOI3o63wuagLfEaFAK2WvPB7rPk56V7dEzYc60vBp7AAheBNMneKg5XWNdAH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=anqSsdW1; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="anqSsdW1" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-92ed19f4d60so64255885a.0 for ; Thu, 06 Aug 2026 06:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1786024218; x=1786629018; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ejTfR18inMal9BF+WY2i6i5Eh6izHN7yhpp6phMOSsU=; b=anqSsdW1ik+tKGSSlut+KCYcmct1sAJiu7lO0fARRvXsuPvzNy9TCEwLQlvPhNOFqm b9uzwPmXBT3GG1k9N+T+OvnWLgrZ9pF8R6PYeX/CsBo4wg89uWF9sL8SVvu2Y0SmQHNi +W2pQsr5Wa1QTwHWWFzaEH1Gk7eqdzFLjeReKn29Aud6F/KbOlgd8CvFiFO8CRwsDCYi aVib+SGfCBVhD5oJeHZTFuQHYuYLSNEdEku8d0GOWpNhj9JJzzCxYYq1/abuer7OCXBD RVgTaarhkE4C5MPn1x/S7NqeVjTLNOxziHkN2yPieYPz9QEn+YDVDmv6h4HphINOAKHA EttQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786024218; x=1786629018; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ejTfR18inMal9BF+WY2i6i5Eh6izHN7yhpp6phMOSsU=; b=ddFzwJgpk+qGg5NLGpeQzDtDC1Im3Dnxxfaxd8msnU/9hLwRbALh87iZ/T6ojA/Lwi KXFTcr6G/Ge/yO8rUZDg0Vc95W3xb090zIIzlm0k4dSXvWKbXfYanJeQOHcF+q6D+tuM tizAhV+y4QlANetj6SQJZBgteUSSFQFbZ968a+k4PDcGofqwk14FT2R1mZbs2mtnrOkC JciflviWgvWiejCwc9ukdiZ0QZqU6TRIXvzf6929HmoLxY9OprKVi2WaOy67Q6C5ajn4 2DXnwNCw5+MK/HfI58jLNXsGa1lmh+Rvr6Oy7SEhsHv5uKrOiF8wHHHimKNeQ0+BPCjQ Gtpw== X-Forwarded-Encrypted: i=1; AHgh+Rqqn5UfhD8Iogef4q9DpkDcBOpC6ITWrx3RCHHce1rloNtpVGdHJAjRqKczrVmbYrooRNnBG+2X/DPxeNw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3EgH92jkhxTDQXUfrfAvG2FFfs6tCZc4fgvv6HXSsOYvuutZf xX5gOewjcac7TvcptUvl2ptGSNDD6/3hrstYZT5Is6q2Fw8KHnkCy/om4dwE/SB09Lo= X-Gm-Gg: AR+sD13/0uxLwiIrkf8CxX3Kq10sQarzfSN3CEJOFoamuEDUXE5MyY3ls9Cs2RGiLaf 5lrF0o31/GGHG/+x5ydX2pjTC/NlAJQAICzofzUtt0ffmOl0puxcwdtYHDtcPyjCtOjjaSYhzO5 rrtjBr0UH6s4R56mWbe0Ijs6zsMPqsjCZ24ASJoot2T5eFfowSWzw0umBqbthu9COjtAaeqY+mC GC1LEM3dS3Fmes3r8kDeCJ3gO0xFLZMnW5xNiQPVi/zUndqCWIL0WarqI/WXMAs16plZZjvglRG 4oQhuU5O8QVVLAsjjF3wIOp1ZokWdgwqLtpBdsGwUhm3PjI29niUSMbRP72/hDOGO8ZXAla0O3P TFuevUmmQo4OxSrZI8FRMChnHonvKYJ6E68v+r60EE/lmn7ocsl7gsHBuFoZgrczbLQPLS3aYG4 DZ6rz9ilcuTHXlGt3vLX+34OOcz8mHriohiaDc7xupEdAQx4O0aOuxAYq8js3cBfqadTXBvrk= X-Received: by 2002:a05:620a:450e:b0:934:ac0a:8bb1 with SMTP id af79cd13be357-9365de9c3b0mr432348085a.8.1786024217836; Thu, 06 Aug 2026 06:50:17 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9364a4260c8sm409474285a.11.2026.08.06.06.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 06:50:17 -0700 (PDT) Date: Thu, 6 Aug 2026 09:50:16 -0400 From: Johannes Weiner To: Jianlin Shi Cc: linux-mm@kvack.org, akpm@linux-foundation.org, vbabka@kernel.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, ziy@nvidia.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] mm/page_alloc: only update lowmem_reserve_ratio on sysctl write Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Aug 06, 2026 at 04:27:34PM +0800, Jianlin Shi wrote: > 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 = > 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_FFD4F4D728AAE8A8AE0AF277A59854A29A06@qq.com/ > > Signed-off-by: Jianlin Shi > --- > 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 = SYSCTL_ZERO to ctl_table entry > - Remove manual sanitization loop; negative writes now return -EINVAL > > v1: https://lore.kernel.org/linux-mm/tencent_FFD4F4D728AAE8A8AE0AF277A59854A29A06@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 > > /* > * 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(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; > + struct ctl_table tmp = *table; > + int ratio[ARRAY_SIZE(sysctl_lowmem_reserve_ratio)]; > + int rc; > > - proc_dointvec_minmax(table, write, buffer, length, ppos); > + if (!write) > + return proc_dointvec_minmax(table, write, buffer, length, ppos); > > - for (i = 0; i < MAX_NR_ZONES; i++) { > - if (sysctl_lowmem_reserve_ratio[i] < 1) > - sysctl_lowmem_reserve_ratio[i] = 0; > - } This could use a comment. How about: /* * proc_dointvec_max() works incrementally. Use a buffer * and only set the values if all of them parse cleanly. */ > + memcpy(ratio, sysctl_lowmem_reserve_ratio, sizeof(ratio)); > + tmp.data = ratio; > > + rc = 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(); But otherwise, looks good to me now. Acked-by: Johannes Weiner