Skip to content

Commit

Permalink
Free all slabs on region reset
Browse files Browse the repository at this point in the history
Free all slabs on region_reset. Freed slabs are going to be used as a
cache for future allocation.

(cherry picked from commit 50069ca)
  • Loading branch information
Georgy Kirichenko committed May 18, 2019
1 parent 76be096 commit 67d7ab4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions small/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ region_reserve(struct region *region, size_t size)
slab.next_in_list);
if (size <= rslab_unused(slab))
return (char *) rslab_data(slab) + slab->used;
/* Try to get a slab from the region cache. */
slab = rlist_last_entry(&region->slabs.slabs,
struct rslab,
slab.next_in_list);
if (slab->used == 0 && size <= rslab_unused(slab)) {
/* Move this slab to the head. */
slab_list_del(&region->slabs, &slab->slab, next_in_list);
slab_list_add(&region->slabs, &slab->slab, next_in_list);
return (char *) rslab_data(slab);
}
}
return region_reserve_slow(region, size);
}
Expand Down Expand Up @@ -212,14 +222,14 @@ region_aligned_alloc(struct region *region, size_t size, size_t alignment)

/**
* Mark region as empty, but keep the blocks.
* Do not change the first slab and use previous slabs as a cache to
* use for future allocations.
*/
static inline void
region_reset(struct region *region)
{
if (! rlist_empty(&region->slabs.slabs)) {
struct rslab *slab = rlist_first_entry(&region->slabs.slabs,
struct rslab,
slab.next_in_list);
struct rslab *slab;
rlist_foreach_entry(slab, &region->slabs.slabs, slab.next_in_list) {
region->slabs.stats.used -= slab->used;
slab->used = 0;
}
Expand Down

0 comments on commit 67d7ab4

Please sign in to comment.