Re: [PATCH 10/17] jbd2: replace __get_free_pages() with kmalloc()
Jan Kara <[email protected]> Mon, 25 May 2026 18:17:04 +0200
| Newsgroups | org.kernel.vger.linux-nilfs,dev.linux.lists.ocfs2-devel,org.kernel.vger.linux-ext4,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.kvack.linux-mm |
|---|---|
| Message-ID | <2omm5gmnv2khshoxkrag5rusd3qzrsqyjgsef2syxgryrtg6vq@ao7oabqwebgo> |
On Sat 23-05-26 20:54:22, 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) <[email protected]> Looks good. Feel free to add: Reviewed-by: Jan Kara <[email protected]> I'll just note that we allocate here fs block size large buffer so the same kind of allocator as we use for folios would be even better. But that's a different cleanup I guess. Honza > --- > fs/jbd2/journal.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c > index 4f397fcdb13c..1137b471e490 100644 > --- a/fs/jbd2/journal.c > +++ b/fs/jbd2/journal.c > @@ -2784,7 +2784,7 @@ void *jbd2_alloc(size_t size, gfp_t flags) > if (size < PAGE_SIZE) > ptr = kmem_cache_alloc(get_slab(size), flags); > else > - ptr = (void *)__get_free_pages(flags, get_order(size)); > + ptr = kmalloc(size, flags); > > /* Check alignment; SLUB has gotten this wrong in the past, > * and this can lead to user data corruption! */ > @@ -2795,10 +2795,7 @@ void *jbd2_alloc(size_t size, gfp_t flags) > > void jbd2_free(void *ptr, size_t size) > { > - if (size < PAGE_SIZE) > - kmem_cache_free(get_slab(size), ptr); > - else > - free_pages((unsigned long)ptr, get_order(size)); > + kfree(ptr); > }; > > /* > > -- > 2.53.0 > -- Jan Kara <[email protected]> SUSE Labs, CR