Add ss_fast_lookup() for O(1) SuperSlab lookup via mask
Replaces expensive hak_super_lookup() (registry hash lookup, 50-100 cycles) with fast mask-based lookup (~5-10 cycles) in free hot paths. Algorithm: 1. Mask pointer with SUPERSLAB_SIZE_MIN (1MB) - works for both 1MB and 2MB SS 2. Validate magic (SUPERSLAB_MAGIC) 3. Range check using ss->lg_size Applied to: - tiny_free_fast.inc.h: tiny_free_fast() SuperSlab path - tiny_free_fast_v2.inc.h: LARSON_FIX cross-thread check - front/malloc_tiny_fast.h: free_tiny_fast() LARSON_FIX path Note: Performance impact minimal with LARSON_FIX=OFF (default) since SuperSlab lookup is skipped entirely in that case. Optimization benefits LARSON_FIX=ON path for safe multi-threaded operation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -28,7 +28,7 @@
|
||||
#include "../hakmem_build_flags.h"
|
||||
#include "../hakmem_tiny_config.h" // For TINY_NUM_CLASSES
|
||||
#include "../hakmem_super_registry.h" // For cross-thread owner check
|
||||
#include "../superslab/superslab_inline.h" // For slab_index_for
|
||||
#include "../superslab/superslab_inline.h" // For ss_fast_lookup, slab_index_for (Phase 12)
|
||||
#include "../box/ss_slab_meta_box.h" // For ss_slab_meta_owner_tid_low_get
|
||||
#include "../box/free_remote_box.h" // For tiny_free_remote_box
|
||||
#include "tiny_unified_cache.h" // For unified_cache_pop_or_refill
|
||||
@ -159,8 +159,9 @@ static inline int free_tiny_fast(void* ptr) {
|
||||
}
|
||||
|
||||
if (__builtin_expect(g_larson_fix, 0)) {
|
||||
SuperSlab* ss = hak_super_lookup(base);
|
||||
if (ss && ss->magic == SUPERSLAB_MAGIC) {
|
||||
// Phase 12 optimization: Use fast mask-based lookup (~5-10 cycles vs 50-100)
|
||||
SuperSlab* ss = ss_fast_lookup(base);
|
||||
if (ss) {
|
||||
int slab_idx = slab_index_for(ss, base);
|
||||
if (__builtin_expect(slab_idx >= 0 && slab_idx < ss_slabs_capacity(ss), 1)) {
|
||||
uint32_t self_tid = tiny_self_u32_local();
|
||||
|
||||
Reference in New Issue
Block a user