Skip to content

Commit b4c1131

Browse files
author
Georgy Kirichenko
committed
do not keep a slab in cache if new allocation does not fit
Do not allocate a new slab if there is a free slab in a region cache. If a cached slab is not big enough then free it. Follow up 67d7ab4 Fixes #12
1 parent 50cb787 commit b4c1131

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

small/region.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ region_reserve(struct region *region, size_t size)
157157
if (size <= rslab_unused(slab))
158158
return (char *) rslab_data(slab) + slab->used;
159159
/* Try to get a slab from the region cache. */
160-
slab = rlist_last_entry(&region->slabs.slabs,
161-
struct rslab,
162-
slab.next_in_list);
163-
if (slab->used == 0 && size <= rslab_unused(slab)) {
164-
/* Move this slab to the head. */
160+
while ((slab = rlist_last_entry(&region->slabs.slabs,
161+
struct rslab,
162+
slab.next_in_list))->used == 0) {
165163
slab_list_del(&region->slabs, &slab->slab, next_in_list);
166-
slab_list_add(&region->slabs, &slab->slab, next_in_list);
167-
return (char *) rslab_data(slab);
164+
if (size <= rslab_unused(slab)) {
165+
/* Move this slab to the head. */
166+
slab_list_add(&region->slabs, &slab->slab, next_in_list);
167+
return (char *) rslab_data(slab);
168+
}
169+
/*
170+
* This cached slab could not be used so free it
171+
* and try to use the next one.
172+
*/
173+
slab_put(region->cache, (struct slab *)slab);
168174
}
169175
}
170176
return region_reserve_slow(region, size);

0 commit comments

Comments
 (0)