From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-37.mta0.migadu.com [91.218.175.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0381440EBBD for ; Fri, 14 Aug 2026 07:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786692556; cv=none; b=DbSNTt6mOBRjiXqLDWekSWBW/PWwJdY4vGOvpPokAxb5WhTd+jAYJzHy0j3QOj5O2BX51b9WYBNF8CL/rjP5IWbTHVT6MI+hlnJWjP8IovYcYCnZYdzUI9Of38NiD8lgu6N+OvwjhmsIzrviY96ThZ8J1oYaWQMJAJ2OoP6GqFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786692556; c=relaxed/simple; bh=CUoyu6aX2EaLFf6CkIL9A6s2yLAOnA9F4p2InMLCBOo=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=RjxKVJBJem39H0FAZ0rXODfATfq14ZJvAxXwpduD5VGkFu5/KIA4FawyFKYX4XA8Zbx9vXb+Yv8KAHnCna3iXv0Wt17GU77f7QTSV1HgsFrjAidbbL3pp+IjIKEcfVyBa9aHMo0DnWstVNbFljgLah1hHyk+Kf/B0RYGSEfgFzM= 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=qZfv5/ON; arc=none smtp.client-ip=91.218.175.37 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="qZfv5/ON" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=CUoyu6aX2EaLFf6CkIL9A6s2yLAOnA9F4p2InMLCBOo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786692548; v=1; x=1787297348; b=qZfv5/ONotx/yRIWGLcNwl2uH1gA6Mxplo6oQNGZDAhuUAgKnzYRhh8KFn5iLoOLLqCOSu6M TzDnWXGzMzzfz3x21I6EctAQEwoszF2+hftL/KleYSXznwW50e/UvK5pP8uXo9IOnWmDmsP8iQ3 ktXDLIBzlRb0vtViHJNpqkFQ= X-Envelope-To: linux-kernel@vger.kernel.org Received: from [10.67.156.244] (114.251.196.87) by smtp.migadu.com with ESMTPS id 5bec0d8127702ed1; Fri, 14 Aug 2026 07:29:08 +0000 X-Migadu-Flow: FLOW_OUT Message-ID: <5b13eb55-4e27-47e0-adef-ef4c2f46f4c8@linux.dev> Date: Fri, 14 Aug 2026 15:29:03 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 08/17] mm/sparse-vmemmap: support section-based vmemmap optimization From: Muchun Song To: Muchun Song Cc: Mike Rapoport , Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , David Laight , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Oscar Salvador , David Hildenbrand References: <20260804035535.2846016-1-songmuchun@bytedance.com> <20260804035535.2846016-9-songmuchun@bytedance.com> <978060e0-a202-43b2-b84d-b1950b2d28c1@linux.dev> Content-Language: en-US In-Reply-To: <978060e0-a202-43b2-b84d-b1950b2d28c1@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/8/6 11:04, Muchun Song wrote: > > > On 2026/8/4 11:55, Muchun Song wrote: >> Teach sparse-vmemmap population code to use the compound page order >> when deciding whether a vmemmap page can be optimized. >> >> With this information, the common sparse-vmemmap population path can >> allocate or reuse shared tail vmemmap pages directly instead of relying >> on HugeTLB-specific handling. >> >> This centralizes vmemmap optimization logic in the sparse-vmemmap code, >> based on section metadata, and prepares for sharing the same mechanism >> across different users of vmemmap optimization, including HugeTLB and >> DAX. >> >> Signed-off-by: Muchun Song >> --- >> v2: >> - Keep vmemmap accounting and population logic in sparse-vmemmap.c >>    (suggested by Mike Rapoport) >> - Move vmemmap_get_tail() before its first use instead of adding only a >>    forward declaration in the previous patch (suggested by Mike >> Rapoport) >> - Simplify the PMD path handling for HVO-covered sections >> --- >>   mm/sparse-vmemmap.c | 36 ++++++++++++++++++++++++++++++------ >>   mm/sparse.c         |  4 ++-- >>   mm/sparse.h         |  7 +++++++ >>   3 files changed, 39 insertions(+), 8 deletions(-) >> >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index b770fe2428fd..b69a7af76858 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -186,6 +186,11 @@ static __meminit struct page >> *vmemmap_get_tail(unsigned int order, struct zone * >>         return tail; >>   } >> +#else >> +static inline struct page *vmemmap_get_tail(unsigned int order, >> struct zone *zone) >> +{ >> +    return NULL; >> +} >>   #endif >>     static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, >> unsigned long addr, int node, >> @@ -193,12 +198,24 @@ static pte_t * __meminit >> vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in >>                          unsigned long ptpfn, unsigned long flags) >>   { >>       pte_t *pte = pte_offset_kernel(pmd, addr); >> +    unsigned long pfn = page_to_pfn((struct page *)addr); >> + >>       if (pte_none(ptep_get(pte))) { >>           pte_t entry; >> -        void *p; >> + >> +        if (pfn_vmemmap_optimizable(pfn) && ptpfn == (unsigned >> long)-1) { >> +            unsigned int order = pfn_to_section_order(pfn); >> +            struct zone *zone = pfn_to_zone(pfn, node); >> +            struct page *page = vmemmap_get_tail(order, zone); >> + >> +            if (!page) >> +                return NULL; >> +            ptpfn = page_to_pfn(page); >> +        } >>             if (ptpfn == (unsigned long)-1) { >> -            p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap); >> +            void *p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap); >> + >>               if (!p) >>                   return NULL; >>               ptpfn = PHYS_PFN(__pa(p)); >> @@ -217,7 +234,8 @@ static pte_t * __meminit >> vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in >>           } >>           entry = pfn_pte(ptpfn, PAGE_KERNEL); >>           set_pte_at(&init_mm, addr, pte, entry); >> -    } >> +    } else if (WARN_ON_ONCE(pfn_vmemmap_optimizable(pfn))) >> +        return NULL; >>       return pte; >>   } >>   @@ -406,6 +424,9 @@ int __meminit >> vmemmap_populate_hugepages(unsigned long start, unsigned long end, >>       pmd_t *pmd; >>         for (addr = start; addr < end; addr = next) { >> +        unsigned long pfn = page_to_pfn((struct page *)addr); >> +        const struct mem_section *ms = __pfn_to_section(pfn); >> + >>           next = pmd_addr_end(addr, end); >>             pgd = vmemmap_pgd_populate(addr, node); >> @@ -421,7 +442,7 @@ int __meminit vmemmap_populate_hugepages(unsigned >> long start, unsigned long end, >>               return -ENOMEM; >>             pmd = pmd_offset(pud, addr); >> -        if (pmd_none(pmdp_get(pmd))) { >> +        if (pmd_none(pmdp_get(pmd)) && >> !section_vmemmap_optimizable(ms)) { >>               void *p; >>                 p = vmemmap_alloc_block_buf(PMD_SIZE, node, altmap); >> @@ -439,8 +460,11 @@ int __meminit >> vmemmap_populate_hugepages(unsigned long start, unsigned long end, >>                    */ >>                   return -ENOMEM; >>               } >> -        } else if (vmemmap_check_pmd(pmd, node, addr, next)) >> +        } else if (vmemmap_check_pmd(pmd, node, addr, next)) { >> +            if (WARN_ON_ONCE(section_vmemmap_optimizable(ms))) >> +                return -ENOTSUPP; >>               continue; >> +        } >>           if (vmemmap_populate_basepages(addr, next, node, altmap)) >>               return -ENOMEM; >>       } >> @@ -648,7 +672,7 @@ void offline_mem_sections(unsigned long >> start_pfn, unsigned long end_pfn) >>       } >>   } >>   -static int __meminit section_nr_vmemmap_pages(unsigned long pfn, >> unsigned long nr_pages, >> +int __meminit section_nr_vmemmap_pages(unsigned long pfn, unsigned >> long nr_pages, > > The kernel test robot reported a compilation issue: when > CONFIG_MEMORY_HOTPLUG = n && CONFIG_SPARSEMEM_VMEMMAP=y, > section_nr_vmemmap_pages is undefined. This problem is easy to fix, and > I will move the entire function outside the CONFIG_MEMORY_HOTPLUG guard > in the next version. Hi, I will wait a few more days to see if there are any reviews. If there is no further input during this period, I will update a new version to resolve this compilation issue. Muchun, Thanks