[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <7BD81F46-74A0-4991-8B32-67E5DBC682B3@linux.dev>
Date: Thu, 29 Jan 2026 11:04:53 +0800
From: Muchun Song <muchun.song@...ux.dev>
To: Kiryl Shutsemau <kas@...nel.org>
Cc: Oscar Salvador <osalvador@...e.de>,
Mike Rapoport <rppt@...nel.org>,
Vlastimil Babka <vbabka@...e.cz>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Zi Yan <ziy@...dia.com>,
Baoquan He <bhe@...hat.com>,
Michal Hocko <mhocko@...e.com>,
Johannes Weiner <hannes@...xchg.org>,
Jonathan Corbet <corbet@....net>,
kernel-team@...a.com,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org,
Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Usama Arif <usamaarif642@...il.com>,
Frank van der Linden <fvdl@...gle.com>
Subject: Re: [PATCHv4 09/14] mm/hugetlb: Remove fake head pages
> On Jan 28, 2026, at 20:59, Kiryl Shutsemau <kas@...nel.org> wrote:
>
> On Wed, Jan 28, 2026 at 10:43:13AM +0800, Muchun Song wrote:
>>
>>
>>> On Jan 27, 2026, at 22:51, Kiryl Shutsemau <kas@...nel.org> wrote:
>>>
>>> On Thu, Jan 22, 2026 at 03:00:03PM +0800, Muchun Song wrote:
>>>>> + if (pfn)
>>>>> + return pfn_to_page(pfn);
>>>>> +
>>>>> + tail = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
>>>>> + if (!tail)
>>>>> + return NULL;
>>>>> +
>>>>> + p = page_to_virt(tail);
>>>>> + for (int i = 0; i < PAGE_SIZE / sizeof(struct page); i++)
>>>>> + prep_compound_tail(p + i, NULL, order);
>>>>> +
>>>>> + spin_lock(&hugetlb_lock);
>>>>
>>>> hugetlb_lock is considered a contended lock, better not to abuse it.
>>>> cmpxchg() is enought in this case.
>>>
>>> We hit the lock once per node (excluding races). Its contribution to the
>>> lock contention is negligible. spin_lock() is easier to follow. I will
>>> keep it.
>>
>> I don't think cmpxchg() is hard to follow. It’s precisely because of
>> your abuse that interrupts still have to be disabled here—hugetlb_lock
>> must be an irq-off lock. Are you really going to use spin_lock_irq just
>> because “it feels simpler” to you?
>
> I looked again at it and reconsidered. I will use cmpxchg(), but mostly
> because hugetlb_lock is a bad fit to protect anything in pg_data_t.
> vmemmap_tails can be used by code outside hugetlb.
>
> Here's the fixup.
>
> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> index 29e9bbb43178..63e7ca85c8c9 100644
> --- a/mm/hugetlb_vmemmap.c
> +++ b/mm/hugetlb_vmemmap.c
> @@ -512,18 +512,11 @@ static struct page *vmemmap_get_tail(unsigned int order, int node)
> for (int i = 0; i < PAGE_SIZE / sizeof(struct page); i++)
> prep_compound_tail(p + i, NULL, order);
>
> - spin_lock(&hugetlb_lock);
> - if (!NODE_DATA(node)->vmemmap_tails[idx]) {
> - pfn = PHYS_PFN(virt_to_phys(p));
> - NODE_DATA(node)->vmemmap_tails[idx] = pfn;
> - tail = NULL;
> - } else {
> - pfn = NODE_DATA(node)->vmemmap_tails[idx];
> - }
> - spin_unlock(&hugetlb_lock);
> -
> - if (tail)
> + pfn = PHYS_PFN(virt_to_phys(p));
> + if (cmpxchg(&NODE_DATA(node)->vmemmap_tails[idx], 0, pfn)) {
> __free_page(tail);
> + pfn = READ_ONCE(NODE_DATA(node)->vmemmap_tails[idx]);
> + }
Simpler than before.
>
> return pfn_to_page(pfn);
> }
> --
> Kiryl Shutsemau / Kirill A. Shutemov
Powered by blists - more mailing lists