Lines Matching full:pool
48 * - a pointer to the child pool to which this element belongs, or
62 /* Next page in the same child pool. */
83 * pool has been destroyed). Mark the element as freed and free the whole page
99 * Create a parent pool for the allocation of same-sized objects.
123 * Create a child pool linked to the given parent.
125 void slab_create_child(struct slab_child_pool *pool, in slab_create_child() argument
128 pool->parent = parent; in slab_create_child()
129 pool->pages = NULL; in slab_create_child()
130 pool->free = NULL; in slab_create_child()
131 pool->migrated = NULL; in slab_create_child()
135 * Destroy the child pool.
137 * Pages associated to the pool will be orphaned. They are eventually freed
140 void slab_destroy_child(struct slab_child_pool *pool) in slab_destroy_child() argument
142 if (!pool->parent) in slab_destroy_child()
145 simple_mtx_lock(&pool->parent->mutex); in slab_destroy_child()
147 while (pool->pages) { in slab_destroy_child()
148 struct slab_page_header *page = pool->pages; in slab_destroy_child()
149 pool->pages = page->u.next; in slab_destroy_child()
150 p_atomic_set(&page->u.num_remaining, pool->parent->num_elements); in slab_destroy_child()
152 for (unsigned i = 0; i < pool->parent->num_elements; ++i) { in slab_destroy_child()
153 struct slab_element_header *elt = slab_get_element(pool->parent, page, i); in slab_destroy_child()
158 while (pool->migrated) { in slab_destroy_child()
159 struct slab_element_header *elt = pool->migrated; in slab_destroy_child()
160 pool->migrated = elt->next; in slab_destroy_child()
164 simple_mtx_unlock(&pool->parent->mutex); in slab_destroy_child()
166 while (pool->free) { in slab_destroy_child()
167 struct slab_element_header *elt = pool->free; in slab_destroy_child()
168 pool->free = elt->next; in slab_destroy_child()
173 pool->parent = NULL; in slab_destroy_child()
177 slab_add_new_page(struct slab_child_pool *pool) in slab_add_new_page() argument
180 pool->parent->num_elements * pool->parent->element_size); in slab_add_new_page()
185 for (unsigned i = 0; i < pool->parent->num_elements; ++i) { in slab_add_new_page()
186 struct slab_element_header *elt = slab_get_element(pool->parent, page, i); in slab_add_new_page()
187 elt->owner = (intptr_t)pool; in slab_add_new_page()
190 elt->next = pool->free; in slab_add_new_page()
191 pool->free = elt; in slab_add_new_page()
195 page->u.next = pool->pages; in slab_add_new_page()
196 pool->pages = page; in slab_add_new_page()
202 * Allocate an object from the child pool. Single-threaded (i.e. the caller
203 * must ensure that no operation happens on the same child pool in another
207 slab_alloc(struct slab_child_pool *pool) in slab_alloc() argument
211 if (!pool->free) { in slab_alloc()
213 * different child pool. in slab_alloc()
215 simple_mtx_lock(&pool->parent->mutex); in slab_alloc()
216 pool->free = pool->migrated; in slab_alloc()
217 pool->migrated = NULL; in slab_alloc()
218 simple_mtx_unlock(&pool->parent->mutex); in slab_alloc()
221 if (!pool->free && !slab_add_new_page(pool)) in slab_alloc()
225 elt = pool->free; in slab_alloc()
226 pool->free = elt->next; in slab_alloc()
238 slab_zalloc(struct slab_child_pool *pool) in slab_zalloc() argument
240 void *r = slab_alloc(pool); in slab_zalloc()
242 memset(r, 0, pool->parent->item_size); in slab_zalloc()
248 * must ensure that no operation happens on the same child pool in another
251 * Freeing an object in a different child pool from the one where it was
252 * allocated is allowed, as long the pool belong to the same parent. No
255 void slab_free(struct slab_child_pool *pool, void *ptr) in slab_free() argument
263 if (p_atomic_read(&elt->owner) == (intptr_t)pool) { in slab_free()
267 elt->next = pool->free; in slab_free()
268 pool->free = elt; in slab_free()
273 if (pool->parent) in slab_free()
274 simple_mtx_lock(&pool->parent->mutex); in slab_free()
276 /* Note: we _must_ re-read elt->owner here because the owning child pool in slab_free()
285 if (pool->parent) in slab_free()
286 simple_mtx_unlock(&pool->parent->mutex); in slab_free()
288 if (pool->parent) in slab_free()
289 simple_mtx_unlock(&pool->parent->mutex); in slab_free()