From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E63E606A31E for ; Thu, 29 Oct 2026 03:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=JwHCiaU6 Received: by kanga.kvack.org (Postfix) id 890D56B05B1; Wed, 28 Oct 2026 23:39:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81A436B05B2; Wed, 28 Oct 2026 23:39:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E26B6B05B3; Wed, 28 Oct 2026 23:39:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4ADAB6B05B1 for ; Wed, 28 Oct 2026 23:39:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CB1A11A0301 for ; Thu, 29 Oct 2026 03:39:52 +0000 (UTC) X-FDA: 85374259824.01.1198AE7 Received: from mta0.migadu.com (out-55.mta0.migadu.com [91.218.175.55]) by imf05.hostedemail.com (Postfix) with ESMTP id B1FCD100006 for ; Thu, 29 Oct 2026 03:39:50 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JwHCiaU6; spf=pass (imf05.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.55 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1793245191; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nHYJzejo29azPzDNOxZ+tmpvvDu3XTTv89JLTyFVqd4=; b=VuzJpdtI6PAQVf9Jl14b3jXDG+nSbzz04eXeBmrOxxoiq31/4ZKTGic6M5BgW2S+5EII5K iZaON+RrR9FdDZKDKZKLbmYr4hmaM9OVVz82PQ6XFiA2BpBPULlD9djLILGR+GK2NU7pUv +8MBDfxhCMUEPSl2UgDvnHJoovB+hgY= ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1793245191; b=0P2nyXYJA1KMS831+v/fh/SccOTLDHocZrWcfFD/kaYWqDGeqEGFqCPGpfcWWDGmprdX4v 1Iix9eydyx2g1H18H97DDvlXn/dB9Byay42Lz8nF90yDF4m4mPQGtbK9OmkuLzW+O7IZLm EK1arVt9paLpFWvBcAih+Mq63ad0NPQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JwHCiaU6; spf=pass (imf05.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.55 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=R50k7qXAG33bbhagggBhqvchCPQ52saBCXt3awMCb6U=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793245189; v=1; x=1793849989; b=JwHCiaU6wNlgkZwersY6AMgWtViVtjskMcecd/6+Od2qPv/mWGKr7rlSGPwoiVQjWtSEquTl jz8ubRhsB/Dyc/RqHacrPomgc4WK1uts7m7DL8ZDejrhXjpDsM5Zh945kHdyhP94x2zIdgWwum6 47kzoRxtALGbiybFTOALoFVw= X-Envelope-To: linux-mm@kvack.org Received: by mta12.migadu.com with ESMTPS id 5ac0218b5b613cc1; Thu, 29 Oct 2026 03:39:48 +0000 X-Mizu-Trace-ID: 5ac0218b5b613cc1 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Archived-By: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.100.1.1.12\)) Subject: Re: [PATCH 02/15] mm/hugetlb: compare against persistent count when freeing lowmem folios From: Muchun Song In-Reply-To: <20261028-fixes_hugetlb-v1-2-a0a033db180f@kernel.org> Date: Thu, 29 Oct 2026 11:39:27 +0800 Cc: Oscar Salvador , Naoya Horiguchi , Andrew Morton , Mel Gorman , Andy Whitcroft , Miaohe Lin , Michal Hocko , Rik van Riel , Hugh Dickins , Baolin Wang , Vivek Kasireddy , Dave Airlie , Jason Gunthorpe , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Jonathan Corbet , Shuah Khan , Randy Dunlap , Peter Xu , Breno Leitao , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Gerd Hoffmann , linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, stable@kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <68EFA1E5-4898-4278-8718-06B1A010DFFD@linux.dev> References: <20261028-fixes_hugetlb-v1-0-a0a033db180f@kernel.org> <20261028-fixes_hugetlb-v1-2-a0a033db180f@kernel.org> To: "David Hildenbrand (Arm)" X-Mailer: Apple Mail (2.3901.100.1.1.12) X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B1FCD100006 X-Stat-Signature: 98z6zb6iybqaowz5n9xysa5sh4ad5dsz X-Rspam-User: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_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RUBJ4hOG80CF63WqZstigxIh gl38J4If +BfTdnezDxErHVMHcgVtY81OLiCRtTdTgK36KJsypG2f5bXWchQRae8vTkKsqXauZCkmpFFIZw6CzRnEOX19WR1DXsJo5yIqq+y7bcp2Yq0lAo2lF+xNqsV+J/KRlO3IXkngjPmXa9iLG3V+7pUFgIp8b6rr2VMslmNWV7J4CIvy3bDgJqIeGwa6WBDuD0GDOjTq4spwJbtqcube521R6vGcKrgHsWoXfj1ypYFeeiK5zwyVCYklDCfqvcoyw4mNbF5XAfBfEumgQK9NKQGGXzT9M0qRgEaJO7wdQgd9XlOnS0TMMU6IxNbPz+g07QCVOLMlR4/98IXCoGEuLyxGQl8Qq4zsPi/RWdbDfb6CAGHuYI90= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > On Oct 29, 2026, at 04:13, David Hildenbrand (Arm) = wrote: >=20 > try_to_free_low() gets a target number of persistent folios, but > compares it with "nr_huge_pages", which includes surplus folios. As a > result, it can free lowmem folios below that target. >=20 > For example, with two persistent folios and one surplus folio, a = target > of two can still end up freeing one persistent folio. >=20 > Compare against persistent_huge_pages() instead. Convert the macro to = a > helper function and place it before try_to_free_low(). >=20 > Fixes: 7893d1d505d5 ("hugetlb: Try to grow hugetlb pool for = MAP_PRIVATE mappings") > Cc: stable@kernel.org > Signed-off-by: David Hildenbrand (Arm) Acked-by: Muchun Song One nit bellow. > --- > mm/hugetlb.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) >=20 > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index da5d04edf7c1..3a94ea1c9457 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1335,6 +1335,11 @@ static unsigned long = available_huge_pages(struct hstate *h) > return h->free_huge_pages - h->resv_huge_pages; > } >=20 > +static unsigned long persistent_huge_pages(struct hstate *h) Better to make *h const? Thanks. > +{ > + return h->nr_huge_pages - h->surplus_huge_pages; > +} > + > static struct folio *dequeue_hugetlb_folio(struct hstate *h, gfp_t = gfp_mask, > struct mempolicy_interpreted = *mpoli) > { > @@ -3719,7 +3724,7 @@ static void try_to_free_low(struct hstate *h, = unsigned long count, > struct folio *folio, *next; > struct list_head *freel =3D &h->hugepage_freelists[i]; > list_for_each_entry_safe(folio, next, freel, lru) { > - if (count >=3D h->nr_huge_pages) > + if (count >=3D persistent_huge_pages(h)) > goto out; > if (folio_test_highmem(folio)) > continue; > @@ -3773,7 +3778,6 @@ static int adjust_pool_surplus(struct hstate *h, = nodemask_t *nodes_allowed, > return 1; > } >=20 > -#define persistent_huge_pages(h) (h->nr_huge_pages - = h->surplus_huge_pages) > static int set_max_huge_pages(struct hstate *h, unsigned long count, = int nid, > nodemask_t *nodes_allowed) > { >=20 > --=20 > 2.43.0 >=20