From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 84C7F36A004 for ; Thu, 29 Jan 2026 22:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769724658; cv=none; b=f6dSWzHWm9Xd342klf0svzFJk4n4lclEmuMqD0m7R+48ZdDjlqxpkpvL2u93NEUl6QRz0nHQJZ3e01FnQY6rhZwaCE9K4GWOWxvvFvWEcNTXAo8HHBI6v5k3dtvACJ4plOhu1kf7s73nV2yuPLcVAwriydaJKdeQI4NaVKq0YAI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769724658; c=relaxed/simple; bh=YX0jpZhn3lacQcVZON93fkUNsO8tpKgjkgTZgwkH2bg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=HguSx3M9s5JaIoYR95Nqt6AoacxTiGHj/y7RUlYmV/KcskZQFum9KWFcI491FdDuA/GJCqnIR8QwmXFVs5KSOlJY3ZMclbrR0YNNWMVY8y9uQl0h7JOjexZmxZwfXC79SzjpweBGXabliMKp8zqfuh5zBvFGdSyGVkU6c4QB4hY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=eia/afL1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="eia/afL1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA526C4CEF7; Thu, 29 Jan 2026 22:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1769724658; bh=YX0jpZhn3lacQcVZON93fkUNsO8tpKgjkgTZgwkH2bg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eia/afL1O9p5K8X864NnvO3UBgag0ixah4pG+Un0OcP0885Pi8j/OzpvAwfcmoob0 00oS4KcK9DYYuLPgkJ24EE6XKmjKG+vgvXb13CF+JoptGvmmh10j80dgEAJSckHlIm NRTQS76tCR53YbMn8WDQMXISZjofWBZlbAOuEsWQ= Date: Thu, 29 Jan 2026 14:10:57 -0800 From: Andrew Morton To: "shengminghu512" Cc: "vbabka" , "surenb" , "mhocko" , "jackmanb" , "hannes" , "ziy" , "inux-mm" , "linux-kernel" , "hu.shengming" , "zhang.run" Subject: Re: [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check Message-Id: <20260129141057.b577100c834c726f01a602b9@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 29 Jan 2026 22:38:14 +0800 "shengminghu512" wrote: > From: Shengming Hu > > alloc_pages_bulk_noprof() only fills NULL slots and already tracks how many > entries are pre-populated via nr_populated. > > The fast watermark check was adding nr_pages unconditionally, which can > overestimate the demand. Use (nr_pages - nr_populated) instead, as an > upper bound on the remaining pages this call can still allocate without > scanning the whole array. Thanks. > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5130,7 +5130,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, > > cond_accept_memory(zone, 0, alloc_flags); > retry_this_zone: > - mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages; > + mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages - nr_populated; > if (zone_watermark_fast(zone, 0, mark, > zonelist_zone_idx(ac.preferred_zoneref), > alloc_flags, gfp)) { So that little optimization hasn't been working for four years?