mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 07:31:54 +00:00
Attribute blocks are now allocated from slabs instead of malloc()
This commit is contained in:
parent
d3af586da4
commit
8d7f516b2a
@ -265,6 +265,7 @@ struct ea_storage {
|
|||||||
#define EALF_SORTED 1 /* Attributes are sorted by code */
|
#define EALF_SORTED 1 /* Attributes are sorted by code */
|
||||||
#define EALF_BISECT 2 /* Use interval bisection for searching */
|
#define EALF_BISECT 2 /* Use interval bisection for searching */
|
||||||
#define EALF_CACHED 4 /* List is cached */
|
#define EALF_CACHED 4 /* List is cached */
|
||||||
|
#define EALF_HUGE 8 /* List is too big to fit into slab */
|
||||||
|
|
||||||
struct ea_class {
|
struct ea_class {
|
||||||
#define EA_CLASS_INSIDE \
|
#define EA_CLASS_INSIDE \
|
||||||
|
@ -182,6 +182,10 @@ DOMAIN(attrs) attrs_domain;
|
|||||||
|
|
||||||
pool *rta_pool;
|
pool *rta_pool;
|
||||||
|
|
||||||
|
/* Assuming page size of 4096, these are magic values for slab allocation */
|
||||||
|
static const uint ea_slab_sizes[] = { 56, 112, 168, 288, 448, 800, 1344 };
|
||||||
|
static slab *ea_slab[ARRAY_SIZE(ea_slab_sizes)];
|
||||||
|
|
||||||
static slab *rte_src_slab;
|
static slab *rte_src_slab;
|
||||||
|
|
||||||
static struct idm src_ids;
|
static struct idm src_ids;
|
||||||
@ -1485,11 +1489,22 @@ ea_lookup(ea_list *o, int overlay)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint elen = ea_list_size(o);
|
uint elen = ea_list_size(o);
|
||||||
r = mb_alloc(rta_pool, elen + sizeof(struct ea_storage));
|
uint sz = elen + sizeof(struct ea_storage);
|
||||||
|
for (uint i=0; i<ARRAY_SIZE(ea_slab_sizes); i++)
|
||||||
|
if (sz <= ea_slab_sizes[i])
|
||||||
|
{
|
||||||
|
r = sl_alloc(ea_slab[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int huge = r ? 0 : EALF_HUGE;;
|
||||||
|
if (huge)
|
||||||
|
r = mb_alloc(rta_pool, sz);
|
||||||
|
|
||||||
ea_list_copy(r->l, o, elen);
|
ea_list_copy(r->l, o, elen);
|
||||||
ea_list_ref(r->l);
|
ea_list_ref(r->l);
|
||||||
|
|
||||||
r->l->flags |= EALF_CACHED;
|
r->l->flags |= EALF_CACHED | huge;
|
||||||
r->hash_key = h;
|
r->hash_key = h;
|
||||||
r->uc = 1;
|
r->uc = 1;
|
||||||
|
|
||||||
@ -1516,7 +1531,10 @@ ea_free_locked(struct ea_storage *a)
|
|||||||
a->next_hash->pprev_hash = a->pprev_hash;
|
a->next_hash->pprev_hash = a->pprev_hash;
|
||||||
|
|
||||||
ea_list_unref(a->l);
|
ea_list_unref(a->l);
|
||||||
mb_free(a);
|
if (a->l->flags & EALF_HUGE)
|
||||||
|
mb_free(a);
|
||||||
|
else
|
||||||
|
sl_free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1580,6 +1598,9 @@ rta_init(void)
|
|||||||
|
|
||||||
rta_pool = rp_new(&root_pool, "Attributes");
|
rta_pool = rp_new(&root_pool, "Attributes");
|
||||||
|
|
||||||
|
for (uint i=0; i<ARRAY_SIZE(ea_slab_sizes); i++)
|
||||||
|
ea_slab[i] = sl_new(rta_pool, ea_slab_sizes[i]);
|
||||||
|
|
||||||
rta_alloc_hash();
|
rta_alloc_hash();
|
||||||
rte_src_init();
|
rte_src_init();
|
||||||
ea_class_init();
|
ea_class_init();
|
||||||
|
Loading…
Reference in New Issue
Block a user