]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Slab: Remove fake slab
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Tue, 17 Dec 2024 14:34:56 +0000 (15:34 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 19 Feb 2025 08:44:22 +0000 (09:44 +0100)
From the beginning, there is a years-old implementation of a slab
not actually being a slab, just transparently passing all requests
to malloc and free. We don't need that anymore, we have different
methods now to determine whether the problem is the allocator or
something else, and as we are going to change the slab API anyway,
together with some behavioral updates, having a fake slab is just
an anachronism.

lib/slab.c

index 409f4b33e76443380e66344c736609921d55bf69..79d2a5e9bd0aa62c8127e3216928e8a895b49bb7 100644 (file)
@@ -34,7 +34,6 @@
 #include "lib/string.h"
 #include "lib/tlists.h"
 
-#undef FAKE_SLAB       /* Turn on if you want to debug memory allocations */
 
 #ifdef DEBUGGING
 #define POISON         /* Poison all regions after they are freed */
@@ -45,108 +44,6 @@ static void slab_dump(struct dump_request *dreq, resource *r);
 static resource *slab_lookup(resource *r, unsigned long addr);
 static struct resmem slab_memsize(resource *r);
 
-#ifdef FAKE_SLAB
-
-/*
- *  Fake version used for debugging.
- */
-
-struct slab {
-  resource r;
-  uint size;
-  list objs;
-};
-
-static struct resclass sl_class = {
-  "FakeSlab",
-  sizeof(struct slab),
-  slab_free,
-  slab_dump,
-  NULL,
-  slab_memsize
-};
-
-struct sl_obj {
-  node n;
-  max_align_t data_align[0];
-  byte data[0];
-};
-
-slab *
-sl_new(pool *p, uint size)
-{
-  slab *s = ralloc(p, &sl_class);
-  s->size = size;
-  init_list(&s->objs);
-  return s;
-}
-
-void *
-sl_alloc(slab *s)
-{
-  struct sl_obj *o = xmalloc(sizeof(struct sl_obj) + s->size);
-
-  add_tail(&s->objs, &o->n);
-  return o->data;
-}
-
-void *
-sl_allocz(slab *s)
-{
-  void *obj = sl_alloc(s);
-  memset(obj, 0, s->size);
-  return obj;
-}
-
-void
-sl_free(void *oo)
-{
-  SKIP_BACK_DECLARE(struct sl_obj, o, data, oo);
-
-  rem_node(&o->n);
-  xfree(o);
-}
-
-static void
-slab_free(resource *r)
-{
-  slab *s = (slab *) r;
-  struct sl_obj *o, *p;
-
-  for(o = HEAD(s->objs); p = (struct sl_obj *) o->n.next; o = p)
-    xfree(o);
-}
-
-static void
-slab_dump(resource *r, unsigned indent UNUSED)
-{
-  slab *s = (slab *) r;
-  int cnt = 0;
-  struct sl_obj *o;
-
-  WALK_LIST(o, s->objs)
-    cnt++;
-  debug("(%d objects per %d bytes)\n", cnt, s->size);
-}
-
-static struct resmem
-slab_memsize(resource *r)
-{
-  slab *s = (slab *) r;
-  size_t cnt = 0;
-  struct sl_obj *o;
-
-  WALK_LIST(o, s->objs)
-    cnt++;
-
-  return (struct resmem) {
-    .effective = cnt * s->size,
-    .overhead = ALLOC_OVERHEAD + sizeof(struct slab) + cnt * ALLOC_OVERHEAD,
-  };
-}
-
-
-#else
 
 /*
  *  Real efficient version.
@@ -459,5 +356,3 @@ slab_lookup(resource *r, unsigned long a)
       return r;
   return NULL;
 }
-
-#endif