Mid-Large Phase 12 Complete + P0-5 Lock-Free Stage 2

**Phase 12 第1ラウンド完了** 
- 0.24M → 2.39M ops/s (8T, **+896%**)
- SEGFAULT → Zero crashes (**100% → 0%**)
- futex: 209 → 10 calls (**-95%**)

**P0-5: Lock-Free Stage 2 (Slot Claiming)**
- Atomic SlotState: `_Atomic SlotState state`
- sp_slot_claim_lockfree(): CAS-based UNUSED→ACTIVE transition
- acquire_slab() Stage 2: Lock-free claiming (mutex only for metadata)
- Result: 2.34M → 2.39M ops/s (+2.5% @ 8T)

**Implementation**:
- core/hakmem_shared_pool.h: Atomic SlotState definition
- core/hakmem_shared_pool.c:
  - sp_slot_claim_lockfree() (+40 lines)
  - Atomic helpers: sp_slot_find_unused/mark_active/mark_empty
  - Stage 2 lock-free integration
- Verified via debug logs: STAGE2_LOCKFREE claiming works

**Reports**:
- MID_LARGE_P0_PHASE_REPORT.md: P0-0 to P0-4 comprehensive summary
- MID_LARGE_FINAL_AB_REPORT.md: Complete Phase 12 A/B comparison (17KB)
  - Performance evolution table
  - Lock contention analysis  - Lessons learned
  - File inventory

**Tiny Baseline Measurement** 📊
- System malloc: 82.9M ops/s (256B)
- HAKMEM:        8.88M ops/s (256B)
- **Gap: 9.3x slower** (target for next phase)

**Next**: Tiny allocator optimization (drain interval, front cache, perf profile)

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-14 16:51:53 +09:00
parent 29fefa2018
commit ec453d67f2
4 changed files with 1489 additions and 62 deletions

View File

@ -40,10 +40,11 @@ typedef enum {
} SlotState;
// Per-slot metadata
// P0-5: state is atomic for lock-free claiming
typedef struct {
SlotState state;
uint8_t class_idx; // Valid when state != SLOT_UNUSED (0-7)
uint8_t slab_idx; // SuperSlab-internal index (0-31)
_Atomic SlotState state; // Atomic for lock-free CAS (UNUSED→ACTIVE)
uint8_t class_idx; // Valid when state != SLOT_UNUSED (0-7)
uint8_t slab_idx; // SuperSlab-internal index (0-31)
} SharedSlot;
// Per-SuperSlab metadata for slot management
@ -56,6 +57,31 @@ typedef struct SharedSSMeta {
struct SharedSSMeta* next; // For free list linking
} SharedSSMeta;
// ============================================================================
// P0-4: Lock-Free Free Slot List (LIFO Stack)
// ============================================================================
// Free slot node for lock-free linked list
typedef struct FreeSlotNode {
SharedSSMeta* meta; // Which SuperSlab metadata
uint8_t slot_idx; // Which slot within that SuperSlab
struct FreeSlotNode* next; // Next node in LIFO stack
} FreeSlotNode;
// Lock-free per-class free slot list (LIFO stack with atomic head)
typedef struct {
_Atomic(FreeSlotNode*) head; // Atomic stack head pointer
} LockFreeFreeList;
// Node pool for lock-free allocation (avoid malloc/free)
#define MAX_FREE_NODES_PER_CLASS 512 // Pre-allocated nodes per class
extern FreeSlotNode g_free_node_pool[TINY_NUM_CLASSES_SS][MAX_FREE_NODES_PER_CLASS];
extern _Atomic uint32_t g_node_alloc_index[TINY_NUM_CLASSES_SS];
// ============================================================================
// Legacy Free Slot List (for comparison, will be removed after P0-4)
// ============================================================================
// Free slot entry for per-class reuse lists
typedef struct {
SharedSSMeta* meta; // Which SuperSlab metadata
@ -87,7 +113,10 @@ typedef struct SharedSuperSlabPool {
uint32_t lru_count;
// ========== Phase 12: SP-SLOT Management ==========
// Per-class free slot lists for efficient reuse
// P0-4: Lock-free per-class free slot lists (atomic LIFO stacks)
LockFreeFreeList free_slots_lockfree[TINY_NUM_CLASSES_SS];
// Legacy: Per-class free slot lists (mutex-protected, for comparison)
FreeSlotList free_slots[TINY_NUM_CLASSES_SS];
// SharedSSMeta array for all SuperSlabs in pool