Skip to content

Commit 6bb22d8

Browse files
lplewabratpiorka
authored andcommitted
do not allocate slab->iter dynamically
There is no reason to do so. This is only extra performance overhead. Signed-off-by: Łukasz Plewa <[email protected]>
1 parent 75dea95 commit 6bb22d8

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

src/pool/pool_disjoint.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,16 @@ static slab_t *create_slab(bucket_t *bucket) {
6868
slab->first_free_chunk_idx = 0;
6969
slab->bucket = bucket;
7070

71-
slab->iter = umf_ba_global_alloc(sizeof(*slab->iter));
72-
if (slab->iter == NULL) {
73-
LOG_ERR("allocation of new slab iter failed!");
74-
goto free_slab;
75-
}
76-
slab->iter->val = slab;
77-
slab->iter->prev = slab->iter->next = NULL;
71+
slab->iter.val = slab;
72+
slab->iter.prev = slab->iter.next = NULL;
7873

7974
slab->num_chunks_total =
8075
utils_max(bucket_slab_min_size(bucket) / bucket->size, 1);
8176
slab->chunks =
8277
umf_ba_global_alloc(sizeof(*slab->chunks) * slab->num_chunks_total);
8378
if (slab->chunks == NULL) {
8479
LOG_ERR("allocation of slab chunks failed!");
85-
goto free_slab_iter;
80+
goto free_slab;
8681
}
8782
memset(slab->chunks, 0, sizeof(*slab->chunks) * slab->num_chunks_total);
8883

@@ -111,9 +106,6 @@ static slab_t *create_slab(bucket_t *bucket) {
111106
free_slab_chunks:
112107
umf_ba_global_free(slab->chunks);
113108

114-
free_slab_iter:
115-
umf_ba_global_free(slab->iter);
116-
117109
free_slab:
118110
umf_ba_global_free(slab);
119111
return NULL;
@@ -131,7 +123,6 @@ static void destroy_slab(slab_t *slab) {
131123
}
132124

133125
umf_ba_global_free(slab->chunks);
134-
umf_ba_global_free(slab->iter);
135126
umf_ba_global_free(slab);
136127
}
137128

@@ -296,7 +287,7 @@ static void bucket_free_chunk(bucket_t *bucket, void *ptr, slab_t *slab,
296287
// in case if the slab was previously full and now has single available
297288
// chunk, it should be moved to the list of available slabs
298289
if (slab_get_num_free_chunks(slab) == 1) {
299-
slab_list_item_t *slab_it = slab->iter;
290+
slab_list_item_t *slab_it = &slab->iter;
300291
assert(slab_it->val != NULL);
301292
DL_DELETE(bucket->unavailable_slabs, slab_it);
302293
DL_PREPEND(bucket->available_slabs, slab_it);
@@ -312,7 +303,7 @@ static void bucket_free_chunk(bucket_t *bucket, void *ptr, slab_t *slab,
312303
*to_pool = bucket_can_pool(bucket);
313304
if (*to_pool == false) {
314305
// remove slab
315-
slab_list_item_t *slab_it = slab->iter;
306+
slab_list_item_t *slab_it = &slab->iter;
316307
assert(slab_it->val != NULL);
317308
slab_unreg(slab_it->val);
318309
DL_DELETE(bucket->available_slabs, slab_it);
@@ -364,7 +355,7 @@ static slab_t *bucket_create_slab(bucket_t *bucket) {
364355
return NULL;
365356
}
366357

367-
DL_PREPEND(bucket->available_slabs, slab->iter);
358+
DL_PREPEND(bucket->available_slabs, &slab->iter);
368359
bucket->available_slabs_num++;
369360
bucket_update_stats(bucket, 1, 0);
370361

src/pool/pool_disjoint_internal.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ typedef struct bucket_t {
8181
size_t max_slabs_in_use;
8282
} bucket_t;
8383

84+
typedef struct slab_list_item_t {
85+
slab_t *val;
86+
struct slab_list_item_t *prev, *next;
87+
} slab_list_item_t;
88+
8489
// Represents the allocated memory block of size 'slab_min_size'
8590
// Internally, it splits the memory block into chunks. The number of
8691
// chunks depends on the size of a Bucket which created the Slab.
@@ -107,14 +112,9 @@ typedef struct slab_t {
107112

108113
// Store iterator to the corresponding node in avail/unavail list
109114
// to achieve O(1) removal
110-
slab_list_item_t *iter;
115+
slab_list_item_t iter;
111116
} slab_t;
112117

113-
typedef struct slab_list_item_t {
114-
slab_t *val;
115-
struct slab_list_item_t *prev, *next;
116-
} slab_list_item_t;
117-
118118
typedef struct umf_disjoint_pool_shared_limits_t {
119119
size_t max_size;
120120
size_t total_size; // requires atomic access

0 commit comments

Comments
 (0)