Skip to content
Permalink
Browse files

lib: Implement an allocator for 32 bit ID numbers

This commit introduces lib/id_alloc, which has facilities for both an ID number
allocator, and less efficient ID holding pools. The pools are meant to be a
temporary holding area for ID numbers meant to be re-used, and are implemented
as a linked-list stack.

The allocator itself is much more efficient with memory. Based on sizeof
values on my 64 bit desktop, the allocator requires around 155 KiB per
million IDs tracked.

IDs are ultimately tracked in a bit-map split into many "pages." The
allocator tracks a list of pages that have free bits, and which sections
of each page have free IDs, so there isn't any scanning required to find
a free ID. (The library utility ffs, or "Find First Set," is generally a
single CPU instruction.) At the moment, totally empty pages will not be
freed, so the memory utilization of this allocator will remain at the
high water mark.

The initial intended use case is for BGP's TX Addpath IDs to be pulled
from an allocator that tracks which IDs are in use, rather than a free
running counter.  The allocator reserves ID #0 as a sentinel value for
an invalid ID numbers, and BGP will want ID #1 reserved as well. To
support this, the allocator allows for IDs to be explicitly reserved,
though be aware this is only practical to use with low numbered IDs
because the allocator must allocate pages in order.

Signed-off-by Mitchell Skiba <mskiba@amazon.com>
  • Loading branch information...
mitch-skiba committed May 17, 2018
1 parent 4c056cf commit a94eca0968d914d58dff819c2411542377f56bae
Showing with 703 additions and 0 deletions.
  1. +406 −0 lib/id_alloc.c
  2. +90 −0 lib/id_alloc.h
  3. +2 −0 lib/lib_errors.h
  4. +2 −0 lib/subdir.am
  5. +193 −0 tests/lib/test_idalloc.c
  6. +6 −0 tests/lib/test_idalloc.py
  7. +4 −0 tests/subdir.am
Oops, something went wrong.

0 comments on commit a94eca0

Please sign in to comment.
You can’t perform that action at this time.