ChatGPT-guided Box theory refactoring (Phase A: Boundary only). Changes: - Created ss_slab_meta_box.h with 15 inline accessor functions - HOT fields (8): freelist, used, capacity (fast path) - COLD fields (6): class_idx, carved, owner_tid_low (init/debug) - Legacy (1): ss_slab_meta_ptr() for atomic ops - Migrated 14 direct slabs[] access sites across 6 files - hakmem_shared_pool.c (4 sites) - tiny_free_fast_v2.inc.h (1 site) - hakmem_tiny.c (3 sites) - external_guard_box.h (1 site) - hakmem_tiny_lifecycle.inc (1 site) - ss_allocation_box.c (4 sites) Architecture: - Zero overhead (static inline wrappers) - Single point of change for future layout optimizations - Enables Hot/Cold split (Phase C) without touching call sites - A/B testing support via compile-time flags Verification: - Build: ✅ Success (no errors) - Stability: ✅ All sizes pass (128B-1KB, 22-24M ops/s) - Behavior: Unchanged (thin wrapper, no logic changes) Next: Phase B (TLS Cache Merge, +12-18% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
108 lines
3.9 KiB
C
108 lines
3.9 KiB
C
#ifndef SS_SLAB_META_BOX_H
|
|
#define SS_SLAB_META_BOX_H
|
|
|
|
// ============================================================================
|
|
// Box: SlabMeta Access Layer (Phase 3d-A)
|
|
// ============================================================================
|
|
// Purpose: Encapsulate SuperSlab metadata field access
|
|
// Boundary: SuperSlab internal layout (slabs[] array)
|
|
// Benefits:
|
|
// - Single point of change for future layout optimizations
|
|
// - Enables Hot/Cold split without touching call sites
|
|
// - Supports A/B testing via compile-time flags
|
|
//
|
|
// Design: Thin inline wrappers (zero overhead, unchanged behavior)
|
|
// ============================================================================
|
|
|
|
#include "../superslab/superslab_types.h"
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// HOT field accessors (frequent access on alloc/free paths)
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Get freelist pointer (HOT field)
|
|
static inline void* ss_slab_meta_freelist_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].freelist;
|
|
}
|
|
|
|
// Set freelist pointer (HOT field)
|
|
static inline void ss_slab_meta_freelist_set(SuperSlab* ss, int slab_idx, void* ptr) {
|
|
ss->slabs[slab_idx].freelist = ptr;
|
|
}
|
|
|
|
// Get used count (HOT field)
|
|
static inline uint16_t ss_slab_meta_used_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].used;
|
|
}
|
|
|
|
// Set used count (HOT field)
|
|
static inline void ss_slab_meta_used_set(SuperSlab* ss, int slab_idx, uint16_t val) {
|
|
ss->slabs[slab_idx].used = val;
|
|
}
|
|
|
|
// Increment used count (HOT field, common operation)
|
|
static inline void ss_slab_meta_used_inc(SuperSlab* ss, int slab_idx) {
|
|
ss->slabs[slab_idx].used++;
|
|
}
|
|
|
|
// Decrement used count (HOT field, common operation)
|
|
static inline void ss_slab_meta_used_dec(SuperSlab* ss, int slab_idx) {
|
|
ss->slabs[slab_idx].used--;
|
|
}
|
|
|
|
// Get capacity (HOT field)
|
|
static inline uint16_t ss_slab_meta_capacity_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].capacity;
|
|
}
|
|
|
|
// Set capacity (HOT field, set once at init)
|
|
static inline void ss_slab_meta_capacity_set(SuperSlab* ss, int slab_idx, uint16_t val) {
|
|
ss->slabs[slab_idx].capacity = val;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// COLD field accessors (rare access: init, debug, stats)
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Get class_idx (COLD field)
|
|
static inline uint8_t ss_slab_meta_class_idx_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].class_idx;
|
|
}
|
|
|
|
// Set class_idx (COLD field, set once at init)
|
|
static inline void ss_slab_meta_class_idx_set(SuperSlab* ss, int slab_idx, uint8_t val) {
|
|
ss->slabs[slab_idx].class_idx = val;
|
|
}
|
|
|
|
// Get carved (COLD field)
|
|
static inline uint8_t ss_slab_meta_carved_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].carved;
|
|
}
|
|
|
|
// Set carved (COLD field)
|
|
static inline void ss_slab_meta_carved_set(SuperSlab* ss, int slab_idx, uint8_t val) {
|
|
ss->slabs[slab_idx].carved = val;
|
|
}
|
|
|
|
// Get owner_tid_low (COLD field, debug only)
|
|
static inline uint8_t ss_slab_meta_owner_tid_low_get(SuperSlab* ss, int slab_idx) {
|
|
return ss->slabs[slab_idx].owner_tid_low;
|
|
}
|
|
|
|
// Set owner_tid_low (COLD field, debug only)
|
|
static inline void ss_slab_meta_owner_tid_low_set(SuperSlab* ss, int slab_idx, uint8_t val) {
|
|
ss->slabs[slab_idx].owner_tid_low = val;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Legacy direct pointer access (for gradual migration)
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Get pointer to TinySlabMeta (for code that needs direct struct access)
|
|
// TODO Phase 3d-B: Migrate all users to field-specific accessors above
|
|
static inline TinySlabMeta* ss_slab_meta_ptr(SuperSlab* ss, int slab_idx) {
|
|
return &ss->slabs[slab_idx];
|
|
}
|
|
|
|
#endif // SS_SLAB_META_BOX_H
|