• Home
  • Raw
  • Download

Lines Matching full:pool

50     * - a pointer to the child pool to which this element belongs, or
64 /* Next page in the same child pool. */
85 * pool has been destroyed). Mark the element as freed and free the whole page
101 * Create a parent pool for the allocation of same-sized objects.
124 * Create a child pool linked to the given parent.
126 void slab_create_child(struct slab_child_pool *pool, in slab_create_child() argument
129 pool->parent = parent; in slab_create_child()
130 pool->pages = NULL; in slab_create_child()
131 pool->free = NULL; in slab_create_child()
132 pool->migrated = NULL; in slab_create_child()
136 * Destroy the child pool.
138 * Pages associated to the pool will be orphaned. They are eventually freed
141 void slab_destroy_child(struct slab_child_pool *pool) in slab_destroy_child() argument
143 if (!pool->parent) in slab_destroy_child()
146 mtx_lock(&pool->parent->mutex); in slab_destroy_child()
148 while (pool->pages) { in slab_destroy_child()
149 struct slab_page_header *page = pool->pages; in slab_destroy_child()
150 pool->pages = page->u.next; in slab_destroy_child()
151 p_atomic_set(&page->u.num_remaining, pool->parent->num_elements); in slab_destroy_child()
153 for (unsigned i = 0; i < pool->parent->num_elements; ++i) { in slab_destroy_child()
154 struct slab_element_header *elt = slab_get_element(pool->parent, page, i); in slab_destroy_child()
159 while (pool->migrated) { in slab_destroy_child()
160 struct slab_element_header *elt = pool->migrated; in slab_destroy_child()
161 pool->migrated = elt->next; in slab_destroy_child()
165 mtx_unlock(&pool->parent->mutex); in slab_destroy_child()
167 while (pool->free) { in slab_destroy_child()
168 struct slab_element_header *elt = pool->free; in slab_destroy_child()
169 pool->free = elt->next; in slab_destroy_child()
174 pool->parent = NULL; in slab_destroy_child()
178 slab_add_new_page(struct slab_child_pool *pool) in slab_add_new_page() argument
181 pool->parent->num_elements * pool->parent->element_size); in slab_add_new_page()
186 for (unsigned i = 0; i < pool->parent->num_elements; ++i) { in slab_add_new_page()
187 struct slab_element_header *elt = slab_get_element(pool->parent, page, i); in slab_add_new_page()
188 elt->owner = (intptr_t)pool; in slab_add_new_page()
191 elt->next = pool->free; in slab_add_new_page()
192 pool->free = elt; in slab_add_new_page()
196 page->u.next = pool->pages; in slab_add_new_page()
197 pool->pages = page; in slab_add_new_page()
203 * Allocate an object from the child pool. Single-threaded (i.e. the caller
204 * must ensure that no operation happens on the same child pool in another
208 slab_alloc(struct slab_child_pool *pool) in slab_alloc() argument
212 if (!pool->free) { in slab_alloc()
214 * different child pool. in slab_alloc()
216 mtx_lock(&pool->parent->mutex); in slab_alloc()
217 pool->free = pool->migrated; in slab_alloc()
218 pool->migrated = NULL; in slab_alloc()
219 mtx_unlock(&pool->parent->mutex); in slab_alloc()
222 if (!pool->free && !slab_add_new_page(pool)) in slab_alloc()
226 elt = pool->free; in slab_alloc()
227 pool->free = elt->next; in slab_alloc()
237 * must ensure that no operation happens on the same child pool in another
240 * Freeing an object in a different child pool from the one where it was
241 * allocated is allowed, as long the pool belong to the same parent. No
244 void slab_free(struct slab_child_pool *pool, void *ptr) in slab_free() argument
252 if (p_atomic_read(&elt->owner) == (intptr_t)pool) { in slab_free()
256 elt->next = pool->free; in slab_free()
257 pool->free = elt; in slab_free()
262 mtx_lock(&pool->parent->mutex); in slab_free()
264 /* Note: we _must_ re-read elt->owner here because the owning child pool in slab_free()
273 mtx_unlock(&pool->parent->mutex); in slab_free()
275 mtx_unlock(&pool->parent->mutex); in slab_free()
285 slab_alloc_st(struct slab_mempool *pool) in slab_alloc_st() argument
287 return slab_alloc(&pool->child); in slab_alloc_st()
294 slab_free_st(struct slab_mempool *pool, void *ptr) in slab_free_st() argument
296 slab_free(&pool->child, ptr); in slab_free_st()
300 slab_destroy(struct slab_mempool *pool) in slab_destroy() argument
302 slab_destroy_child(&pool->child); in slab_destroy()
303 slab_destroy_parent(&pool->parent); in slab_destroy()
313 slab_create(struct slab_mempool *pool, in slab_create() argument
317 slab_create_parent(&pool->parent, item_size, num_items); in slab_create()
318 slab_create_child(&pool->child, &pool->parent); in slab_create()