Re: [PATCH 10/17] jbd2: replace __get_free_pages() with kmalloc()
From: Theodore Tso
Date: Wed Jun 03 2026 - 09:58:33 EST
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?
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?
* 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?
Thanks,
- Ted