Purpose: Set the library's widths, sizes and optional modules for your target. Know which of them derive from others and are never yours to set. Scope: include/mmgr.h, deps/embedded_types/include/, CMakeLists.txt Author: dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m Date: 2026-08-30
Nothing here changes at runtime. Every value below is a preprocessor define with a default: you set only what you change. The last section is the exception: those are CMake options and never defines.
These come from embedded_types, not from MMgr, and carry its prefix.
| knob | default | what it changes |
|---|---|---|
| EMBED_WORD_BITS | derived from UINTPTR_MAX | the SWAR carrier and embed_word. 64, 32 or 16 |
| EMBED_INDEX_BITS | 32, or EMBED_WORD_BITS if narrower | the type of an offset into a region |
An EMBED_WORD_BITS narrower than the machine does not make anything faster: it makes the scanner answer for fewer bytes per load. It exists to let a wide host exercise a narrow machine's code paths. See Doing eight bytes at a time.
embed_types.h carries static asserts that police the combination; idx16 is the environment that exists to reach them.
No knob sets a size here. The size is in the declaration: ParsMemoriaeInternae(work, 4096) states the extent where the storage exists. The pool asserts its sizeof against the count it gets, so the two cannot disagree.
| knob | default | what it changes |
|---|---|---|
| MMGR_ALIGN_BYTES | 16 | alignment every pool declaration puts on its storage |
| MMGR_CARCER_ALIGN | sizeof(embed_word) | derived. The alignment every cell is passed out at |
| MMGR_EXTRAM_ATTR | empty | placement an external pool carries. The port supplies it |
This page names MMGR_EXTRAM_ATTR, and the port fills it, because which section a part puts external memory in is the part's business. A build that enables external memory and leaves this empty gets pools placed wherever the linker puts an ordinary one, and nothing diagnoses that.
These are the numbers you change after you measure. Do not guess them. See Your first prison site for how to read the high-water marks.
| knob | default | what it changes |
|---|---|---|
| MMGR_CARCER_OWNERS | 128 | the max owners a program's owner table holds |
| MMGR_MOVABLE_SETTLE_PERCENT | 25 | the fragmentation at which a cellblock's mover sorts |
| MMGR_MOVABLE_READ_MS | 100 | the milliseconds between the mover's readings |
| MMGR_MOVABLE_QUIET_READINGS | 3 | the readings in a row of low occupancy before it locks a turnstile |
| MMGR_MOVABLE_BACKOFF_MAX_MS | 25600 | the longest it waits after a sort it backed off from |
| MMGR_MOVABLE_IDLE_MAX_MS | 1000 | the longest it waits over a settled cellblock that no pass touched |
| MMGR_CARCER_REGIONS | 0 | regions of the temporary tier, one per thread place modulo this; 0 is one shared stack |
| MMGR_CARCER_REGION_BYTES | 0 | bytes of each region, a multiple of MMGR_CARCER_ALIGN |
| MMGR_CARCER_LARGE_REGION_BYTES | 0 | bytes of the one region every thread shares for a take over a region's room; 0 refuses that take |
Over a settled cellblock that no pass touched, each reading doubles the mover's wait up to MMGR_MOVABLE_IDLE_MAX_MS. A pass or a rise brings the next reading back to MMGR_MOVABLE_READ_MS.
The regions lie at the top of the cellblock, and the gap lies below them. A take goes to the region that embed_thread_place() selects, and a give goes to the region that holds the cell. The host defines embed_thread_place beside embed_clock_ns.
Every context that reaches a cellblock shares it, with no switch and no lock. Every boundary, every cell's claim and every count is an atomic word from embedded_types, moved in one step each, and no context waits for another. The same build serves a host thread, a part's task and a GPU thread.
The CellOwner record in the program's owner table retains an owner's own counts, its bytes in use and its peak. MMGR_OWNERS positions the table once, as data, from the program's list of owners. It also defines each owner's const pointer into it, which the owner's module names on every take, give and growth. A list longer than MMGR_CARCER_OWNERS fails the build. See Who owns what.
| knob | default | what it changes |
|---|---|---|
| MMGR_DEBUG_CHECKS | 0 | compiles in the checks, and selects the trapping assert |
| MMGR_ASSERT(cond, msg) | a type-checked no-op | what a broken precondition does |
The default MMGR_ASSERT retains its expression type-checked with sizeof and then discards it: it cannot rot and costs nothing.
MMGR_DEBUG_CHECKS=1 is all it takes to trap: test/support/mmgr_host_traps.h then supplies MMGR_ASSERT. That form writes a report to stderr that names the expectation, the file and the line, and then calls abort(). That report is the checks environment entire. Define MMGR_ASSERT yourself before you include the header, and the library uses neither form. A target with no stderr and no abort() wants that shape. See How failure is reported.
| knob | default | what it changes |
|---|---|---|
| MMGR_ENABLE_DMA | 0 | compiles memoriam_praetereo/, included from mmgr.h |
| MMGR_ENABLE_EXTRAM | 0 | compiles memoria_externa/, included from mmgr.h |
With these off, the modules are absent entirely, with no stubs. The build skips their test suites with a CMake status message and does not drop them silently.
The module reads these only where MMGR_ENABLE_DMA is on. None of these has a value that is right for every part, and a build answers them. From CMake, pass them as one list in MMGR_PRAET_KNOBS, which reaches the library and every suite over it:
| knob | default when unset | what it changes |
|---|---|---|
| PRAET_CHANNELS | 8 | logical channels one context carries |
| PRAET_SETTLE_MICROS | 0 | microseconds the engine takes to come up after an attach |
| PRAET_KEEPALIVE_MICROS | 1000 | microseconds a moving channel may go unkicked before it stalls |
| PRAET_RECOVERY | 0 | whether a stalled transfer can be backed out or scrubbed |
| EMBED_CLOCK_HZ | 1000000 | ticks per second of the clock the deadlines are scaled from |
| EMBED_CLOCK_SOURCE | derived from the architecture | EMBED_CLOCK_CALLER or EMBED_CLOCK_OWN |
| EMBED_CLOCK_CORE | EMBED_CLOCK_CORE_DEFAULT | the core a pinned timer runs on, read only on EMBED_CLOCK_OWN |
Each unset knob takes its default and raises a warning that names it. After the build reads every knob, praet_iudex.h stops the build once if any of them was unset. Define MMGR_ACCEPT_DEFAULTS to build on the defaults and retain the warnings as the record.
| knob | default | what it changes |
|---|---|---|
| MMGR_STR_MAX | see mmgr_string_shim.h | the read cap the shim's str* replacements use |
| MMGR_RING_LOCULI | 8 | loculi this build reserves |
| MMGR_RING_LOCULI_MAX | EMBED_WORD_BITS | loculi a mask can address, one bit per loculus in a machine word |
| MMGR_RING_WORDS | 40 | size of the ring storage a caller declares, in size_t units |
| MMGR_SIEVE_ROWS | 1 | needle offsets the search sieve tests per candidate word |
| MMGR_FIND_CHAIN_MAX | SIZE_MAX | longest haystack a one or two byte needle is settled by mask chain |
MMGR_RING_LOCULI_MAX derives from the word and is not a knob, and it is EMBED_WORD_BITS and not a fixed 32. The free and busy masks are one embed_word each, one bit per loculus (src/memoria_anularis/memoria_anularis.c:308-309), and the ceiling moves with the word width. A build that declares more loculi than that fails the static assert in src/memoria_anularis/memoria_anularis.h:84.
The byte-frequency profile is a CMake option that takes a value, in place of a set of defines: -DMMGR_ANCORAE_FORMA=english, and likewise uri, inet, route or generic. One profile is one translation unit. src/impensa_ancorae_acus/CMakeLists.txt:7-15 selects the single source that carries the table, and the four not chosen are not in the image at all. It defaults to generic. The wrong one costs speed and never correctness: the search still finds what is there. See Anchor cost: where a search starts.
MMGR_FIND_CHAIN_MAX defaults to no limit, which folds its test away: read_cap <= SIZE_MAX holds for every size_t. A default build emits no comparison. A mask chain settles a one or two byte needle. It does one broadcast per needle byte and decides every start position in the word at once, with nothing to verify. The sieve does not run; it exists to find a rare byte in a long needle and prove the rest once. Measured with a two byte needle, cycles for the whole call:
| n | 8 | 64 | 2048 |
|---|---|---|---|
| Xtensa chain | 124 | 489 | 13391 |
| Xtensa sieve | 187 | 607 | 15494 |
| RISC-V chain | 124 | 488 | 13393 |
| RISC-V sieve | 219 | 680 | 17059 |
The chain wins at every length on both parts: nothing needs a change. The library retains the knob because a measurement proves nothing about an unmeasured length; zero sends every needle through the sieve.
A find that ignores case always goes through the sieve: the chain compares raw bytes.
These come from embedded_types as well.
| knob | default | what it changes |
|---|---|---|
| EMBED_BIG_ENDIAN | derived from __BYTE_ORDER__ | the host's byte order |
| EMBED_FAST_UNALIGNED_LOAD | derived from __ARM_FEATURE_UNALIGNED etc | whether a word load takes any address |
| EMBED_INLINE | static inline, plus always_inline where available | how hot entries are inlined |
| EMBED_FLATTEN | __attribute__((flatten)) where available, else nothing | a caller's lever to inline an entry |
EMBED_FLATTEN is for a caller and never for the library. Put it on the one hot function that reaches an entry, and the compiler inlines the entry into it. The inliner otherwise declines to do that on size, even under link-time optimization. Measured on an ESP32-S3, cellul.len over eight bytes is 112 cycles as a call and 80 inlined, a third of the work at that length.
The page What it costs has the table and the caveats. It needs LTO, and it costs the walk's code at every site that takes it. A long scan amortizes the call and will not notice.
EMBED_FAST_UNALIGNED_LOAD is not whether an unaligned load compiles. Every target accepts one through a type that carries EMBED_RAW, which is EMBED_ALIGN(1) and EMBED_ALIAS. It is whether the hardware does it in one instruction, or the compiler assembles the word out of byte loads and shifts. Measured on a single such load: ARMv7-M emits one ldr, Xtensa twelve instructions, RISC-V eleven. A walk that needs the word at an offset of one takes the load where it is one instruction. Where it is a dozen, the walk derives it from the word already in hand.
It is not a statement about the family either. Cortex-M0 is ARMv6-M, has no unaligned access, and the macro reports it slow. The compiler answers through __ARM_FEATURE_UNALIGNED, which -mno-unaligned-access also turns off on a part that has it.
Every compiler conditional lives in embed_compiler_directives.h by policy: a new toolchain is one file to read. See Compilers, attributes and fallbacks.
These are build options and never preprocessor defines.
| option | default | what it does |
|---|---|---|
| MMGR_BUILD_TESTS | ON | build the unit and environment suites |
| MMGR_BUILD_BENCH | OFF | build the benchmarks |
| MMGR_WERROR | OFF | treat warnings as errors |
| MMGR_LTO | ON | link-time optimization, where the toolchain supports it |
The build also does one more thing you should know. MinSizeRel normally means -Os, and -Os declines to inline the small branch-free entries that are this library. The calls it saves space on are the calls that cost the max. The top-level CMakeLists.txt rewrites -Os to -O2 for that configuration. An embedded build that reaches for MinSizeRel wants small, not slow-and-small.