Fix 1KB-8KB allocation gap: Close Tiny/Mid boundary
Problem: 1024B allocations fell through to mmap (1000x slowdown) - TINY_MAX_SIZE: 1023B (C7 usable size with 1-byte header) - MID_MIN_SIZE: 8KB (was too large) - Gap: 1KB-8KB → no allocator handled → mmap fallback → syscall hell Solution: Lower MID_MIN_SIZE to 1KB (ChatGPT recommendation) - Tiny: 0-1023B (header-based, C7 usable=1023B) - Mid: 1KB-32KB (closes gap, uses 8KB class for sub-8KB sizes) - Pool: 8KB-52KB (parallel, Pool takes priority) Results (bench_fixed_size 1024B, workset=128, 200K iterations): - Before: 82K ops/s (mmap flood: 1000+ syscalls/iter) - After: 489K ops/s (Mid allocator: ~30 mmap total) - Improvement: 6.0x faster ✅ - No hang: Completes in 0.4s (was timing out) ✅ Syscall reduction (1000 iterations): - mmap: 1029 → 30 (-97%) ✅ - munmap: 1003 → 3 (-99%) ✅ - mincore: 1000 → 1000 (unchanged, separate issue) Related: Phase 13-A (TinyHeapV2), workset=128 debug investigation 🤝 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
/**
|
||||
* hakmem_mid_mt.h
|
||||
*
|
||||
* Mid Range Multi-threaded Allocator (8-32KB)
|
||||
* Mid Range Multi-threaded Allocator (1-32KB)
|
||||
* mimalloc-style per-thread segment design for optimal MT performance
|
||||
*
|
||||
* Part of Hybrid Approach:
|
||||
* - ≤1KB: Tiny Pool (static optimization, P0 complete)
|
||||
* - 8-32KB: Mid MT (this module, mimalloc-style per-thread)
|
||||
* - ≥64KB: Large Pool (learning-based, ELO strategies)
|
||||
* - ≤1023B: Tiny Pool (header-based, C7 usable size)
|
||||
* - 1-32KB: Mid MT (this module, mimalloc-style per-thread)
|
||||
* - ≥64KB: Large Pool (learning-based, ELO strategies)
|
||||
*
|
||||
* Created: 2025-11-01
|
||||
* Goal: 46M → 100-120M ops/s (2.2-2.6x improvement)
|
||||
@ -34,7 +34,11 @@ extern "C" {
|
||||
#define MID_SIZE_CLASS_32K 2 // 32KB blocks
|
||||
#define MID_NUM_CLASSES 3 // Total number of size classes
|
||||
|
||||
#define MID_MIN_SIZE (8 * 1024) // 8KB
|
||||
// Phase 13: Close Tiny/Mid gap.
|
||||
// Tiny now handles up to 1023B (C7 usable size), so Mid must accept
|
||||
// 1KB-32KB. We keep size classes at 8/16/32KB; sub-8KB sizes use the
|
||||
// 8KB class with some internal slack.
|
||||
#define MID_MIN_SIZE (1024) // 1KB (was 8KB)
|
||||
#define MID_MAX_SIZE (32 * 1024) // 32KB
|
||||
#define MID_CHUNK_SIZE (4 * 1024 * 1024) // 4MB chunks (same as mimalloc segments)
|
||||
|
||||
|
||||
@ -23,7 +23,9 @@ int hak_is_initializing(void);
|
||||
|
||||
#define TINY_NUM_CLASSES 8
|
||||
#define TINY_SLAB_SIZE (64 * 1024) // 64KB per slab
|
||||
#define TINY_MAX_SIZE 1024 // Tiny handles up to 1024B (C7 headerless)
|
||||
// Phase E1-CORRECT: All Tiny classes use a 1-byte header.
|
||||
// C7 stride=1024B → usable 1023B (1024-1). 1024B は Mid allocator に委譲する。
|
||||
#define TINY_MAX_SIZE 1023 // Tiny handles up to 1023B (C7 usable size)
|
||||
|
||||
// ============================================================================
|
||||
// Size Classes
|
||||
|
||||
Reference in New Issue
Block a user