Lines Matching refs: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.
122 * Create a child pool linked to the given parent.
124 void slab_create_child(struct slab_child_pool *pool,
127 pool->parent = parent;
128 pool->pages = NULL;
129 pool->free = NULL;
130 pool->migrated = NULL;
134 * Destroy the child pool.
136 * Pages associated to the pool will be orphaned. They are eventually freed
139 void slab_destroy_child(struct slab_child_pool *pool)
141 if (!pool->parent)
144 simple_mtx_lock(&pool->parent->mutex);
146 while (pool->pages) {
147 struct slab_page_header *page = pool->pages;
148 pool->pages = page->u.next;
149 p_atomic_set(&page->u.num_remaining, pool->parent->num_elements);
151 for (unsigned i = 0; i < pool->parent->num_elements; ++i) {
152 struct slab_element_header *elt = slab_get_element(pool->parent, page, i);
157 while (pool->migrated) {
158 struct slab_element_header *elt = pool->migrated;
159 pool->migrated = elt->next;
163 simple_mtx_unlock(&pool->parent->mutex);
165 while (pool->free) {
166 struct slab_element_header *elt = pool->free;
167 pool->free = elt->next;
172 pool->parent = NULL;
176 slab_add_new_page(struct slab_child_pool *pool)
179 pool->parent->num_elements * pool->parent->element_size);
184 for (unsigned i = 0; i < pool->parent->num_elements; ++i) {
185 struct slab_element_header *elt = slab_get_element(pool->parent, page, i);
186 elt->owner = (intptr_t)pool;
189 elt->next = pool->free;
190 pool->free = elt;
194 page->u.next = pool->pages;
195 pool->pages = page;
201 * Allocate an object from the child pool. Single-threaded (i.e. the caller
202 * must ensure that no operation happens on the same child pool in another
206 slab_alloc(struct slab_child_pool *pool)
210 if (!pool->free) {
212 * different child pool.
214 simple_mtx_lock(&pool->parent->mutex);
215 pool->free = pool->migrated;
216 pool->migrated = NULL;
217 simple_mtx_unlock(&pool->parent->mutex);
220 if (!pool->free && !slab_add_new_page(pool))
224 elt = pool->free;
225 pool->free = elt->next;
235 * must ensure that no operation happens on the same child pool in another
238 * Freeing an object in a different child pool from the one where it was
239 * allocated is allowed, as long the pool belong to the same parent. No
242 void slab_free(struct slab_child_pool *pool, void *ptr)
250 if (p_atomic_read(&elt->owner) == (intptr_t)pool) {
254 elt->next = pool->free;
255 pool->free = elt;
260 if (pool->parent)
261 simple_mtx_lock(&pool->parent->mutex);
263 /* Note: we _must_ re-read elt->owner here because the owning child pool
272 if (pool->parent)
273 simple_mtx_unlock(&pool->parent->mutex);
275 if (pool->parent)
276 simple_mtx_unlock(&pool->parent->mutex);