summaryrefslogtreecommitdiffstats
path: root/lib/id_alloc.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* *: remove PRI[udx](8|16|32)David Lamparter2020-07-141-7/+4
| | | | | | | | | | | These are completely pointless and break coccinelle string replacements. Scripted commit, idempotent to running: ``` python3 tools/stringmangle.py --pri8-16-32 `git ls-files | egrep '\.[ch]$'` ``` Signed-off-by: David Lamparter <equinox@diac24.net>
* *: config.h or zebra.h is the first #includeDavid Lamparter2019-06-131-0/+4
| | | | | | | | This is mostly relevant for Solaris, where config.h sets up some #define that affect overall header behaviour, so it needs to be before anything else. Signed-off-by: David Lamparter <equinox@diac24.net>
* libs: rename two id_alloc macros to resolve bsd conflictMark Stapp2018-11-141-4/+4
| | | | | | | Two of the macros in lib/id_alloc had conflicts on some platforms; rename them to be unique. Signed-off-by: Mark Stapp <mjs@voltanet.io>
* lib: Implement an allocator for 32 bit ID numbersMitch Skiba2018-11-091-0/+406
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>