From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 1AA95367B90 for ; Wed, 3 Jun 2026 12:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780489466; cv=none; b=XrGJmO0OivKnkukpdIMs/dioEjv07gTindjgLnZJY3GgJi6PFFQ2lVgiRFCwPyjRoI7iXlsdLO85dYZzzB5C6SLMg1YQvSFA30LhJCVRQ8yWOLCm5fuaZxWt/1pON7s16qqNf8OJbQ4C+pcGmHP52bYKkBUEigRX3KGGhUFZ74E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780489466; c=relaxed/simple; bh=pLnbHTyJLvX5eI1GzF2yve6nxyXqkC8CgfQa+ncIKS4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VK1RB6wfeZYKca5j1NdLKQjfsIx6Od6dsCF2pJJisyHnX01N8ChFnYk5Niwy8v+9lz4xzVKZlLZIg8T10LFa/0qRzpIsSDphdQWi9nzGKyw/SnYpbIXI8CXmXqrgJWvG6jhT2Udlf6h5a82g8fJPXBeaUjjd65p3cjkp5Fsx04w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=HubuBb2q; arc=none smtp.client-ip=91.218.175.173 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) header.d=linux.dev header.i=@linux.dev header.b="HubuBb2q" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780489462; h=from:from: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; bh=i81FGwAX/vixZ25Q3Ngd8ivvoVTv7aSnS7HWQVQ1K20=; b=HubuBb2qZb4N9mqtKd+HqBZxa//bXTQ7vqPh0cqo521lhCGrl2arQXZ0egrlgrhMVPjN1w 58IEh2Vdv9FcCt9r5uDyBa3ErJYP6T7LGb5Df4WMvfpy1qfJaqgAjvA1opfVW8eeXtT4yb kc47gaP4MkVI9XYMHI853t/97ZI2r0w= Date: Wed, 3 Jun 2026 20:24:09 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3 15/19] mm/hugetlb_vmemmap: Move bootmem HVO setup to early init To: Usama Arif Cc: Oscar Salvador , David Hildenbrand , Andrew Morton , Madhavan Srinivasan , Michael Ellerman , Mike Rapoport , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , "Aneesh Kumar K.V" , linuxppc-dev@lists.ozlabs.org, Muchun Song References: <20260603120246.1572177-1-usama.arif@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260603120246.1572177-1-usama.arif@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/6/3 20:02, Usama Arif wrote: > On Tue, 2 Jun 2026 18:10:35 +0800 Muchun Song wrote: > >> Bootmem HugeTLB pages currently defer HVO setup to >> hugetlb_vmemmap_init_late(), because the optimization needs zone >> information. >> >> Now that zone initialization is available earlier, the bootmem HVO setup >> can be done directly from hugetlb_vmemmap_init_early(). This lets >> gigantic HugeTLB pages apply HVO as soon as they are allocated. >> >> Bootmem gigantic pages that span multiple zones are now filtered out >> when they are allocated, so the remaining bootmem gigantic pages seen by >> later hugetlb initialization are already zone-valid. As a result, >> hugetlb_vmemmap_init_late() no longer needs to handle bootmem HVO setup. >> >> Signed-off-by: Muchun Song >> --- >> mm/hugetlb_vmemmap.c | 67 +++++++++----------------------------------- >> 1 file changed, 13 insertions(+), 54 deletions(-) >> >> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c >> index ea6af85bfec1..464578ee246e 100644 >> --- a/mm/hugetlb_vmemmap.c >> +++ b/mm/hugetlb_vmemmap.c >> @@ -745,6 +745,8 @@ static bool vmemmap_should_optimize_bootmem_page(struct huge_bootmem_page *m) >> return true; >> } >> >> +static struct zone *pfn_to_zone(unsigned nid, unsigned long pfn); >> + >> /* >> * Initialize memmap section for a gigantic page, HVO-style. >> */ >> @@ -752,6 +754,7 @@ void __init hugetlb_vmemmap_init_early(int nid) >> { >> unsigned long psize, paddr, section_size; >> unsigned long ns, i, pnum, pfn, nr_pages; >> + unsigned long start, end; >> struct huge_bootmem_page *m = NULL; >> void *map; >> >> @@ -761,6 +764,8 @@ void __init hugetlb_vmemmap_init_early(int nid) >> section_size = (1UL << PA_SECTION_SHIFT); >> >> list_for_each_entry(m, &huge_boot_pages[nid], list) { >> + struct zone *zone; >> + >> if (!vmemmap_should_optimize_bootmem_page(m)) >> continue; >> >> @@ -769,6 +774,14 @@ void __init hugetlb_vmemmap_init_early(int nid) >> paddr = virt_to_phys(m); >> pfn = PHYS_PFN(paddr); >> map = pfn_to_page(pfn); >> + start = (unsigned long)map; >> + end = start + hugetlb_vmemmap_size(m->hstate); >> + zone = pfn_to_zone(nid, pfn); >> + >> + if (vmemmap_populate_hvo(start, end, huge_page_order(m->hstate), >> + zone, HUGETLB_VMEMMAP_RESERVE_SIZE)) >> + panic("Failed to allocate memmap for HugeTLB page\n"); > The replaced hugetlb_vmemmap_init_late() path used to fall back to > vmemmap_populate() if vmemmap_populate_hvo() returned an error and > just lost the HVO optimization for that page. > > The new path panics on any non-zero return. Is the panic intended, > given that vmemmap_populate_hvo() returns -ENOMEM on allocation > failure and HVO is normally treated as an optimization rather than a > hard requirement? This is intentional; see patch 6:     mm/sparse: Panic on memmap and usemap allocation failure We already panic on OOM anyway. Muchun, Thanks. > >> + memmap_boot_pages_add(DIV_ROUND_UP(HUGETLB_VMEMMAP_RESERVE_SIZE, PAGE_SIZE)); >> >> pnum = pfn_to_section_nr(pfn); >> ns = psize / section_size; >> @@ -800,60 +813,6 @@ static struct zone *pfn_to_zone(unsigned nid, unsigned long pfn) >> >> void __init hugetlb_vmemmap_init_late(int nid) >> { >> - struct huge_bootmem_page *m, *tm; >> - unsigned long phys, nr_pages, start, end; >> - unsigned long pfn, nr_mmap; >> - struct zone *zone = NULL; >> - struct hstate *h; >> - void *map; >> - >> - if (!READ_ONCE(vmemmap_optimize_enabled)) >> - return; >> - >> - list_for_each_entry_safe(m, tm, &huge_boot_pages[nid], list) { >> - if (!(m->flags & HUGE_BOOTMEM_HVO)) >> - continue; >> - >> - phys = virt_to_phys(m); >> - h = m->hstate; >> - pfn = PHYS_PFN(phys); >> - nr_pages = pages_per_huge_page(h); >> - map = pfn_to_page(pfn); >> - start = (unsigned long)map; >> - end = start + nr_pages * sizeof(struct page); >> - >> - if (!hugetlb_bootmem_page_zones_valid(nid, m)) { >> - /* >> - * Oops, the hugetlb page spans multiple zones. >> - * Remove it from the list, and populate it normally. >> - */ >> - list_del(&m->list); >> - >> - vmemmap_populate(start, end, nid, NULL); >> - nr_mmap = end - start; >> - memmap_boot_pages_add(DIV_ROUND_UP(nr_mmap, PAGE_SIZE)); >> - >> - memblock_phys_free(phys, huge_page_size(h)); >> - continue; >> - } >> - >> - if (!zone || !zone_spans_pfn(zone, pfn)) >> - zone = pfn_to_zone(nid, pfn); >> - if (WARN_ON_ONCE(!zone)) >> - continue; >> - >> - if (vmemmap_populate_hvo(start, end, huge_page_order(h), zone, >> - HUGETLB_VMEMMAP_RESERVE_SIZE) < 0) { >> - /* Fallback if HVO population fails */ >> - vmemmap_populate(start, end, nid, NULL); >> - nr_mmap = end - start; >> - } else { >> - m->flags |= HUGE_BOOTMEM_ZONES_VALID; >> - nr_mmap = HUGETLB_VMEMMAP_RESERVE_SIZE; >> - } >> - >> - memmap_boot_pages_add(DIV_ROUND_UP(nr_mmap, PAGE_SIZE)); >> - } >> } >> #endif >> >> -- >> 2.54.0 >> >>