diff --git a/include/os/linux/spl/sys/kmem_cache.h b/include/os/linux/spl/sys/kmem_cache.h index b159bb52d1..905ff57a14 100644 --- a/include/os/linux/spl/sys/kmem_cache.h +++ b/include/os/linux/spl/sys/kmem_cache.h @@ -192,22 +192,25 @@ extern void spl_kmem_reap(void); extern uint64_t spl_kmem_cache_inuse(kmem_cache_t *cache); extern uint64_t spl_kmem_cache_entry_size(kmem_cache_t *cache); +#ifndef SPL_KMEM_CACHE_IMPLEMENTING +/* + * Macros for the kmem_cache_* API expected by ZFS and SPL clients. We don't + * define them inside spl-kmem-cache.c, as that uses the kernel's incompatible + * kmem_cache_* facilities to implement ours. + */ + +/* Avoid conflicts with kernel names that might be implemented as macros. */ +#undef kmem_cache_alloc + #define kmem_cache_create(name, size, align, ctor, dtor, rclm, priv, vmp, fl) \ spl_kmem_cache_create(name, size, align, ctor, dtor, rclm, priv, vmp, fl) #define kmem_cache_set_move(skc, move) spl_kmem_cache_set_move(skc, move) #define kmem_cache_destroy(skc) spl_kmem_cache_destroy(skc) -/* - * This is necessary to be compatible with other kernel modules - * or in-tree filesystem that may define kmem_cache_alloc, - * like bcachefs does it now. - */ -#ifdef kmem_cache_alloc -#undef kmem_cache_alloc -#endif #define kmem_cache_alloc(skc, flags) spl_kmem_cache_alloc(skc, flags) #define kmem_cache_free(skc, obj) spl_kmem_cache_free(skc, obj) #define kmem_cache_reap_now(skc) spl_kmem_cache_reap_now(skc) #define kmem_reap() spl_kmem_reap() +#endif /* * The following functions are only available for internal use. diff --git a/module/os/linux/spl/spl-kmem-cache.c b/module/os/linux/spl/spl-kmem-cache.c index 42821ad602..737c2e063f 100644 --- a/module/os/linux/spl/spl-kmem-cache.c +++ b/module/os/linux/spl/spl-kmem-cache.c @@ -21,6 +21,8 @@ * with the SPL. If not, see . */ +#define SPL_KMEM_CACHE_IMPLEMENTING + #include #include #include @@ -33,16 +35,6 @@ #include #include -/* - * Within the scope of spl-kmem.c file the kmem_cache_* definitions - * are removed to allow access to the real Linux slab allocator. - */ -#undef kmem_cache_destroy -#undef kmem_cache_create -#undef kmem_cache_alloc -#undef kmem_cache_free - - /* * Linux 3.16 replaced smp_mb__{before,after}_{atomic,clear}_{dec,inc,bit}() * with smp_mb__{before,after}_atomic() because they were redundant. This is