Home | History | Annotate | Download | only in pipebuffer

Lines Matching full:slabs

38    /* Slabs with allocation candidates. Typically, slabs in this list should
46 * Due to a race in new slab allocation, additional slabs in this list
49 struct list_head slabs;
54 pb_slab_reclaim(struct pb_slabs *slabs, struct pb_slab_entry *entry)
64 struct pb_slab_group *group = &slabs->groups[entry->group_index];
65 LIST_ADDTAIL(&slab->head, &group->slabs);
70 slabs->slab_free(slabs->priv, slab);
75 pb_slabs_reclaim_locked(struct pb_slabs *slabs)
77 while (!LIST_IS_EMPTY(&slabs->reclaim)) {
79 LIST_ENTRY(struct pb_slab_entry, slabs->reclaim.next, head);
81 if (!slabs->can_reclaim(slabs->priv, entry))
84 pb_slab_reclaim(slabs, entry);
98 pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap)
100 unsigned order = MAX2(slabs->min_order, util_logbase2_ceil(size));
106 assert(order < slabs->min_order + slabs->num_orders);
107 assert(heap < slabs->num_heaps);
109 group_index = heap * slabs->num_orders + (order - slabs->min_order);
110 group = &slabs->groups[group_index];
112 pipe_mutex_lock(slabs->mutex);
117 if (LIST_IS_EMPTY(&group->slabs) ||
118 LIST_IS_EMPTY(&LIST_ENTRY(struct pb_slab, group->slabs.next, head)->free))
119 pb_slabs_reclaim_locked(slabs);
121 /* Remove slabs without free entries. */
122 while (!LIST_IS_EMPTY(&group->slabs)) {
123 slab = LIST_ENTRY(struct pb_slab, group->slabs.next, head);
130 if (LIST_IS_EMPTY(&group->slabs)) {
136 * slabs for the same group, but that doesn't hurt correctness.
138 pipe_mutex_unlock(slabs->mutex);
139 slab = slabs->slab_alloc(slabs->priv, heap, 1 << order, group_index);
142 pipe_mutex_lock(slabs->mutex);
144 LIST_ADD(&slab->head, &group->slabs);
151 pipe_mutex_unlock(slabs->mutex);
163 pb_slab_free(struct pb_slabs* slabs, struct pb_slab_entry *entry)
165 pipe_mutex_lock(slabs->mutex);
166 LIST_ADDTAIL(&entry->head, &slabs->reclaim);
167 pipe_mutex_unlock(slabs->mutex);
172 * This may end up freeing some slabs and is therefore useful to try to reclaim
177 pb_slabs_reclaim(struct pb_slabs *slabs)
179 pipe_mutex_lock(slabs->mutex);
180 pb_slabs_reclaim_locked(slabs);
181 pipe_mutex_unlock(slabs->mutex);
184 /* Initialize the slabs manager.
192 pb_slabs_init(struct pb_slabs *slabs,
206 slabs->min_order = min_order;
207 slabs->num_orders = max_order - min_order + 1;
208 slabs->num_heaps = num_heaps;
210 slabs->priv = priv;
211 slabs->can_reclaim = can_reclaim;
212 slabs->slab_alloc = slab_alloc;
213 slabs->slab_free = slab_free;
215 LIST_INITHEAD(&slabs->reclaim);
217 num_groups = slabs->num_orders * slabs->num_heaps;
218 slabs->groups = CALLOC(num_groups, sizeof(*slabs->groups));
219 if (!slabs->groups)
223 struct pb_slab_group *group = &slabs->groups[i];
224 LIST_INITHEAD(&group->slabs);
227 pipe_mutex_init(slabs->mutex);
234 * This will free all allocated slabs and internal structures, even if some
239 pb_slabs_deinit(struct pb_slabs *slabs)
244 while (!LIST_IS_EMPTY(&slabs->reclaim)) {
246 LIST_ENTRY(struct pb_slab_entry, slabs->reclaim.next, head);
247 pb_slab_reclaim(slabs, entry);
250 FREE(slabs->groups);
251 pipe_mutex_destroy(slabs->mutex);