Commit Graph

6 Commits

Author SHA1 Message Date
4ef0171bc0 feat: Add ACE allocation failure tracing and debug hooks
This commit introduces a comprehensive tracing mechanism for allocation failures within the Adaptive Cache Engine (ACE) component. This feature allows for precise identification of the root cause for Out-Of-Memory (OOM) issues related to ACE allocations.

Key changes include:
- **ACE Tracing Implementation**:
  - Added  environment variable to enable/disable detailed logging of allocation failures.
  - Instrumented , , and  to distinguish between "Threshold" (size class mismatch), "Exhaustion" (pool depletion), and "MapFail" (OS memory allocation failure).
- **Build System Fixes**:
  - Corrected  to ensure  is properly linked into , resolving an  error.
- **LD_PRELOAD Wrapper Adjustments**:
  - Investigated and understood the  wrapper's behavior under , particularly its interaction with  and  checks.
  - Enabled debugging flags for  environment to prevent unintended fallbacks to 's  for non-tiny allocations, allowing comprehensive testing of the  allocator.
- **Debugging & Verification**:
  - Introduced temporary verbose logging to pinpoint execution flow issues within  interception and  routing. These temporary logs have been removed.
  - Created  to facilitate testing of the tracing features.

This feature will significantly aid in diagnosing and resolving allocation-related OOM issues in  by providing clear insights into the failure pathways.
2025-12-01 16:37:59 +09:00
0bc33dc4f5 Phase 9-2: Remove Legacy Backend & Unify to Shared Pool (50M ops/s)
- Removed Legacy Backend fallback; Shared Pool is now the sole backend.
- Removed Soft Cap limit in Shared Pool to allow full memory management.
- Implemented EMPTY slab recycling with batched meta->used decrement in remote drain.
- Updated tiny_free_local_box to return is_empty status for safe recycling.
- Fixed race condition in release path by removing from legacy list early.
- Achieved 50.3M ops/s in WS8192 benchmark (+200% vs baseline).
2025-12-01 13:47:23 +09:00
83e88210f2 Phase 9-2: Disable Legacy backend by default (Shared Pool unification)
Implementation:
- 3-mode control via HAKMEM_TINY_SS_SHARED env var
  - 0: Legacy only
  - 1: Shared Pool + Legacy fallback
  - 2: Shared Pool only (DEFAULT)
- Mode 2 returns NULL on failure (no Legacy fallback)
- 'Reversible box' design - can switch back via env var

Results:
-  Legacy backend cleanly disabled
-  No shared_fail→legacy in Mode 2
-  Env var switching verified

Known Issues:
- TLS_SLL_DUP remains in Shared Pool backend (cls=5, 141 pointers)
- This is a Shared Pool backend internal issue, not Legacy backend
- Phase 9-3 will address root cause

Box Theory Compliance:
- Single Responsibility: Shared Pool only manages state
- Clear Contract: 3 modes clearly defined
- Observable: Debug logs show mode selection
- Composable: Instant env var switching

Performance:
- Some benchmarks may be slower (user approved)
- Stability prioritized over performance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 09:27:08 +09:00
d5645ec42d Add: Allocation path tracking for debugging
Added HAK_RET_ALLOC_BLOCK_TRACED macro with path identifiers:
- ALLOC_PATH_BACKEND (1): SuperSlab backend allocation
- ALLOC_PATH_TLS_POP (2): TLS SLL pop
- ALLOC_PATH_CARVE (3): Linear carve
- ALLOC_PATH_FREELIST (4): Freelist pop
- ALLOC_PATH_HOTMAG (5): Hot magazine
- ALLOC_PATH_FASTCACHE (6): Fast cache
- ALLOC_PATH_BUMP (7): Bump allocator
- ALLOC_PATH_REFILL (8): Refill/adoption

Usage:
  HAKMEM_ALLOC_PATH_TRACE=1 ./larson_hakmem ...

Logs first 20 allocations with path ID for debugging.

Updated SuperSlab backend to use traced version.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 05:38:30 +09:00
5582cbc22c Refactor: Unified allocation macros + header validation
1. Archive unused backend files (ss_legacy/unified_backend_box.c/h)
   - These files were not linked in the build
   - Moved to archive/ to reduce confusion

2. Created HAK_RET_ALLOC_BLOCK macro for SuperSlab allocations
   - Replaces superslab_return_block() function
   - Consistent with existing HAK_RET_ALLOC pattern
   - Single source of truth for header writing
   - Defined in hakmem_tiny_superslab_internal.h

3. Added header validation on TLS SLL push
   - Detects blocks pushed without proper header
   - Enabled via HAKMEM_TINY_SLL_VALIDATE_HDR=1 (release)
   - Always on in debug builds
   - Logs first 10 violations with backtraces

Benefits:
- Easier to track allocation paths
- Catches header bugs at push time
- More maintainable macro-based design

Note: Larson bug still reproduces - header corruption occurs
before push validation can catch it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 05:37:24 +09:00
6ac6f5ae1b Refactor: Split hakmem_tiny_superslab.c + unified backend exit point
Major refactoring to improve maintainability and debugging:

1. Split hakmem_tiny_superslab.c (1521 lines) into 7 focused files:
   - superslab_allocate.c: SuperSlab allocation/deallocation
   - superslab_backend.c: Backend allocation paths (legacy, shared)
   - superslab_ace.c: ACE (Adaptive Cache Engine) logic
   - superslab_slab.c: Slab initialization and bitmap management
   - superslab_cache.c: LRU cache and prewarm cache management
   - superslab_head.c: SuperSlabHead management and expansion
   - superslab_stats.c: Statistics tracking and debugging

2. Created hakmem_tiny_superslab_internal.h for shared declarations

3. Added superslab_return_block() as single exit point for header writing:
   - All backend allocations now go through this helper
   - Prevents bugs where headers are forgotten in some paths
   - Makes future debugging easier

4. Updated Makefile for new file structure

5. Added header writing to ss_legacy_backend_box.c and
   ss_unified_backend_box.c (though not currently linked)

Note: Header corruption bug in Larson benchmark still exists.
Class 1-6 allocations go through TLS refill/carve paths, not backend.
Further investigation needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 05:13:04 +09:00