Lines Matching refs:slabs
49 struct list_head slabs; member
54 pb_slab_reclaim(struct pb_slabs *slabs, struct pb_slab_entry *entry) in pb_slab_reclaim() argument
64 struct pb_slab_group *group = &slabs->groups[entry->group_index]; in pb_slab_reclaim()
65 list_addtail(&slab->head, &group->slabs); in pb_slab_reclaim()
70 slabs->slab_free(slabs->priv, slab); in pb_slab_reclaim()
75 pb_slabs_reclaim_locked(struct pb_slabs *slabs) in pb_slabs_reclaim_locked() argument
77 while (!list_is_empty(&slabs->reclaim)) { in pb_slabs_reclaim_locked()
79 LIST_ENTRY(struct pb_slab_entry, slabs->reclaim.next, head); in pb_slabs_reclaim_locked()
81 if (!slabs->can_reclaim(slabs->priv, entry)) in pb_slabs_reclaim_locked()
84 pb_slab_reclaim(slabs, entry); in pb_slabs_reclaim_locked()
98 pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap) in pb_slab_alloc() argument
100 unsigned order = MAX2(slabs->min_order, util_logbase2_ceil(size)); in pb_slab_alloc()
106 assert(order < slabs->min_order + slabs->num_orders); in pb_slab_alloc()
107 assert(heap < slabs->num_heaps); in pb_slab_alloc()
109 group_index = heap * slabs->num_orders + (order - slabs->min_order); in pb_slab_alloc()
110 group = &slabs->groups[group_index]; in pb_slab_alloc()
112 mtx_lock(&slabs->mutex); in pb_slab_alloc()
117 if (list_is_empty(&group->slabs) || in pb_slab_alloc()
118 list_is_empty(&LIST_ENTRY(struct pb_slab, group->slabs.next, head)->free)) in pb_slab_alloc()
119 pb_slabs_reclaim_locked(slabs); in pb_slab_alloc()
122 while (!list_is_empty(&group->slabs)) { in pb_slab_alloc()
123 slab = LIST_ENTRY(struct pb_slab, group->slabs.next, head); in pb_slab_alloc()
130 if (list_is_empty(&group->slabs)) { in pb_slab_alloc()
138 mtx_unlock(&slabs->mutex); in pb_slab_alloc()
139 slab = slabs->slab_alloc(slabs->priv, heap, 1 << order, group_index); in pb_slab_alloc()
142 mtx_lock(&slabs->mutex); in pb_slab_alloc()
144 list_add(&slab->head, &group->slabs); in pb_slab_alloc()
151 mtx_unlock(&slabs->mutex); in pb_slab_alloc()
163 pb_slab_free(struct pb_slabs* slabs, struct pb_slab_entry *entry) in pb_slab_free() argument
165 mtx_lock(&slabs->mutex); in pb_slab_free()
166 list_addtail(&entry->head, &slabs->reclaim); in pb_slab_free()
167 mtx_unlock(&slabs->mutex); in pb_slab_free()
177 pb_slabs_reclaim(struct pb_slabs *slabs) in pb_slabs_reclaim() argument
179 mtx_lock(&slabs->mutex); in pb_slabs_reclaim()
180 pb_slabs_reclaim_locked(slabs); in pb_slabs_reclaim()
181 mtx_unlock(&slabs->mutex); in pb_slabs_reclaim()
192 pb_slabs_init(struct pb_slabs *slabs, in pb_slabs_init() argument
206 slabs->min_order = min_order; in pb_slabs_init()
207 slabs->num_orders = max_order - min_order + 1; in pb_slabs_init()
208 slabs->num_heaps = num_heaps; in pb_slabs_init()
210 slabs->priv = priv; in pb_slabs_init()
211 slabs->can_reclaim = can_reclaim; in pb_slabs_init()
212 slabs->slab_alloc = slab_alloc; in pb_slabs_init()
213 slabs->slab_free = slab_free; in pb_slabs_init()
215 list_inithead(&slabs->reclaim); in pb_slabs_init()
217 num_groups = slabs->num_orders * slabs->num_heaps; in pb_slabs_init()
218 slabs->groups = CALLOC(num_groups, sizeof(*slabs->groups)); in pb_slabs_init()
219 if (!slabs->groups) in pb_slabs_init()
223 struct pb_slab_group *group = &slabs->groups[i]; in pb_slabs_init()
224 list_inithead(&group->slabs); in pb_slabs_init()
227 (void) mtx_init(&slabs->mutex, mtx_plain); in pb_slabs_init()
239 pb_slabs_deinit(struct pb_slabs *slabs) in pb_slabs_deinit() argument
244 while (!list_is_empty(&slabs->reclaim)) { in pb_slabs_deinit()
246 LIST_ENTRY(struct pb_slab_entry, slabs->reclaim.next, head); in pb_slabs_deinit()
247 pb_slab_reclaim(slabs, entry); in pb_slabs_deinit()
250 FREE(slabs->groups); in pb_slabs_deinit()
251 mtx_destroy(&slabs->mutex); in pb_slabs_deinit()