Phase: Pool API Modularization - Step 4: Extract pool_block_to_user_box.h
Extract 30 lines: hak_pool_block_to_user() + hak_pool_block_to_user_legacy() - New box: core/box/pool_block_to_user_box.h (helpers for block→user conversion) - Updated: pool_api.inc.h (add include, remove extracted functions) - Build: OK, bench_mid_large_mt_hakmem: 9.17M ops/s (baseline ~8M) - Risk: MINIMAL (simple extraction, no dependencies) Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -10,44 +10,9 @@
|
||||
#include "box/pool_stats_box.h" // Pool statistics & monitoring
|
||||
#include "box/pool_mid_desc_cache_box.h" // Mid descriptor TLS cache
|
||||
#include "box/pool_free_v1_box.h" // Pool v1 free implementation (L0-SplitBox + L1-FastBox/SlowBox)
|
||||
#include "box/pool_block_to_user_box.h" // Pool block to user pointer helpers
|
||||
#include <stdint.h>
|
||||
|
||||
// Thin helper to keep the hot path straight-line when converting a PoolBlock to
|
||||
// a user pointer. All sampling/stat updates remain here so the callers stay
|
||||
// small.
|
||||
static inline void* hak_pool_block_to_user(PoolBlock* b, int class_idx, uintptr_t site_id) {
|
||||
void* raw = (void*)b;
|
||||
AllocHeader* hdr = (AllocHeader*)raw;
|
||||
mid_set_header(hdr, g_class_sizes[class_idx], site_id);
|
||||
void* user = (char*)raw + HEADER_SIZE;
|
||||
mid_page_inuse_inc(raw);
|
||||
t_pool_rng ^= t_pool_rng << 13;
|
||||
t_pool_rng ^= t_pool_rng >> 17;
|
||||
t_pool_rng ^= t_pool_rng << 5;
|
||||
if ((t_pool_rng & ((1u << g_count_sample_exp) - 1u)) == 0u) {
|
||||
g_pool.hits[class_idx]++;
|
||||
}
|
||||
pagefault_telemetry_touch(PF_BUCKET_MID, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
// Legacy inline conversion used when v2 helper is disabled.
|
||||
static inline void* hak_pool_block_to_user_legacy(PoolBlock* b, int class_idx, uintptr_t site_id) {
|
||||
void* raw = (void*)b;
|
||||
AllocHeader* hdr = (AllocHeader*)raw;
|
||||
mid_set_header(hdr, g_class_sizes[class_idx], site_id);
|
||||
void* user = (char*)raw + HEADER_SIZE;
|
||||
mid_page_inuse_inc(raw);
|
||||
t_pool_rng ^= t_pool_rng << 13;
|
||||
t_pool_rng ^= t_pool_rng >> 17;
|
||||
t_pool_rng ^= t_pool_rng << 5;
|
||||
if ((t_pool_rng & ((1u << g_count_sample_exp) - 1u)) == 0u) {
|
||||
g_pool.hits[class_idx]++;
|
||||
}
|
||||
pagefault_telemetry_touch(PF_BUCKET_MID, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
static inline void* hak_pool_try_alloc_v2_impl(size_t size, uintptr_t site_id) {
|
||||
// Debug: IMMEDIATE output to verify function is called
|
||||
static int first_call = 1;
|
||||
|
||||
Reference in New Issue
Block a user