Skip to content

Commit 4d84444

Browse files
committed
Use global base alloc in critnib
To avoid wasting memory. This will improve memory utilization especially for IPC-related changes where each memory provider can have it's own critnib instance for caching handles.
1 parent 3a2c937 commit 4d84444

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/critnib/critnib.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ struct critnib {
129129
uint64_t remove_count;
130130

131131
struct os_mutex_t mutex; /* writes/removes */
132-
133-
umf_ba_pool_t *pool_nodes;
134-
umf_ba_pool_t *pool_leaves;
135132
};
136133

137134
/*
@@ -191,25 +188,10 @@ struct critnib *critnib_new(void) {
191188
goto err_free_critnib;
192189
}
193190

194-
c->pool_nodes = umf_ba_create(sizeof(struct critnib_node));
195-
if (!c->pool_nodes) {
196-
goto err_util_mutex_destroy;
197-
}
198-
199-
c->pool_leaves = umf_ba_create(sizeof(struct critnib_leaf));
200-
if (!c->pool_leaves) {
201-
goto err_destroy_pool_nodes;
202-
}
203-
204191
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->root, sizeof(c->root));
205192
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->remove_count, sizeof(c->remove_count));
206193

207194
return c;
208-
209-
err_destroy_pool_nodes:
210-
umf_ba_destroy(c->pool_nodes);
211-
err_util_mutex_destroy:
212-
util_mutex_destroy_not_free(&c->mutex);
213195
err_free_critnib:
214196
umf_ba_global_free(c);
215197
return NULL;
@@ -220,15 +202,15 @@ struct critnib *critnib_new(void) {
220202
*/
221203
static void delete_node(struct critnib *c, struct critnib_node *__restrict n) {
222204
if (is_leaf(n)) {
223-
umf_ba_free(c->pool_leaves, to_leaf(n));
205+
umf_ba_global_free(to_leaf(n));
224206
} else {
225207
for (int i = 0; i < SLNODES; i++) {
226208
if (n->child[i]) {
227209
delete_node(c, n->child[i]);
228210
}
229211
}
230212

231-
umf_ba_free(c->pool_nodes, n);
213+
umf_ba_global_free(n);
232214
}
233215
}
234216

@@ -244,23 +226,21 @@ void critnib_delete(struct critnib *c) {
244226

245227
for (struct critnib_node *m = c->deleted_node; m;) {
246228
struct critnib_node *mm = m->child[0];
247-
umf_ba_free(c->pool_nodes, m);
229+
umf_ba_global_free(m);
248230
m = mm;
249231
}
250232

251233
for (struct critnib_leaf *k = c->deleted_leaf; k;) {
252234
struct critnib_leaf *kk = k->value;
253-
umf_ba_free(c->pool_leaves, k);
235+
umf_ba_global_free(k);
254236
k = kk;
255237
}
256238

257239
for (int i = 0; i < DELETED_LIFE; i++) {
258-
umf_ba_free(c->pool_nodes, c->pending_del_nodes[i]);
259-
umf_ba_free(c->pool_leaves, c->pending_del_leaves[i]);
240+
umf_ba_global_free(c->pending_del_nodes[i]);
241+
umf_ba_global_free(c->pending_del_leaves[i]);
260242
}
261243

262-
umf_ba_destroy(c->pool_nodes);
263-
umf_ba_destroy(c->pool_leaves);
264244
umf_ba_global_free(c);
265245
}
266246

@@ -288,7 +268,7 @@ static void free_node(struct critnib *__restrict c,
288268
*/
289269
static struct critnib_node *alloc_node(struct critnib *__restrict c) {
290270
if (!c->deleted_node) {
291-
return umf_ba_alloc(c->pool_nodes);
271+
return umf_ba_global_alloc(sizeof(struct critnib_node));
292272
}
293273

294274
struct critnib_node *n = c->deleted_node;
@@ -319,7 +299,7 @@ static void free_leaf(struct critnib *__restrict c,
319299
*/
320300
static struct critnib_leaf *alloc_leaf(struct critnib *__restrict c) {
321301
if (!c->deleted_leaf) {
322-
return umf_ba_alloc(c->pool_leaves);
302+
return umf_ba_global_alloc(sizeof(struct critnib_leaf));
323303
}
324304

325305
struct critnib_leaf *k = c->deleted_leaf;

0 commit comments

Comments
 (0)