From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793245193; b=Y+LFY23+9cUHNtDIBB3dR5hdylDEWHgx+KfJQf301SyPLPr7ke7dmz8wWRD5RUBINuha E5ddASDjk3ump9NLLXNd7fkuv8rs3eMsShIrmIKS26DTYBC8UZw8XJeqlgvtkqvijdM5U 7Q8xWE5c2AlxNUWRIV3zOocfqc39FEF4cTaykmGkhxwir7rGmvBrmWwOB4uBHHK4u8Q5J u1DyiFAwb+gKbrG2cW1ru466xqNpVGqcssYs3LlGbtvBXQqcrQcNT5THXtNDvBPHIA4ny DwFz9miU92kgjirdCoLTTrNbXqXDZuwfoml6oZYYTm6SYeE7hQgyaDS/zhcmfox0PeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793245193; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=nHYJzejo29azPzDNOxZ+tmpvvDu3XTTv89JLTyFVqd4=; b=pMJwPMhQLTWxOHJ49lLDPCfJaG5oaHlKLwesRIL4ILDNjEBEkwo9v9RSMwZTXBLzo2fO qvjS/NftuJQKt1CmpnDRuRODcN082Dejai1QfpN2pl0RjNnH9kop88BgIsyIrpJhGSiTm wtKqLfLxRXkuYKqR4uNqJW90vXQRwax3svJbPeYL4xcIUMIjbYoD+rpG+WE85ipqeLx0f rxtyL3Wvv0h6mZcUJSt/ShtYkN630F2+gwmSdLx/kM9yKkQ0oD++3akrkT1gqeE2gzmsT Chm2mbgZ3AxJkktft8yU0EKQVoG9flHitexRmugrX97TW+EIHZj83N2r+pPjX9EPZrw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=JwHCiaU6; arc=none smtp.remote-ip=91.218.175.53 Received: from mta0.migadu.com (out-53.mta0.migadu.com [91.218.175.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D836606A321 for ; Thu, 29 Oct 2026 03:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7D836606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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 X-Envelope-To: linux-kernel@vger.kernel.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-kernel@vger.kernel.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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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) > 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