Re: [PATCH v6 4/6] mm/vmalloc: Extend page table walk to support larger page_shift sizes and eliminate page table rewalk
From: Dev Jain
Date: Tue Jul 14 2026 - 02:46:02 EST
On 14/07/26 11:40 am, Wen Jiang wrote:
> On Mon, 13 Jul 2026 at 21:49, Dev Jain <dev.jain@xxxxxxx> wrote:
>>
>>
>>
>> On 09/07/26 1:08 pm, Wen Jiang wrote:
>>> From: "Barry Song (Xiaomi)" <baohua@xxxxxxxxxx>
>>>
>>> vmap_pages_range_noflush_walk() (formerly vmap_small_pages_range_noflush())
>>> provides a clean interface by taking struct page **pages and mapping them
>>> via direct PTE iteration. This avoids the page table rewalk seen when
>>> using vmap_range_noflush() for page_shift values other than PAGE_SHIFT.
>>>
>>> Extend it to support larger page_shift values, and add PMD- and
>>> contiguous-PTE mappings as well. Rename it to vmap_pages_range_noflush_walk()
>>> since it now handles more than just small pages.
>>>
>>> For vmalloc() allocations with VM_ALLOW_HUGE_VMAP, we no longer need to
>>> iterate over pages one by one via vmap_range_noflush(), which would
>>> otherwise lead to page table rewalk. The code is now unified with the
>>> PAGE_SHIFT case by simply calling vmap_pages_range_noflush_walk().
>>>
>>> Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
>>> Signed-off-by: Wen Jiang <jiangwen6@xxxxxxxxxx>
>>> Tested-by: Xueyuan Chen <xueyuan.chen21@xxxxxxxxx>
>>> Tested-by: Leo Yan <leo.yan@xxxxxxx>
>>> Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
>>> ---
>>> mm/vmalloc.c | 81 ++++++++++++++++++++++++++++++----------------------
>>> 1 file changed, 47 insertions(+), 34 deletions(-)
>>>
>>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>>> index d7fef85b241c4..d2a4d649af549 100644
>>> --- a/mm/vmalloc.c
>>> +++ b/mm/vmalloc.c
>>> @@ -125,7 +125,8 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
>>> pte_t *pte;
>>> u64 pfn;
>>> struct page *page;
>>> - unsigned long size = PAGE_SIZE;
>>> + unsigned long size;
>>> + unsigned int steps;
>>>
>>> if (WARN_ON_ONCE(!PAGE_ALIGNED(end - addr)))
>>> return -EINVAL;
>>> @@ -147,8 +148,8 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
>>> }
>>>
>>> size = vmap_set_ptes(pte, addr, end, pfn, prot, max_page_shift);
>>> - pfn += PFN_DOWN(size);
>>> - } while (pte += PFN_DOWN(size), addr += size, addr != end);
>>> + steps = PFN_DOWN(size);
>>> + } while (pte += steps, pfn += steps, addr += size, addr != end);
>>
>> I think I had also recommended to put these vmap_pte_range() changes
>> into the previous patch.
>>
>
> Hi Dev
>
> I put this change in patch 4 following Uladzislau's earlier suggestion:
>
> https://lore.kernel.org/linux-mm/ah3Cn3YnefIVJDo2@milan/
>
> Uladzislau, do you have a preference on where this hunk should go?
>
Sorry if I wasn't clear enough. I am not contradicting Uladzislau's comment -
separate patch 3 and 4 are good. I was just commenting on the specific change
you did here w.r.t vmap_pte_range.
The only bit you change above is to introduce a local variable 'steps'. You
can move this bit into the previous patch, so that patch 4 is completely
focussed on extending the vmap_pages_* functions to accept a 'shift'.
> Thanks,
> Wen