53#include <sys/kernel.h>
56#include <sys/malloc.h>
63#ifndef MTX_POOL_SLEEP_SIZE
64#define MTX_POOL_SLEEP_SIZE 1024
79#define mtx_pool_size mtx_pool_header.mtxpool_size
80#define mtx_pool_mask mtx_pool_header.mtxpool_mask
81#define mtx_pool_shift mtx_pool_header.mtxpool_shift
82#define mtx_pool_next mtx_pool_header.mtxpool_next
86#if UINTPTR_MAX == UINT64_MAX
87# define POINTER_BITS 64
88# define HASH_MULTIPLIER 11400714819323198485u
90# define POINTER_BITS 32
91# define HASH_MULTIPLIER 2654435769u
105 KASSERT(pool != NULL, (
"_mtx_pool_find(): null pool"));
121 pool->mtx_pool_size = pool_size;
122 pool->mtx_pool_mask = pool_size - 1;
123 for (i = 1, maskbits = 0; (i & pool_size) == 0; i = i << 1)
126 pool->mtx_pool_next = 0;
127 for (i = 0; i < pool_size; ++i)
136 if (pool_size <= 0 || !powerof2(pool_size)) {
137 printf(
"WARNING: %s pool size is not a power of 2.\n",
142 ((pool_size - 1) *
sizeof (
struct mtx)),
143 M_MTXPOOL, M_WAITOK | M_ZERO);
154 for (i = pool->mtx_pool_size - 1; i >= 0; --i)
156 free(pool, M_MTXPOOL);
177 KASSERT(pool != NULL, (
"mtx_pool_alloc(): null pool"));
183 i = pool->mtx_pool_next;
184 pool->mtx_pool_next = (i + 1) & pool->mtx_pool_mask;
188SYSINIT(mtxpooli2, SI_SUB_MTX_POOL_DYNAMIC, SI_ORDER_FIRST,
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
#define MTX_POOL_SLEEP_SIZE
static void mtx_pool_initialize(struct mtx_pool *pool, const char *mtx_name, int pool_size, int opts)
static void mtx_pool_setup_dynamic(void *dummy __unused)
struct mtx * mtx_pool_alloc(struct mtx_pool *pool)
static MALLOC_DEFINE(M_MTXPOOL, "mtx_pool", "mutex pool")
void mtx_pool_destroy(struct mtx_pool **poolp)
struct mtx_pool * mtx_pool_create(const char *mtx_name, int pool_size, int opts)
struct mtx_pool __read_mostly * mtxpool_sleep
struct mtx * mtx_pool_find(struct mtx_pool *pool, void *ptr)
SYSINIT(mtxpooli2, SI_SUB_MTX_POOL_DYNAMIC, SI_ORDER_FIRST, mtx_pool_setup_dynamic, NULL)
struct mtxpool_header mtx_pool_header
struct mtx mtx_pool_ary[1]
static bool kasan_enabled __read_mostly
int printf(const char *fmt,...)