Files
hakmem/CURRENT_TASK.md
Moe Charm (CI) 3a040a545a Refactor: Split monolithic hakmem_shared_pool.c into acquire/release modules
- Split core/hakmem_shared_pool.c into acquire/release modules for maintainability.
- Introduced core/hakmem_shared_pool_internal.h for shared internal API.
- Fixed incorrect function name usage (superslab_alloc -> superslab_allocate).
- Increased SUPER_REG_SIZE to 1M to support large working sets (Phase 9-2 fix).
- Updated Makefile.
- Verified with benchmarks.
2025-11-30 18:11:08 +09:00

3.0 KiB

Current Task: Phase 9-2 Refactoring (Complete)

Date: 2025-11-30 Status: COMPLETE (Phase 9-2 & Refactoring) Goal: SuperSlab Unified Management, Stability Fixes, and Code Refactoring


Phase 9-2 Achievements (Completed)

  1. Critical Fixes (Deadlock & OOM)

    • Deadlock: shared_pool_acquire_slab now releases alloc_lock before calling superslab_allocate (via sp_internal_allocate_superslab), preventing lock inversion with g_super_reg_lock.
    • OOM: Enabled HAKMEM_TINY_USE_SUPERSLAB=1 by default in hakmem_build_flags.h, ensuring fallback to Legacy Backend when Shared Pool hits soft cap.
  2. SuperSlab Management Unification

    • Unified Entry: sp_internal_allocate_superslab helper introduced to manage safe allocation flow.
    • Unified Free: remove_superslab_from_legacy_head implemented to safely remove pointers from legacy lists when freeing via Shared Pool.
  3. Code Refactoring (Split hakmem_shared_pool.c)

    • Split Strategy: Divided the monolithic core/hakmem_shared_pool.c (1400+ lines) into logical modules:
      • core/hakmem_shared_pool.c: Initialization, stats, and common helpers.
      • core/hakmem_shared_pool_acquire.c: Allocation logic (shared_pool_acquire_slab and Stage 0.5-3).
      • core/hakmem_shared_pool_release.c: Deallocation logic (shared_pool_release_slab).
      • core/hakmem_shared_pool_internal.h: Internal shared definitions and prototypes.
    • Makefile: Updated to compile and link the new files.
    • Cleanups: Removed unused "L0 Cache" experimental code and fixed incorrect function names (superslab_alloc -> superslab_allocate).

Next Phase Candidates (Handover from Phase 9-2)

1. Soft Cap (Policy) Tuning

  • Issue: Medium Working Sets (8192) hit the Shared Pool "Soft Cap" easily, causing frequent fallbacks and performance degradation.
  • Action: Review hakmem_policy.c and adjust tiny_cap or improve dynamic adjustment logic.

2. Fast Path Optimization

  • Issue: Small Working Sets (256) show 70-88% performance vs SysAlloc due to lock/call overhead. Refactoring caused a slight dip (15%), highlighting the need for optimization.
  • Action: Re-implement a lightweight L0 Cache or optimize the lock-free path in Shared Pool for hot-path performance. Consider inlining hot helpers again via header-only implementations if needed.

3. Legacy Backend Removal

  • Issue: Legacy Backend (g_superslab_heads) is still kept for fallback but causes complexity.
  • Action: Plan complete removal of g_superslab_heads, migrating all management to Shared Pool.

Current Status

  • Build: Passing (Clean build verified).
  • Benchmarks:
    • HAKMEM_TINY_SS_SHARED=1 (Normal): ~20.0 M ops/s (working, fallback active).
    • HAKMEM_TINY_SS_SHARED=2 (Strict): ~20.3 M ops/s (working, OOMs on soft cap as expected).
  • Pending: Selection of next focus area.