0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-03 15:41:54 +00:00

Change slabs for linpools

This commit is contained in:
Igor Putovny 2024-06-04 17:44:28 +02:00
parent cdc90530ed
commit 67350540fb
2 changed files with 35 additions and 42 deletions

View File

@ -77,16 +77,16 @@ is_leaf(const struct trie_node *node)
} }
/* /*
* Allocate new node in protocol slab * Allocate new node in protocol linpool
*/ */
static struct trie_node * static struct trie_node *
create_new_node(slab *trie_slab) create_new_node(linpool *trie_pool)
{ {
return sl_allocz(trie_slab); return lp_allocz(trie_pool, sizeof(struct trie_node));
} }
/* /*
* Mark appropriate child of parent node as NULL and free @node * Mark appropriate child of parent node as NULL
*/ */
static void static void
remove_node(struct trie_node *node) remove_node(struct trie_node *node)
@ -105,8 +105,6 @@ remove_node(struct trie_node *node)
else else
bug("Invalid child pointer"); bug("Invalid child pointer");
} }
sl_free(node);
} }
/* /*
@ -131,12 +129,12 @@ delete_trie(struct trie_node *node)
* Insert prefix in @addr to prefix trie with beginning at @root and assign @bucket to this prefix * Insert prefix in @addr to prefix trie with beginning at @root and assign @bucket to this prefix
*/ */
static void static void
trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const root, struct aggregator_bucket *bucket, slab *trie_slab) trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const root, struct aggregator_bucket *bucket, linpool *trie_pool)
{ {
assert(addr != NULL); assert(addr != NULL);
assert(bucket != NULL); assert(bucket != NULL);
assert(root != NULL); assert(root != NULL);
assert(trie_slab != NULL); assert(trie_pool != NULL);
struct trie_node *node = root; struct trie_node *node = root;
@ -146,7 +144,7 @@ trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const
if (!node->child[bit]) if (!node->child[bit])
{ {
struct trie_node *new = create_new_node(trie_slab); struct trie_node *new = create_new_node(trie_pool);
new->parent = node; new->parent = node;
node->child[bit] = new; node->child[bit] = new;
new->depth = new->parent->depth + 1; new->depth = new->parent->depth + 1;
@ -160,12 +158,12 @@ trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const
} }
static void static void
trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const root, struct aggregator_bucket *bucket, slab *trie_slab) trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const root, struct aggregator_bucket *bucket, linpool *trie_pool)
{ {
assert(addr != NULL); assert(addr != NULL);
assert(bucket != NULL); assert(bucket != NULL);
assert(root != NULL); assert(root != NULL);
assert(trie_slab != NULL); assert(trie_pool != NULL);
struct trie_node *node = root; struct trie_node *node = root;
@ -175,7 +173,7 @@ trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const
if (!node->child[bit]) if (!node->child[bit])
{ {
struct trie_node *new = create_new_node(trie_slab); struct trie_node *new = create_new_node(trie_pool);
new->parent = node; new->parent = node;
node->child[bit] = new; node->child[bit] = new;
new->depth = new->parent->depth + 1; new->depth = new->parent->depth + 1;
@ -208,10 +206,10 @@ get_ancestor_bucket(const struct trie_node *node)
} }
static void static void
first_pass_new(struct trie_node *node, slab *trie_slab) first_pass_new(struct trie_node *node, linpool *trie_pool)
{ {
assert(node != NULL); assert(node != NULL);
assert(trie_slab != NULL); assert(trie_pool != NULL);
if (is_leaf(node)) if (is_leaf(node))
{ {
@ -232,7 +230,7 @@ first_pass_new(struct trie_node *node, slab *trie_slab)
{ {
if (!node->child[i]) if (!node->child[i])
{ {
struct trie_node *new = create_new_node(trie_slab); struct trie_node *new = create_new_node(trie_pool);
new->parent = node; new->parent = node;
new->bucket = node->bucket; new->bucket = node->bucket;
new->depth = node->depth + 1; new->depth = node->depth + 1;
@ -241,10 +239,10 @@ first_pass_new(struct trie_node *node, slab *trie_slab)
} }
if (node->child[0]) if (node->child[0])
first_pass_new(node->child[0], trie_slab); first_pass_new(node->child[0], trie_pool);
if (node->child[1]) if (node->child[1])
first_pass_new(node->child[1], trie_slab); first_pass_new(node->child[1], trie_pool);
node->bucket = NULL; node->bucket = NULL;
} }
@ -281,11 +279,11 @@ first_pass_after_check(const struct trie_node *node)
* First pass of Optimal Route Table Construction (ORTC) algorithm * First pass of Optimal Route Table Construction (ORTC) algorithm
*/ */
static void static void
first_pass(struct trie_node *node, slab *trie_slab) first_pass(struct trie_node *node, linpool *trie_pool)
{ {
bug(""); bug("");
assert(node != NULL); assert(node != NULL);
assert(trie_slab != NULL); assert(trie_pool != NULL);
if (!node->parent) if (!node->parent)
assert(node->bucket != NULL); assert(node->bucket != NULL);
@ -310,7 +308,7 @@ first_pass(struct trie_node *node, slab *trie_slab)
{ {
if (!node->child[i]) if (!node->child[i])
{ {
struct trie_node *new = create_new_node(trie_slab); struct trie_node *new = create_new_node(trie_pool);
new->parent = node; new->parent = node;
new->bucket = get_ancestor_bucket(new); new->bucket = get_ancestor_bucket(new);
node->child[i] = new; node->child[i] = new;
@ -319,8 +317,8 @@ first_pass(struct trie_node *node, slab *trie_slab)
} }
/* Preorder traversal */ /* Preorder traversal */
first_pass(node->child[0], trie_slab); first_pass(node->child[0], trie_pool);
first_pass(node->child[1], trie_slab); first_pass(node->child[1], trie_pool);
} }
static int static int
@ -861,14 +859,14 @@ construct_trie(struct aggregator_proto *p)
if (uptr->n.type == NET_IP4) if (uptr->n.type == NET_IP4)
{ {
const struct net_addr_ip4 *addr = &uptr->ip4; const struct net_addr_ip4 *addr = &uptr->ip4;
trie_insert_prefix_ip4(addr, p->root, bucket, p->trie_slab); trie_insert_prefix_ip4(addr, p->root, bucket, p->trie_pool);
log("INSERT %N", addr); log("INSERT %N", addr);
p->before_count++; p->before_count++;
} }
else if (uptr->n.type == NET_IP6) else if (uptr->n.type == NET_IP6)
{ {
const struct net_addr_ip6 *addr = &uptr->ip6; const struct net_addr_ip6 *addr = &uptr->ip6;
trie_insert_prefix_ip6(addr, p->root, bucket, p->trie_slab); trie_insert_prefix_ip6(addr, p->root, bucket, p->trie_pool);
log("INSERT %N", addr); log("INSERT %N", addr);
p->before_count++; p->before_count++;
} }
@ -890,7 +888,7 @@ calculate_trie(struct aggregator_proto *p)
log("====PREFIXES BEFORE ===="); log("====PREFIXES BEFORE ====");
log("====FIRST PASS===="); log("====FIRST PASS====");
first_pass_new(p->root, p->trie_slab); first_pass_new(p->root, p->trie_pool);
first_pass_after_check(p->root); first_pass_after_check(p->root);
print_prefixes(p->root, p->addr_type); print_prefixes(p->root, p->addr_type);
@ -1320,7 +1318,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
return; return;
/* Evaluate route attributes. */ /* Evaluate route attributes. */
struct aggregator_bucket *tmp_bucket = sl_allocz(p->bucket_slab); struct aggregator_bucket *tmp_bucket = lp_allocz(p->bucket_pool, sizeof(*tmp_bucket));
for (uint val_idx = 0; val_idx < p->aggr_on_count; val_idx++) for (uint val_idx = 0; val_idx < p->aggr_on_count; val_idx++)
{ {
@ -1425,7 +1423,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
/* Find the existing bucket */ /* Find the existing bucket */
if (new_bucket = HASH_FIND(p->buckets, AGGR_BUCK, tmp_bucket)) if (new_bucket = HASH_FIND(p->buckets, AGGR_BUCK, tmp_bucket))
sl_free(tmp_bucket); ;
else else
{ {
new_bucket = tmp_bucket; new_bucket = tmp_bucket;
@ -1441,7 +1439,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
log("new rte: %p, net: %p, src: %p, hash: %x", new, new->net, new->src, aggr_route_hash(new)); log("new rte: %p, net: %p, src: %p, hash: %x", new, new->net, new->src, aggr_route_hash(new));
/* Insert the new route into the bucket */ /* Insert the new route into the bucket */
struct aggregator_route *arte = sl_alloc(p->route_slab); struct aggregator_route *arte = lp_allocz(p->route_pool, sizeof(*arte));
*arte = (struct aggregator_route) { *arte = (struct aggregator_route) {
.bucket = new_bucket, .bucket = new_bucket,
.rte = *new, .rte = *new,
@ -1466,7 +1464,6 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
old_bucket->count--; old_bucket->count--;
HASH_REMOVE2(p->routes, AGGR_RTE, p->p.pool, old_route); HASH_REMOVE2(p->routes, AGGR_RTE, p->p.pool, old_route);
rta_free(old_route->rte.attrs); rta_free(old_route->rte.attrs);
sl_free(old_route);
} }
if (p->net_present != 0) if (p->net_present != 0)
@ -1484,7 +1481,6 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
{ {
ASSERT_DIE(!old_bucket->rte && !old_bucket->count); ASSERT_DIE(!old_bucket->rte && !old_bucket->count);
HASH_REMOVE2(p->buckets, AGGR_BUCK, p->p.pool, old_bucket); HASH_REMOVE2(p->buckets, AGGR_BUCK, p->p.pool, old_bucket);
sl_free(old_bucket);
} }
assert(p->root != NULL); assert(p->root != NULL);
@ -1561,10 +1557,10 @@ aggregator_start(struct proto *P)
p->addr_type = p->src->table->addr_type; p->addr_type = p->src->table->addr_type;
p->bucket_slab = sl_new(P->pool, sizeof(struct aggregator_bucket) + AGGR_DATA_MEMSIZE); p->bucket_pool = lp_new(P->pool);
HASH_INIT(p->buckets, P->pool, AGGR_BUCK_ORDER); HASH_INIT(p->buckets, P->pool, AGGR_BUCK_ORDER);
p->route_slab = sl_new(P->pool, sizeof(struct aggregator_route)); p->route_pool = lp_new(P->pool);
HASH_INIT(p->routes, P->pool, AGGR_RTE_ORDER); HASH_INIT(p->routes, P->pool, AGGR_RTE_ORDER);
p->reload_buckets = (event) { p->reload_buckets = (event) {
@ -1572,8 +1568,8 @@ aggregator_start(struct proto *P)
.data = p, .data = p,
}; };
p->trie_slab = sl_new(p->p.pool, sizeof(struct trie_node)); p->trie_pool = lp_new(P->pool);
p->root = create_new_node(p->trie_slab); p->root = create_new_node(p->trie_pool);
p->root->depth = 1; p->root->depth = 1;
p->aggr_done = 0; p->aggr_done = 0;
@ -1596,12 +1592,12 @@ aggregator_start(struct proto *P)
struct rta rta = { 0 }; struct rta rta = { 0 };
/* Allocate bucket for root node */ /* Allocate bucket for root node */
struct aggregator_bucket *new_bucket = sl_allocz(p->bucket_slab); struct aggregator_bucket *new_bucket = lp_allocz(p->bucket_pool, sizeof(*new_bucket));
u64 haux = 0; u64 haux = 0;
mem_hash_init(&haux); mem_hash_init(&haux);
new_bucket->hash = mem_hash_value(&haux); new_bucket->hash = mem_hash_value(&haux);
struct aggregator_route *arte = sl_alloc(p->route_slab); struct aggregator_route *arte = lp_allocz(p->route_pool, sizeof(*arte));
*arte = (struct aggregator_route) { *arte = (struct aggregator_route) {
.bucket = new_bucket, .bucket = new_bucket,
@ -1640,19 +1636,16 @@ aggregator_shutdown(struct proto *P)
b->count--; b->count--;
HASH_REMOVE(p->routes, AGGR_RTE, arte); HASH_REMOVE(p->routes, AGGR_RTE, arte);
rta_free(arte->rte.attrs); rta_free(arte->rte.attrs);
sl_free(arte);
} }
ASSERT_DIE(b->count == 0); ASSERT_DIE(b->count == 0);
HASH_REMOVE(p->buckets, AGGR_BUCK, b); HASH_REMOVE(p->buckets, AGGR_BUCK, b);
sl_free(b);
} }
HASH_WALK_END; HASH_WALK_END;
settle_cancel(&p->aggr_timer); settle_cancel(&p->aggr_timer);
assert(p->root != NULL); assert(p->root != NULL);
delete_trie(p->root);
p->root = NULL; p->root = NULL;
return PS_DOWN; return PS_DOWN;

View File

@ -52,11 +52,11 @@ struct aggregator_proto {
/* Buckets by aggregator rule */ /* Buckets by aggregator rule */
HASH(struct aggregator_bucket) buckets; HASH(struct aggregator_bucket) buckets;
slab *bucket_slab; linpool *bucket_pool;
/* Routes by net and src */ /* Routes by net and src */
HASH(struct aggregator_route) routes; HASH(struct aggregator_route) routes;
slab *route_slab; linpool *route_pool;
/* Aggregator rule */ /* Aggregator rule */
uint aggr_on_count; uint aggr_on_count;
@ -70,7 +70,7 @@ struct aggregator_proto {
/* Aggregation trie */ /* Aggregation trie */
uint addr_type; uint addr_type;
slab *trie_slab; linpool *trie_pool;
struct trie_node *root; struct trie_node *root;
struct settle_config aggr_timer_cf; struct settle_config aggr_timer_cf;
struct settle aggr_timer; struct settle aggr_timer;