Lines Matching refs:pool
73 static void init_mpool(struct mempool *pool) in init_mpool() argument
75 size_t sz = pool->size - raw_malloc_get_ctx_size(); in init_mpool()
76 vaddr_t v = ROUNDDOWN(pool->data + sz, sizeof(long) * 2); in init_mpool()
85 assert(v > pool->data); in init_mpool()
86 pool->mctx = (struct malloc_ctx *)v; in init_mpool()
87 raw_malloc_init_ctx(pool->mctx); in init_mpool()
88 raw_malloc_add_pool(pool->mctx, (void *)pool->data, v - pool->data); in init_mpool()
91 static void get_pool(struct mempool *pool __maybe_unused) in get_pool()
94 mutex_lock_recursive(&pool->mu); in get_pool()
95 if (!pool->mctx) in get_pool()
96 init_mpool(pool); in get_pool()
101 static void put_pool(struct mempool *pool __maybe_unused) in put_pool()
104 if (mutex_get_recursive_lock_depth(&pool->mu) == 1) { in put_pool()
109 if (pool->release_mem) { in put_pool()
110 pool->mctx = NULL; in put_pool()
111 pool->release_mem((void *)pool->data, pool->size); in put_pool()
114 mutex_unlock_recursive(&pool->mu); in put_pool()
122 struct mempool *pool = calloc(1, sizeof(*pool)); in mempool_alloc_pool() local
127 if (pool) { in mempool_alloc_pool()
128 pool->size = size; in mempool_alloc_pool()
129 pool->data = (vaddr_t)data; in mempool_alloc_pool()
131 pool->release_mem = release_mem; in mempool_alloc_pool()
132 mutex_init_recursive(&pool->mu); in mempool_alloc_pool()
134 init_mpool(pool); in mempool_alloc_pool()
138 return pool; in mempool_alloc_pool()
141 void *mempool_alloc(struct mempool *pool, size_t size) in mempool_alloc() argument
145 get_pool(pool); in mempool_alloc()
147 p = raw_malloc(0, 0, size, pool->mctx); in mempool_alloc()
152 raw_malloc_get_stats(pool->mctx, &stats); in mempool_alloc()
153 if (stats.max_allocated > pool->max_allocated) { in mempool_alloc()
154 pool->max_allocated = stats.max_allocated; in mempool_alloc()
156 pool->max_allocated); in mempool_alloc()
163 put_pool(pool); in mempool_alloc()
167 void *mempool_calloc(struct mempool *pool, size_t nmemb, size_t size) in mempool_calloc() argument
175 p = mempool_alloc(pool, sz); in mempool_calloc()
182 void mempool_free(struct mempool *pool, void *ptr) in mempool_free() argument
185 raw_free(ptr, pool->mctx, false /*!wipe*/); in mempool_free()
186 put_pool(pool); in mempool_free()