]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Revert migration of route attributes and BGP TX cache to Stonehenge
authorMaria Matejka <mq@ucw.cz>
Wed, 19 Feb 2025 08:40:27 +0000 (09:40 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 19 Feb 2025 08:40:59 +0000 (09:40 +0100)
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.

lib/resource.h
lib/slab.c
nest/rt-attr.c
proto/bgp/attrs.c
proto/bgp/bgp.h

index 12b78851073693ebd9cc25b39a041e617501b2be..48bf1f9ba5355110e875add8ffcf387c91555a79 100644 (file)
@@ -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.
index 9351a06dcc79d29fe45749986a3ee5519891e5fb..409f4b33e76443380e66344c736609921d55bf69 100644 (file)
@@ -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; i<ARRAY_SIZE(stonehenge_sizes); i++)
-    if (size <= stonehenge_sizes[i])
-    {
-      if (!sth->s[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
index f4e09083e4e7769519ec6897b40ac8044e4b88b7..2e5560c0c2087a0bbd8eb4b7bcba15e5fb1b2cfd 100644 (file)
@@ -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; i<ARRAY_SIZE(ea_slab_sizes); i++)
+    if (sz <= ea_slab_sizes[i])
+    {
+      r = sl_alloc(ea_slab[i]);
+      break;
+    }
 
-  struct ea_storage *r = b.block;
+  int huge = r ? 0 : EALF_HUGE;;
+  if (huge)
+    r = mb_alloc(rta_pool, sz);
 
   ea_list_copy(r->l, 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; i<ARRAY_SIZE(ea_slab_sizes); i++)
+    ea_slab[i] = sl_new(rta_pool, ea_slab_sizes[i]);
+
   SPINHASH_INIT(rta_hash_table, RTAH, rta_pool, &global_work_list);
 
   rte_src_init();
index db654234343e3af0eb63c11ee0926c0672e6b262..ed4ded9d53eba120527d91a71d5aed555a774433 100644 (file)
@@ -1734,16 +1734,13 @@ bgp_get_bucket(struct bgp_ptx_private *c, ea_list *new)
   uint size = sizeof(struct bgp_bucket) + ea_size;
 
   /* Allocate the bucket */
-  sth_block blk = sth_alloc(c->sth, 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);
 
index dac6e84eaa415792c0347bb07cc909dc999c84ef..202e78ba39a0f4dc03b844e8dd06c07afac811e1 100644 (file)
@@ -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 */
 };