]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Attribute blocks are now allocated from slabs instead of malloc()
authorMaria Matejka <mq@ucw.cz>
Wed, 12 Oct 2022 16:04:39 +0000 (18:04 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 12 Oct 2022 16:04:39 +0000 (18:04 +0200)
lib/route.h
nest/rt-attr.c

index eae251e70bfbc35cd44256311832481b63928fb7..50e6244065aeb66be85a740d2149376452252469 100644 (file)
@@ -265,6 +265,7 @@ struct ea_storage {
 #define EALF_SORTED 1                  /* Attributes are sorted by code */
 #define EALF_BISECT 2                  /* Use interval bisection for searching */
 #define EALF_CACHED 4                  /* List is cached */
+#define EALF_HUGE   8                  /* List is too big to fit into slab */
 
 struct ea_class {
 #define EA_CLASS_INSIDE \
index 471209ee2cd5760b328eced48eae57df4d39866d..b41e56c2c779d9d6f1ae1b2fc28decb984c64c03 100644 (file)
@@ -182,6 +182,10 @@ DOMAIN(attrs) attrs_domain;
 
 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 struct idm src_ids;
@@ -1485,11 +1489,22 @@ ea_lookup(ea_list *o, int overlay)
     }
 
   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_ref(r->l);
 
-  r->l->flags |= EALF_CACHED;
+  r->l->flags |= EALF_CACHED | huge;
   r->hash_key = h;
   r->uc = 1;
 
@@ -1516,7 +1531,10 @@ ea_free_locked(struct ea_storage *a)
     a->next_hash->pprev_hash = a->pprev_hash;
 
   ea_list_unref(a->l);
-  mb_free(a);
+  if (a->l->flags & EALF_HUGE)
+    mb_free(a);
+  else
+    sl_free(a);
 }
 
 static void
@@ -1580,6 +1598,9 @@ rta_init(void)
 
   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();
   rte_src_init();
   ea_class_init();