- Root cause: header-based class indexing (HEADER_CLASSIDX=1) wrote a 1-byte header during allocation, but linear carve/refill and initial slab capacity still used bare class block sizes. This mismatch could overrun slab usable space and corrupt freelists, causing reproducible SEGV at ~100k iters. Changes - Superslab: compute capacity with effective stride (block_size + header for classes 0..6; class7 remains headerless) in superslab_init_slab(). Add a debug-only bound check in superslab_alloc_from_slab() to fail fast if carve would exceed usable bytes. - Refill (non-P0 and P0): use header-aware stride for all linear carving and TLS window bump operations. Ensure alignment/validation in tiny_refill_opt.h also uses stride, not raw class size. - Drain: keep existing defense-in-depth for remote sentinel and sanitize nodes before splicing into freelist (already present). Notes - This unifies the memory layout across alloc/linear-carve/refill with a single stride definition and keeps class7 (1024B) headerless as designed. - Debug builds add fail-fast checks; release builds remain lean. Next - Re-run Tiny benches (256/1024B) in debug to confirm stability, then in release. If any remaining crash persists, bisect with HAKMEM_TINY_P0_BATCH_REFILL=0 to isolate P0 batch carve, and continue reducing branch-miss as planned.
37 lines
962 B
C
37 lines
962 B
C
#ifndef POOL_TLS_H
|
|
#define POOL_TLS_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// Pool size classes (8KB - 52KB)
|
|
#define POOL_SIZE_CLASSES 7
|
|
extern const size_t POOL_CLASS_SIZES[POOL_SIZE_CLASSES];
|
|
|
|
// Public API (Box 1)
|
|
void* pool_alloc(size_t size);
|
|
void pool_free(void* ptr);
|
|
void pool_thread_init(void);
|
|
void pool_thread_cleanup(void);
|
|
|
|
// Pre-warm TLS cache (Phase 1.5b - call once at thread init)
|
|
void pool_tls_prewarm(void);
|
|
|
|
// Internal API (for Box 2 only)
|
|
void pool_install_chain(int class_idx, void* chain, int count);
|
|
int pool_get_refill_count(int class_idx);
|
|
|
|
// Remote queue (cross-thread free) API — Phase 1.5c
|
|
int pool_remote_push(int class_idx, void* ptr, int owner_tid);
|
|
int pool_remote_drain_light(int class_idx);
|
|
|
|
// Feature flags
|
|
#define POOL_USE_HEADERS 1 // 1-byte headers for O(1) free
|
|
|
|
#if POOL_USE_HEADERS
|
|
#define POOL_MAGIC 0xb0 // Different from Tiny (0xa0) for safety
|
|
#define POOL_HEADER_SIZE 1
|
|
#endif
|
|
|
|
#endif // POOL_TLS_H
|