Skip to content

Commit

Permalink
LinuxKPI: move __kmalloc from slab.h to slab.c
Browse files Browse the repository at this point in the history
In order to allow the allocator to change in the future move it into
the implementation file from being an inline function in the header.

While here factor out the size calculation and add a comment as-to why
this is done.  We will need the size (_s) in the future to make a
decision on how to allocate.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45815
  • Loading branch information
Bjoern A. Zeeb authored and Bjoern A. Zeeb committed Jul 26, 2024
1 parent 5c3af1d commit 1f7df75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 2 additions & 7 deletions sys/compat/linuxkpi/common/include/linux/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct linux_kmem_cache;
#define ZERO_OR_NULL_PTR(x) ((x) == NULL || (x) == ZERO_SIZE_PTR)

extern void *lkpi_kmalloc(size_t size, gfp_t flags);
void *lkpi___kmalloc(size_t size, gfp_t flags);
#define __kmalloc(_s, _f) lkpi___kmalloc(_s, _f)

static inline gfp_t
linux_check_m_flags(gfp_t flags)
Expand All @@ -108,13 +110,6 @@ linux_check_m_flags(gfp_t flags)
return (flags & GFP_NATIVE_MASK);
}

static inline void *
__kmalloc(size_t size, gfp_t flags)
{
return (malloc(MAX(size, sizeof(struct llist_node)), M_KMALLOC,
linux_check_m_flags(flags)));
}

static inline void *
kmalloc_node(size_t size, gfp_t flags, int node)
{
Expand Down
11 changes: 11 additions & 0 deletions sys/compat/linuxkpi/common/src/linux_slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ linux_kmem_cache_destroy(struct linux_kmem_cache *c)
free(c, M_KMALLOC);
}

void *
lkpi___kmalloc(size_t size, gfp_t flags)
{
size_t _s;

/* sizeof(struct llist_node) is used for kfree_async(). */
_s = MAX(size, sizeof(struct llist_node));

return (malloc(_s, M_KMALLOC, linux_check_m_flags(flags)));
}

struct lkpi_kmalloc_ctx {
size_t size;
gfp_t flags;
Expand Down

0 comments on commit 1f7df75

Please sign in to comment.