From: Maria Matejka Date: Wed, 19 Feb 2025 08:40:27 +0000 (+0100) Subject: Revert migration of route attributes and BGP TX cache to Stonehenge X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf8304f16585e13c4a633b3e86b4904dba3aed4d;p=thirdparty%2Fbird.git Revert migration of route attributes and BGP TX cache to Stonehenge It collides with the new implementation of lockless Slab and global attribute cache, and becomes effectively useless. This reverts commit 4f7899e3cb17ee67875e53512db25ba5aa1dc236. This reverts commit 240dd41f06ef805f0f45ab8d2f58376fb9e538a6. This reverts commit 29df992f7f6ad03110240b2e65b498fe97371725. --- diff --git a/lib/resource.h b/lib/resource.h index 12b788510..48bf1f9ba 100644 --- a/lib/resource.h +++ b/lib/resource.h @@ -139,20 +139,6 @@ void *sl_allocz(slab *); void sl_free(void *); void sl_delete(slab *); -/* A whole stonehenge of slabs */ - -typedef struct stonehenge stonehenge; -typedef struct sth_block { - void *block; - bool large; -} sth_block; - -stonehenge *sth_new(pool *); -sth_block sth_alloc(stonehenge *, uint size); -sth_block sth_allocz(stonehenge *, uint size); -void sth_free(sth_block); -void sth_delete(stonehenge *); - /* * Low-level memory allocation functions, please don't use * outside resource manager and possibly sysdep code. diff --git a/lib/slab.c b/lib/slab.c index 9351a06dc..409f4b33e 100644 --- a/lib/slab.c +++ b/lib/slab.c @@ -460,66 +460,4 @@ slab_lookup(resource *r, unsigned long a) return NULL; } -static const uint stonehenge_sizes[] = { 56, 112, 168, 288, 448, 800, 1344 }; - -struct stonehenge { - pool *p; - slab *s[ARRAY_SIZE(stonehenge_sizes)]; -}; - -sth_block -sth_alloc(stonehenge *sth, uint size) -{ - for (uint i=0; is[i]) - sth->s[i] = sl_new(sth->p, stonehenge_sizes[i]); - - return (sth_block) { .block = sl_alloc(sth->s[i]), }; - } - - return (sth_block) { - .block = mb_alloc(sth->p, size), - .large = 1, - }; -} - -sth_block -sth_allocz(stonehenge *sth, uint size) -{ - sth_block b = sth_alloc(sth, size); - bzero(b.block, size); - return b; -} - -void -sth_free(sth_block b) -{ - if (b.large) - mb_free(b.block); - else - sl_free(b.block); -} - -stonehenge * -sth_new(pool *pp) -{ - stonehenge tmps = { - .p = rp_new(pp, pp->domain, "Stonehenge"), - }; - - stonehenge *s = sth_alloc(&tmps, sizeof(stonehenge)).block; - *s = tmps; - return s; -} - -void sth_delete(stonehenge *s) -{ - pool *p = s->p; - sth_free((sth_block) { s }); - rp_free(p); -} - - #endif diff --git a/nest/rt-attr.c b/nest/rt-attr.c index f4e09083e..2e5560c0c 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -204,7 +204,9 @@ DOMAIN(attrs) attrs_domain; pool *rta_pool; -static stonehenge *ea_sth; +/* 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; @@ -1592,18 +1594,24 @@ ea_lookup_slow(ea_list *o, u32 squash_upto, enum ea_stored oid) return rr; } + struct ea_storage *r = NULL; uint elen = ea_list_size(o); uint sz = elen + sizeof(struct ea_storage); - sth_block b = sth_alloc(ea_sth, sz); + for (uint i=0; il, o, elen); ea_list_ref(r->l); - if (b.large) - r->l->flags |= EALF_HUGE; - + r->l->flags |= huge; r->l->stored = oid; r->hash_key = h; atomic_store_explicit(&r->uc, 1, memory_order_release); @@ -1671,7 +1679,10 @@ ea_free_deferred(struct deferred_call *dc) /* And now we can free the object, finally */ ea_list_unref(r->l); - sth_free((sth_block) { r, !!(r->l->flags & EALF_HUGE) }); + if (r->l->flags & EALF_HUGE) + mb_free(r); + else + sl_free(r); RTA_UNLOCK; } @@ -1722,7 +1733,9 @@ rta_init(void) RTA_LOCK; rta_pool = rp_new(&root_pool, attrs_domain.attrs, "Attributes"); - ea_sth = sth_new(rta_pool); + for (uint i=0; isth, size); - b = blk.block; + b = mb_alloc(c->pool, size); *b = (struct bgp_bucket) { }; init_list(&b->prefixes); b->hash = hash; /* Copy the ea_list */ ea_list_copy(b->eattrs, new, ea_size); - if (blk.large) - b->eattrs->flags |= EALF_HUGE; /* Insert the bucket to bucket hash */ HASH_INSERT2(c->bucket_hash, RBH, c->pool, b); @@ -1767,7 +1764,7 @@ static void bgp_free_bucket(struct bgp_ptx_private *c, struct bgp_bucket *b) { HASH_REMOVE2(c->bucket_hash, RBH, c->pool, b); - sth_free((sth_block) { b, !!(b->eattrs->flags & EALF_HUGE) }); + mb_free(b); } int @@ -2089,7 +2086,6 @@ bgp_init_pending_tx(struct bgp_channel *c) bpp->lock = dom; bpp->pool = p; - bpp->sth = sth_new(p); bpp->c = c; bgp_init_bucket_table(bpp); @@ -2164,7 +2160,8 @@ bgp_free_pending_tx(struct bgp_channel *bc) HASH_WALK_END; HASH_FREE(c->bucket_hash); - sth_delete(c->sth); + sl_delete(c->bucket_slab); + c->bucket_slab = NULL; rp_free(c->pool); diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index dac6e84ea..202e78ba3 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -452,8 +452,7 @@ struct bgp_ptx_private { struct { BGP_PTX_PUBLIC; }; struct bgp_ptx_private **locked_at; - pool *pool; /* Pool for infrequent long-term blocks */ - stonehenge *sth; /* Bucket allocator */ + pool *pool; /* Resource pool for TX related allocations */ HASH(struct bgp_bucket) bucket_hash; /* Hash table of route buckets */ struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */ @@ -462,6 +461,7 @@ struct bgp_ptx_private { HASH(struct bgp_prefix) prefix_hash; /* Hash table of pending prefices */ slab *prefix_slab; /* Slab holding prefix nodes */ + slab *bucket_slab; /* Slab holding buckets to send */ char bmp; /* This is a fake ptx for BMP encoding */ };