Re: [PATCH] mm: Refactor vma_map_pages to use vm_insert_pages
From: Arjun Roy
Date: Wed Jan 28 2026 - 23:45:09 EST
On Wed, Jan 28, 2026 at 4:51 PM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
>
> 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.
>
Yes, it was an oversight. I had originally cooked up vm_insert_pages()
to amortize
that spinlock for TCP zerocopy receive, and had not noticed __vm_map_pages()
sitting right there.
Reviewed-by: Arjun Roy <arjunroy@xxxxxxxxxx>
-Arjun
> Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>