Re: [PATCH] mm: Refactor vma_map_pages to use vm_insert_pages

From: Matthew Wilcox

Date: Wed Jan 28 2026 - 19:51:31 EST


On Wed, Jan 28, 2026 at 05:59:12PM -0500, Brian Geffon wrote:
> On Wed, Jan 28, 2026 at 5:57 PM Justin Green <greenjustin@xxxxxxxxxxxx> wrote:
> >
> > vma_map_pages currently calls vm_insert_page on each individual page in
> > the mapping, which creates significant overhead because we are
> > repeatedly spinlocking. Instead, we should batch insert pages using
> > vm_insert_pages, which amortizes the cost of the spinlock.
>
> This makes sense, I wonder why this wasn't done previously?

That's always a good question, because it might reveal why this patch is
a bad idea ...

However in this case, it simply seems to be an oversight.
__vm_map_pages() was introduced in May 2019 and then vm_insert_pages()
was added in April 2020.

Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>