Re: [PATCH] block: partitions: replace __get_free_page() with kmalloc()

From: Mike Rapoport

Date: Mon May 25 2026 - 05:37:16 EST


On Mon, May 25, 2026 at 12:16:23AM -0700, Christoph Hellwig wrote:
> On Mon, May 25, 2026 at 09:52:09AM +0300, Mike Rapoport wrote:
> > On Sun, May 24, 2026 at 11:08:31PM -0700, Christoph Hellwig wrote:
> > > On Wed, May 20, 2026 at 11:15:52AM +0300, Mike Rapoport (Microsoft) wrote:
> > > > check_partition() allocates a buffer to use as backing buffer for
> > > > seq_buf.
> > > >
> > > > This buffer can be allocated with kmalloc() as there's nothing special
> > > > about it to go directly to the page allocator.
> > > >
> > > > Replace use of __get_free_page() with kmalloc() and free_page() with
> > > > kfree().
> > >
> > > So I heard various vague references that we should replace
> > > __get_free_page with kmalloc, but nothing definitive. Can you please
> > > point to a good resource for that?
> >
> > There was quite recent discussion when I posted patches that change
> > __get_free_page to return void *:
> >
> > https://lore.kernel.org/all/20251018093002.3660549-1-rppt@xxxxxxxxxx/
>
> This doesn't tell much more.
>
> > And an old thread when Al posted similar patches:
> >
> > https://lore.kernel.org/all/CA+55aFwp4iy4rtX2gE2WjBGFL=NxMVnoFeHqYa2j1dYOMMGqxg@xxxxxxxxxxxxxx/T/#u<S-Del>
>
> This does, but it still fails to explain why kmalloc performs just as
> well as __get_free_page(s) these days.

I don't think that in this case - a single allocation on the cold path -
the performance difference is even measurable.

Nevertheless allocations from slab caches are way faster than
__get_free_page() (i.e. alloc_pages()) as it's essentially lockless
cmpxchg. Allocations that need to refill the cache do alloc_pages() with a
little of slab bookkeeping overhead.

--
Sincerely yours,
Mike.