From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793624211; b=FqfE5YhV5IxC/74WwdsDomEbftVSpa1XrQdsCBOJbYhrbty8/6at+9u1M7mZrtxYDuhG 0G2C3xQJQB+Bge/UnHRTD2sJy67aOZGB000FnghZqX8V4Fn39Cgy7470zwRHZmzd3qsPk 0TQ7Fdc/s01EB3TB4NUK84Pikw0nNwlCemEuzniWjWyytkVnQC853qsDRzZZLDQdtsDMZ 0FZ+3bZMtAcBRsfqa6UNwUYpH7jzZzb0S0Vlq3H9qbAPEvpoK1+jnN16n4kwhRmcLiZHY ozFWu9kiQkjtzf+1nVtibY9Gyay2LVLVNhMk5Z1vcQJ8f21PYA6Ty54i27W0KICMOtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793624211; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=blL8YXc+drVTz8krqBB5UB1MrPCv3ruMb4bo9ij/yX8=; b=sZIPs7k5TX/sbJfMUo7zktqSd9OusqxJOXnG8HFcq+J3S2AsAbaH8jTkbP8XflQkbN3E shmJyGsebfBqBaSe5bQrg41rw9bdIOOczumvHi44pBvTtdlXDh4pOPaTgSCLiW+bWPUlU x57Q69oSbN3hBJ1m/7Zv4D+NzbAuK+NaA8J3totvMqajpm0nXHyQ+MOEgL0VZ84l+ywbK vM7tJG0329mX2HpenvHTTBmb2eik7evBZwDjnW7iI7trhV9MOpAjc3k1F3qRPjf9FIPIT Gtlb8aANjDQx1H+AF6XZ/jZKndXyPhseRJmh/dNNIcj39xa8/cEkU+8/yLXEt8dJdzw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=irnEG9J2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3FB8606A32C; Mon, 2 Nov 2026 12:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=irnEG9J2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D58C1F00A1B; Mon, 2 Nov 2026 12:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793624210; bh=blL8YXc+drVTz8krqBB5UB1MrPCv3ruMb4bo9ij/yX8=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=irnEG9J2fS0STJK2Hxj5gTVa481M+mWppQY4mrkdog3E0PEnjFBG4xB6z/22UrzGK pb3izZ4bzSiD8hi/MXvOud4UIGcCNN9fTVaBBuDMNwIqIG7U+0JJnio/4QQwvu74rZ wga0hL5FXQappjSIPyWKosl1EPA7PBD2ixWdyIFOzGo/P1qo/N47zNgfB5dL3N+BYl jKDO9GlLb9kJDLfT/Smrism3UeWT/3M8s2IG/ITMWlNioda+S142G1d6Sa9D3C6vBY swRcYPc6lAJCGNP4p8lRIm+6KkLqM1ZwBKnimhBYVQbkR7uF5J1CfTNOv9qaUVKXAJ gSDT467oYpa4g== Message-ID: Date: Mon, 2 Nov 2026 13:56:40 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 04/15] mm/hugetlb: account temporary folios separately To: Muchun Song , 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 Cc: 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, Josef Bacik References: <20261028-fixes_hugetlb-v1-0-a0a033db180f@kernel.org> <20261028-fixes_hugetlb-v1-4-a0a033db180f@kernel.org> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZY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zzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <20261028-fixes_hugetlb-v1-4-a0a033db180f@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/28/26 21:13, David Hildenbrand (Arm) wrote: > Hugetlb migration might have to allocate a temporary folio through > alloc_migrate_hugetlb_folio(). Such folios are currently accounted in > "nr_huge_pages" but not in "surplus_huge_pages". persistent_huge_pages() > can mistake them as persistent huge pages, as it merely calculates the > difference. > > If set_max_huge_pages() shrinks the pool at the wrong time, it will turn > hugetlb folios into surplus folios until persistent_huge_pages() returns > the desired number. > > After the migration (successful or unsuccessful) either the new (temporary) > folio or the old folio gets freed: this will reduce "nr_huge_pages" but > not "surplus_huge_pages", to undo what was done when allocating a > temporary folio. > > This can result in having more surplus folios than actually allocated > folios: > > HugePages_Total: 0 > HugePages_Surp: 1 > > From then on persistent_huge_pages() returns garbage. > > To fix it, add internal temporary counters and subtract them when > calculating persistent pool sizes. Update persistent_huge_pages() and add > persistent_huge_pages_node() to make the code easier to read. > > Count migration targets and rejected surplus allocations as temporary. > Transfer the per-node temporary count along with the temporary flag on > migration, such that folio freeing will always do the right thing. > > Take care of calling account_new_hugetlb_folio() only after setting the > folios to be temporary. > > For now, keep temporary folios in nr_huge_pages, so HugePages_Total and > Hugetlb continue to include them and overcommit accounting remains > unchanged. The new temporary counters are internal for now and are not > exported to userspace. > > Fixes: ab5ac90aecf5 ("mm, hugetlb: do not rely on overcommit limit during migration") > Cc: stable@kernel.org > Reported-by: Josef Bacik > Signed-off-by: David Hildenbrand (Arm) > --- > include/linux/hugetlb.h | 3 +++ > mm/hugetlb.c | 65 +++++++++++++++++++++++++++++-------------------- > 2 files changed, 42 insertions(+), 26 deletions(-) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index 5029c7241863..d49cb15d13e6 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -701,6 +701,8 @@ struct hstate { > unsigned long free_huge_pages; > unsigned long resv_huge_pages; > unsigned long surplus_huge_pages; > + /* Included in nr_huge_pages; not exported separately to userspace. */ > + unsigned long temporary_huge_pages; > unsigned long nr_overcommit_huge_pages; > struct list_head hugepage_activelist; > struct list_head hugepage_freelists[MAX_NUMNODES]; > @@ -708,6 +710,7 @@ struct hstate { > unsigned int nr_huge_pages_node[MAX_NUMNODES]; > unsigned int free_huge_pages_node[MAX_NUMNODES]; > unsigned int surplus_huge_pages_node[MAX_NUMNODES]; > + unsigned int temporary_huge_pages_node[MAX_NUMNODES]; > char name[HSTATE_NAME_LEN]; > }; > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index a78b2487c20c..110a5c2d9e50 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -115,7 +115,7 @@ early_param(str, func##args) > > /* > * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages, > - * free_huge_pages, and surplus_huge_pages. > + * free_huge_pages, surplus_huge_pages, and temporary_huge_pages. > */ > __cacheline_aligned_in_smp DEFINE_SPINLOCK(hugetlb_lock); > > @@ -1337,7 +1337,13 @@ static unsigned long available_huge_pages(struct hstate *h) > > static unsigned long persistent_huge_pages(struct hstate *h) > { > - return h->nr_huge_pages - h->surplus_huge_pages; > + return h->nr_huge_pages - h->surplus_huge_pages - h->temporary_huge_pages; > +} > + > +static unsigned long persistent_huge_pages_node(struct hstate *h, int nid) > +{ > + return h->nr_huge_pages_node[nid] - h->surplus_huge_pages_node[nid] - > + h->temporary_huge_pages_node[nid]; > } I'll also use const pointer here. -- Cheers, David