Re: [PATCH 10/17] jbd2: replace __get_free_pages() with kmalloc()

From: Mike Rapoport

Date: Thu Jun 04 2026 - 02:15:45 EST


Hi Ted,

On Wed, Jun 03, 2026 at 09:50:15AM -0400, Theodore Tso wrote:
> On Sat, May 23, 2026 at 08:54:22PM +0300, Mike Rapoport (Microsoft) wrote:
> > jbd2_alloc() falls back from kmem_cache_alloc() to __get_free_pages() for
> > allocations larger than PAGE_SIZE.
> > But kmalloc() can handle such cases with essentially the same fallback.
> >
> > Replace use of __get_free_pages() with kmalloc() and simplify
> > jbd2_free() as both kmem_cache_alloc() and kmalloc() allocations can be
> > freed with kfree().
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
>
> So historically __get_free_pages() was more efficient than kmalloc
> since previously the kmalloc overhead meant that a single 4k
> allocation would take two pages instead of one. I'm guessing that has
> since changed?

Today there's no memory overhead for kmalloc(PAGE_SIZE). Cache refill takes
more pages of course, but they will be handed over to the next
kmalloc(PAGE_SIZE).

> Can you explain to someone who hasn't been tracking the changes in
> kmalloc over time:
>
> * How does the efficiency of kmalloc compare to __get_free_page when
> order == 1? What is the overhead in terms of memory overhead?
> I'm a bit less concerned about CPU overhead, but it would be good
> to know that?

There's no memory overhead when order == 1.
As for the CPU overhead, the difference for the fast path allocations is
not measurable and for the slow path it is anyway determined by the amount
of reclaim involved rather than by what allocator is used.

> * What does kmalloc() do when a size > PAGE_SIZE is passed? Will it
> return contiguous memory, or return an error or worse, BUG? And
> same question as above; what is the overhead of kmalloc() when
> size is 2*PAGE_SIZE? 8*PAGE_SIZE?

For size >= PAGE_SIZE kmalloc() always returns contiguous page aligned
memory.

Larger allocations (> PAGE_SIZE * 2) go straight to the page allocator.

> Thanks,
>
> - Ted

--
Sincerely yours,
Mike.