2025-11-05 12:31:14 +09:00
|
|
|
// tiny_refill.h - Refill Boundary box (inline helpers)
|
|
|
|
|
#pragma once
|
|
|
|
|
#include <stdatomic.h>
|
|
|
|
|
#include "hakmem_tiny_superslab.h"
|
Phase 4c: Add master trace control (HAKMEM_TRACE)
Add unified trace control that allows enabling specific trace modules
using comma-separated values or "all" to enable everything.
New file: core/hakmem_trace_master.h
- HAKMEM_TRACE=all: Enable all trace modules
- HAKMEM_TRACE=ptr,refill,free,mailbox: Enable specific modules
- HAKMEM_TRACE_LEVEL=N: Set trace verbosity (1-3)
- hak_trace_check(): Check if module should enable tracing
Available trace modules:
ptr, refill, superslab, ring, free, mailbox, registry
Priority order:
1. HAKMEM_QUIET=1 → suppress all
2. Specific module ENV (e.g., HAKMEM_PTR_TRACE=1)
3. HAKMEM_TRACE=module1,module2
4. Default → disabled
Updated files:
- core/tiny_refill.h: Use hak_trace_check() for refill tracing
- core/box/mailbox_box.c: Use hak_trace_check() for mailbox tracing
Performance: No regression (72.9M ops/s)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 16:08:44 +09:00
|
|
|
#include "hakmem_trace_master.h" // Phase 4c: Master trace control
|
2025-11-05 12:31:14 +09:00
|
|
|
#include "slab_handle.h"
|
|
|
|
|
#include "tiny_sticky.h"
|
2025-11-07 01:27:04 +09:00
|
|
|
#include "tiny_ready.h"
|
|
|
|
|
#include "box/mailbox_box.h"
|
|
|
|
|
#include "tiny_remote_bg.h" // Background remote-drain step (best-effort)
|
|
|
|
|
#include "tiny_ready_bg.h" // Ready aggregator (mailbox→ready hint)
|
|
|
|
|
#include "tiny_route.h" // Route Fingerprint (Box boundary tracing)
|
2025-11-05 12:31:14 +09:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
// External helpers from main TU
|
|
|
|
|
static inline uint32_t tiny_self_u32(void);
|
|
|
|
|
static inline void tiny_tls_bind_slab(TinyTLSSlab* tls, SuperSlab* ss, int slab_idx);
|
|
|
|
|
|
|
|
|
|
// Forward decls in main TU
|
|
|
|
|
static inline uintptr_t hot_slot_pop(int class_idx);
|
|
|
|
|
static inline uintptr_t bench_pub_pop(int class_idx);
|
|
|
|
|
static inline SuperSlab* slab_entry_ss(uintptr_t ent);
|
|
|
|
|
static inline int slab_entry_idx(uintptr_t ent);
|
|
|
|
|
|
2025-11-26 14:45:26 +09:00
|
|
|
// Mailbox/Ready consumption always allowed (ENV gate removed)
|
|
|
|
|
static inline int tiny_mail_ready_allowed(void) { return 1; }
|
2025-11-07 18:07:48 +09:00
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
// Registry scan window (ENV: HAKMEM_TINY_REG_SCAN_MAX, default 256)
|
|
|
|
|
static inline int tiny_reg_scan_max(void) {
|
|
|
|
|
static int v = -1;
|
|
|
|
|
if (__builtin_expect(v == -1, 0)) {
|
|
|
|
|
const char* s = getenv("HAKMEM_TINY_REG_SCAN_MAX");
|
|
|
|
|
int defv = 256; // conservative default
|
|
|
|
|
if (s && *s) {
|
|
|
|
|
int parsed = atoi(s);
|
|
|
|
|
v = (parsed > 0) ? parsed : defv;
|
|
|
|
|
} else {
|
|
|
|
|
v = defv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 14:45:26 +09:00
|
|
|
// Opportunistic background remote-drain knobs (ENV removed; fixed defaults)
|
|
|
|
|
static inline int tiny_bg_remote_tryrate(void) { return 16; }
|
|
|
|
|
static inline int tiny_bg_remote_budget_default(void) { return 2; }
|
2025-11-07 01:27:04 +09:00
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
// Mid-size simple refill (ENV: HAKMEM_TINY_MID_REFILL_SIMPLE)
|
|
|
|
|
static inline int tiny_mid_refill_simple_enabled(void) {
|
|
|
|
|
static int v = -1;
|
|
|
|
|
if (__builtin_expect(v == -1, 0)) {
|
|
|
|
|
const char* s = getenv("HAKMEM_TINY_MID_REFILL_SIMPLE");
|
|
|
|
|
v = (s && *s && *s != '0') ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try a quick adopt from sticky/hot/bench/mailbox (single pass)
|
|
|
|
|
static inline SuperSlab* tiny_refill_try_fast(int class_idx, TinyTLSSlab* tls) {
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_BEGIN(class_idx); ROUTE_MARK(0);
|
|
|
|
|
// Ready list (Box: Ready) — O(1) candidates published by free/publish
|
|
|
|
|
{
|
2025-11-26 14:45:26 +09:00
|
|
|
const int rb = 1; // Ready budget fixed (ENV removed)
|
2025-11-07 01:27:04 +09:00
|
|
|
for (int attempt = 0; attempt < rb; attempt++) {
|
|
|
|
|
ROUTE_MARK(1); // ready_try
|
2025-11-07 18:07:48 +09:00
|
|
|
uintptr_t ent = tiny_mail_ready_allowed() ? tiny_ready_pop(class_idx) : (uintptr_t)0;
|
2025-11-07 01:27:04 +09:00
|
|
|
if (!ent) break;
|
|
|
|
|
SuperSlab* rss = slab_entry_ss(ent);
|
|
|
|
|
int ridx = slab_entry_idx(ent);
|
|
|
|
|
uint32_t self_tid = tiny_self_u32();
|
|
|
|
|
SlabHandle h = slab_try_acquire(rss, ridx, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
|
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h.ss, h.slab_idx);
|
|
|
|
|
extern unsigned long long g_rf_hit_ready[];
|
|
|
|
|
g_rf_hit_ready[class_idx]++;
|
|
|
|
|
ROUTE_MARK(2); ROUTE_COMMIT(class_idx, 0x01);
|
|
|
|
|
return h.ss;
|
|
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Phase 4c: Add master trace control (HAKMEM_TRACE)
Add unified trace control that allows enabling specific trace modules
using comma-separated values or "all" to enable everything.
New file: core/hakmem_trace_master.h
- HAKMEM_TRACE=all: Enable all trace modules
- HAKMEM_TRACE=ptr,refill,free,mailbox: Enable specific modules
- HAKMEM_TRACE_LEVEL=N: Set trace verbosity (1-3)
- hak_trace_check(): Check if module should enable tracing
Available trace modules:
ptr, refill, superslab, ring, free, mailbox, registry
Priority order:
1. HAKMEM_QUIET=1 → suppress all
2. Specific module ENV (e.g., HAKMEM_PTR_TRACE=1)
3. HAKMEM_TRACE=module1,module2
4. Default → disabled
Updated files:
- core/tiny_refill.h: Use hak_trace_check() for refill tracing
- core/box/mailbox_box.c: Use hak_trace_check() for mailbox tracing
Performance: No regression (72.9M ops/s)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 16:08:44 +09:00
|
|
|
// One-shot entry trace (env: HAKMEM_TINY_RF_TRACE or HAKMEM_TRACE=refill)
|
|
|
|
|
// Phase 4c: Now uses hak_trace_check() for unified trace control
|
ENV cleanup: Add RELEASE guards to DEBUG ENV variables (14 vars)
Added compile-time guards (#if HAKMEM_BUILD_RELEASE) to eliminate
DEBUG ENV variable overhead in RELEASE builds.
Variables guarded (14 total):
- HAKMEM_TINY_TRACE_RING, HAKMEM_TINY_DUMP_RING_ATEXIT
- HAKMEM_TINY_RF_TRACE, HAKMEM_TINY_MAILBOX_TRACE
- HAKMEM_TINY_MAILBOX_TRACE_LIMIT, HAKMEM_TINY_MAILBOX_SLOWDISC
- HAKMEM_TINY_MAILBOX_SLOWDISC_PERIOD
- HAKMEM_SS_PREWARM_DEBUG, HAKMEM_SS_FREE_DEBUG
- HAKMEM_TINY_FRONT_METRICS, HAKMEM_TINY_FRONT_DUMP
- HAKMEM_TINY_COUNTERS_DUMP, HAKMEM_TINY_REFILL_DUMP
- HAKMEM_PTR_TRACE_DUMP, HAKMEM_PTR_TRACE_VERBOSE
Files modified (9 core files):
- core/tiny_debug_ring.c (ring trace/dump)
- core/box/mailbox_box.c (mailbox trace + slowdisc)
- core/tiny_refill.h (refill trace)
- core/hakmem_tiny_superslab.c (superslab debug)
- core/box/ss_allocation_box.c (allocation debug)
- core/tiny_superslab_free.inc.h (free debug)
- core/box/front_metrics_box.c (frontend metrics)
- core/hakmem_tiny_stats.c (stats dump)
- core/ptr_trace.h (pointer trace)
Bug fixes during implementation:
1. mailbox_box.c - Fixed variable scope (moved 'used' outside guard)
2. hakmem_tiny_stats.c - Fixed incomplete declarations (on1, on2)
Impact:
- Binary size: -85KB total
- bench_random_mixed_hakmem: 319K → 305K (-14K, -4.4%)
- larson_hakmem: 380K → 309K (-71K, -18.7%)
- Performance: No regression (16.9-17.9M ops/s maintained)
- Functional: All tests pass (Random Mixed + Larson)
- Behavior: DEBUG ENV vars correctly ignored in RELEASE builds
Testing:
- Build: Clean compilation (warnings only, pre-existing)
- 100K Random Mixed: 16.9-17.9M ops/s (PASS)
- 10K Larson: 25.9M ops/s (PASS)
- DEBUG ENV verification: Correctly ignored (PASS)
Result: 14 DEBUG ENV variables now have zero overhead in RELEASE builds.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 03:41:07 +09:00
|
|
|
#if !HAKMEM_BUILD_RELEASE
|
2025-11-05 12:31:14 +09:00
|
|
|
do {
|
|
|
|
|
static int en = -1; static _Atomic int printed[8];
|
|
|
|
|
if (__builtin_expect(en == -1, 0)) {
|
Phase 4c: Add master trace control (HAKMEM_TRACE)
Add unified trace control that allows enabling specific trace modules
using comma-separated values or "all" to enable everything.
New file: core/hakmem_trace_master.h
- HAKMEM_TRACE=all: Enable all trace modules
- HAKMEM_TRACE=ptr,refill,free,mailbox: Enable specific modules
- HAKMEM_TRACE_LEVEL=N: Set trace verbosity (1-3)
- hak_trace_check(): Check if module should enable tracing
Available trace modules:
ptr, refill, superslab, ring, free, mailbox, registry
Priority order:
1. HAKMEM_QUIET=1 → suppress all
2. Specific module ENV (e.g., HAKMEM_PTR_TRACE=1)
3. HAKMEM_TRACE=module1,module2
4. Default → disabled
Updated files:
- core/tiny_refill.h: Use hak_trace_check() for refill tracing
- core/box/mailbox_box.c: Use hak_trace_check() for mailbox tracing
Performance: No regression (72.9M ops/s)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 16:08:44 +09:00
|
|
|
en = hak_trace_check("HAKMEM_TINY_RF_TRACE", "refill");
|
2025-11-05 12:31:14 +09:00
|
|
|
}
|
|
|
|
|
if (en) {
|
|
|
|
|
int expected = 0;
|
|
|
|
|
(void)atomic_compare_exchange_strong(&printed[class_idx], &expected, 1);
|
|
|
|
|
if (expected == 0) {
|
|
|
|
|
fprintf(stderr, "[RFTRACE] fast-refill enter class=%d\n", class_idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
ENV cleanup: Add RELEASE guards to DEBUG ENV variables (14 vars)
Added compile-time guards (#if HAKMEM_BUILD_RELEASE) to eliminate
DEBUG ENV variable overhead in RELEASE builds.
Variables guarded (14 total):
- HAKMEM_TINY_TRACE_RING, HAKMEM_TINY_DUMP_RING_ATEXIT
- HAKMEM_TINY_RF_TRACE, HAKMEM_TINY_MAILBOX_TRACE
- HAKMEM_TINY_MAILBOX_TRACE_LIMIT, HAKMEM_TINY_MAILBOX_SLOWDISC
- HAKMEM_TINY_MAILBOX_SLOWDISC_PERIOD
- HAKMEM_SS_PREWARM_DEBUG, HAKMEM_SS_FREE_DEBUG
- HAKMEM_TINY_FRONT_METRICS, HAKMEM_TINY_FRONT_DUMP
- HAKMEM_TINY_COUNTERS_DUMP, HAKMEM_TINY_REFILL_DUMP
- HAKMEM_PTR_TRACE_DUMP, HAKMEM_PTR_TRACE_VERBOSE
Files modified (9 core files):
- core/tiny_debug_ring.c (ring trace/dump)
- core/box/mailbox_box.c (mailbox trace + slowdisc)
- core/tiny_refill.h (refill trace)
- core/hakmem_tiny_superslab.c (superslab debug)
- core/box/ss_allocation_box.c (allocation debug)
- core/tiny_superslab_free.inc.h (free debug)
- core/box/front_metrics_box.c (frontend metrics)
- core/hakmem_tiny_stats.c (stats dump)
- core/ptr_trace.h (pointer trace)
Bug fixes during implementation:
1. mailbox_box.c - Fixed variable scope (moved 'used' outside guard)
2. hakmem_tiny_stats.c - Fixed incomplete declarations (on1, on2)
Impact:
- Binary size: -85KB total
- bench_random_mixed_hakmem: 319K → 305K (-14K, -4.4%)
- larson_hakmem: 380K → 309K (-71K, -18.7%)
- Performance: No regression (16.9-17.9M ops/s maintained)
- Functional: All tests pass (Random Mixed + Larson)
- Behavior: DEBUG ENV vars correctly ignored in RELEASE builds
Testing:
- Build: Clean compilation (warnings only, pre-existing)
- 100K Random Mixed: 16.9-17.9M ops/s (PASS)
- 10K Larson: 25.9M ops/s (PASS)
- DEBUG ENV verification: Correctly ignored (PASS)
Result: 14 DEBUG ENV variables now have zero overhead in RELEASE builds.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 03:41:07 +09:00
|
|
|
#endif
|
2025-11-05 12:31:14 +09:00
|
|
|
// For hot tiny classes (0..3), try mailbox first to avoid deeper scans
|
|
|
|
|
if (class_idx <= 3) {
|
|
|
|
|
uint32_t self_tid = tiny_self_u32();
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(3); // mail_try
|
2025-11-07 18:07:48 +09:00
|
|
|
uintptr_t mail = tiny_mail_ready_allowed() ? mailbox_box_fetch(class_idx) : (uintptr_t)0;
|
2025-11-05 12:31:14 +09:00
|
|
|
if (mail) {
|
|
|
|
|
SuperSlab* mss = slab_entry_ss(mail);
|
|
|
|
|
int midx = slab_entry_idx(mail);
|
|
|
|
|
SlabHandle h = slab_try_acquire(mss, midx, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
slab_release(&h);
|
2025-11-07 01:27:04 +09:00
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
2025-11-05 12:31:14 +09:00
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h.ss, h.slab_idx);
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(4); ROUTE_COMMIT(class_idx, 0x02);
|
2025-11-05 12:31:14 +09:00
|
|
|
return h.ss;
|
|
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sticky ring (Box: SlabHandle)
|
|
|
|
|
uint32_t self_tid = tiny_self_u32();
|
|
|
|
|
for (int r = 0; r < TINY_STICKY_RING; r++) {
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(5); // sticky_try
|
2025-11-05 12:31:14 +09:00
|
|
|
SuperSlab* last_ss = g_tls_sticky_ss[class_idx][r];
|
|
|
|
|
if (!(last_ss && last_ss->magic == SUPERSLAB_MAGIC)) { tiny_sticky_clear(class_idx, r); continue; }
|
|
|
|
|
int li = g_tls_sticky_idx[class_idx][r];
|
|
|
|
|
int cap = ss_slabs_capacity(last_ss);
|
|
|
|
|
if (li < 0 || li >= cap) { tiny_sticky_clear(class_idx, r); continue; }
|
|
|
|
|
|
|
|
|
|
// Box: Try to acquire ownership
|
|
|
|
|
SlabHandle h = slab_try_acquire(last_ss, li, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
if (__builtin_expect(g_debug_remote_guard, 0)) {
|
|
|
|
|
uintptr_t head = atomic_load_explicit(&h.ss->remote_heads[h.slab_idx], memory_order_relaxed);
|
|
|
|
|
tiny_remote_watch_note("sticky_remote_pending",
|
|
|
|
|
h.ss,
|
|
|
|
|
h.slab_idx,
|
|
|
|
|
(void*)head,
|
|
|
|
|
0xA250u,
|
|
|
|
|
self_tid,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h);
|
2025-11-07 01:27:04 +09:00
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
2025-11-05 12:31:14 +09:00
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(6); ROUTE_COMMIT(class_idx, 0x03); return h.ss;
|
2025-11-05 12:31:14 +09:00
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int has_remote = (atomic_load_explicit(&last_ss->remote_heads[li], memory_order_acquire) != 0);
|
|
|
|
|
if (!has_remote) tiny_sticky_clear(class_idx, r);
|
|
|
|
|
}
|
|
|
|
|
// Hot slot
|
|
|
|
|
{
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(7); // hot_try
|
2025-11-05 12:31:14 +09:00
|
|
|
uintptr_t hs = hot_slot_pop(class_idx);
|
|
|
|
|
if (hs) {
|
|
|
|
|
SuperSlab* hss = slab_entry_ss(hs);
|
|
|
|
|
int hidx = slab_entry_idx(hs);
|
|
|
|
|
|
|
|
|
|
// Box: Try to acquire ownership
|
|
|
|
|
SlabHandle h = slab_try_acquire(hss, hidx, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
if (__builtin_expect(g_debug_remote_guard, 0)) {
|
|
|
|
|
uintptr_t head = atomic_load_explicit(&h.ss->remote_heads[h.slab_idx], memory_order_relaxed);
|
|
|
|
|
tiny_remote_watch_note("hot_remote_pending",
|
|
|
|
|
h.ss,
|
|
|
|
|
h.slab_idx,
|
|
|
|
|
(void*)head,
|
|
|
|
|
0xA251u,
|
|
|
|
|
self_tid,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h);
|
2025-11-07 01:27:04 +09:00
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
2025-11-05 12:31:14 +09:00
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h.ss, h.slab_idx);
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(8); ROUTE_COMMIT(class_idx, 0x04); return h.ss;
|
2025-11-05 12:31:14 +09:00
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Bench
|
|
|
|
|
{
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(9); // bench_try
|
2025-11-05 12:31:14 +09:00
|
|
|
uintptr_t entb = bench_pub_pop(class_idx);
|
|
|
|
|
if (entb) {
|
|
|
|
|
SuperSlab* bss = slab_entry_ss(entb);
|
|
|
|
|
int bidx = slab_entry_idx(entb);
|
|
|
|
|
|
|
|
|
|
// Box: Try to acquire ownership
|
|
|
|
|
SlabHandle h = slab_try_acquire(bss, bidx, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
if (__builtin_expect(g_debug_remote_guard, 0)) {
|
|
|
|
|
uintptr_t head = atomic_load_explicit(&h.ss->remote_heads[h.slab_idx], memory_order_relaxed);
|
|
|
|
|
tiny_remote_watch_note("bench_remote_pending",
|
|
|
|
|
h.ss,
|
|
|
|
|
h.slab_idx,
|
|
|
|
|
(void*)head,
|
|
|
|
|
0xA252u,
|
|
|
|
|
self_tid,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h);
|
2025-11-07 01:27:04 +09:00
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
2025-11-05 12:31:14 +09:00
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h.ss, h.slab_idx);
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(10); ROUTE_COMMIT(class_idx, 0x05); return h.ss;
|
2025-11-05 12:31:14 +09:00
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Mailbox (for non-hot classes)
|
|
|
|
|
if (class_idx > 3) {
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(3); // mail_try (non-hot)
|
2025-11-07 18:07:48 +09:00
|
|
|
uintptr_t mail = tiny_mail_ready_allowed() ? mailbox_box_fetch(class_idx) : (uintptr_t)0;
|
2025-11-05 12:31:14 +09:00
|
|
|
if (mail) {
|
|
|
|
|
SuperSlab* mss = slab_entry_ss(mail);
|
|
|
|
|
int midx = slab_entry_idx(mail);
|
|
|
|
|
|
|
|
|
|
// Box: Try to acquire ownership
|
|
|
|
|
SlabHandle h = slab_try_acquire(mss, midx, self_tid);
|
|
|
|
|
if (slab_is_valid(&h)) {
|
|
|
|
|
if (slab_remote_pending(&h)) {
|
|
|
|
|
slab_drain_remote_full(&h);
|
|
|
|
|
if (__builtin_expect(g_debug_remote_guard, 0)) {
|
|
|
|
|
uintptr_t head = atomic_load_explicit(&h.ss->remote_heads[h.slab_idx], memory_order_relaxed);
|
|
|
|
|
tiny_remote_watch_note("mailbox_remote_pending",
|
|
|
|
|
h.ss,
|
|
|
|
|
h.slab_idx,
|
|
|
|
|
(void*)head,
|
|
|
|
|
0xA253u,
|
|
|
|
|
self_tid,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h);
|
2025-11-07 01:27:04 +09:00
|
|
|
} else if (slab_is_safe_to_bind(&h)) {
|
2025-11-05 12:31:14 +09:00
|
|
|
tiny_tls_bind_slab(tls, h.ss, h.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h.ss, h.slab_idx);
|
2025-11-07 01:27:04 +09:00
|
|
|
ROUTE_MARK(4); ROUTE_COMMIT(class_idx, 0x02); return h.ss;
|
2025-11-05 12:31:14 +09:00
|
|
|
} else {
|
|
|
|
|
slab_release(&h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-07 01:27:04 +09:00
|
|
|
// Opportunistic background remote-drain (Box: Remote Drain Coalescer)
|
ENV Cleanup: Delete Ultra HEAP & BG Remote dead code (-1,096 LOC)
Deleted files (11):
- core/ultra/ directory (6 files: tiny_ultra_heap.*, tiny_ultra_page_arena.*)
- core/front/tiny_ultrafront.h
- core/tiny_ultra_fast.inc.h
- core/hakmem_tiny_ultra_front.inc.h
- core/hakmem_tiny_ultra_simple.inc
- core/hakmem_tiny_ultra_batch_box.inc
Edited files (10):
- core/hakmem_tiny.c: Remove Ultra HEAP #includes, move ultra_batch_for_class()
- core/hakmem_tiny_tls_state_box.inc: Delete TinyUltraFront, g_ultra_simple
- core/hakmem_tiny_phase6_wrappers_box.inc: Delete ULTRA_SIMPLE block
- core/hakmem_tiny_alloc.inc: Delete Ultra-Front code block
- core/hakmem_tiny_init.inc: Delete ULTRA_SIMPLE ENV loading
- core/hakmem_tiny_remote_target.{c,h}: Delete g_bg_remote_enable/batch
- core/tiny_refill.h: Remove BG Remote check (always break)
- core/hakmem_tiny_background.inc: Delete BG Remote drain loop
Deleted ENV variables:
- HAKMEM_TINY_ULTRA_HEAP (build flag, undefined)
- HAKMEM_TINY_ULTRA_L0
- HAKMEM_TINY_ULTRA_HEAP_DUMP
- HAKMEM_TINY_ULTRA_PAGE_DUMP
- HAKMEM_TINY_ULTRA_FRONT
- HAKMEM_TINY_BG_REMOTE (no getenv, dead code)
- HAKMEM_TINY_BG_REMOTE_BATCH (no getenv, dead code)
- HAKMEM_TINY_ULTRA_SIMPLE (references only)
Impact:
- Code reduction: -1,096 lines
- Binary size: 305KB → 304KB (-1KB)
- Build: PASS
- Sanity: 15.69M ops/s (3 runs avg)
- Larson: 1 crash observed (seed 43, likely existing instability)
Notes:
- Ultra HEAP never compiled (#if HAKMEM_TINY_ULTRA_HEAP undefined)
- BG Remote variables never initialized (g_bg_remote_enable always 0)
- Ultra SLIM (ultra_slim_alloc_box.h) preserved (active 4-layer path)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 04:35:47 +09:00
|
|
|
// NOTE: BG Remote feature permanently disabled (dead code cleanup 2025-11-27)
|
|
|
|
|
// This block was guarded by g_bg_remote_enable which defaulted to 0
|
2025-11-07 01:27:04 +09:00
|
|
|
do {
|
ENV Cleanup: Delete Ultra HEAP & BG Remote dead code (-1,096 LOC)
Deleted files (11):
- core/ultra/ directory (6 files: tiny_ultra_heap.*, tiny_ultra_page_arena.*)
- core/front/tiny_ultrafront.h
- core/tiny_ultra_fast.inc.h
- core/hakmem_tiny_ultra_front.inc.h
- core/hakmem_tiny_ultra_simple.inc
- core/hakmem_tiny_ultra_batch_box.inc
Edited files (10):
- core/hakmem_tiny.c: Remove Ultra HEAP #includes, move ultra_batch_for_class()
- core/hakmem_tiny_tls_state_box.inc: Delete TinyUltraFront, g_ultra_simple
- core/hakmem_tiny_phase6_wrappers_box.inc: Delete ULTRA_SIMPLE block
- core/hakmem_tiny_alloc.inc: Delete Ultra-Front code block
- core/hakmem_tiny_init.inc: Delete ULTRA_SIMPLE ENV loading
- core/hakmem_tiny_remote_target.{c,h}: Delete g_bg_remote_enable/batch
- core/tiny_refill.h: Remove BG Remote check (always break)
- core/hakmem_tiny_background.inc: Delete BG Remote drain loop
Deleted ENV variables:
- HAKMEM_TINY_ULTRA_HEAP (build flag, undefined)
- HAKMEM_TINY_ULTRA_L0
- HAKMEM_TINY_ULTRA_HEAP_DUMP
- HAKMEM_TINY_ULTRA_PAGE_DUMP
- HAKMEM_TINY_ULTRA_FRONT
- HAKMEM_TINY_BG_REMOTE (no getenv, dead code)
- HAKMEM_TINY_BG_REMOTE_BATCH (no getenv, dead code)
- HAKMEM_TINY_ULTRA_SIMPLE (references only)
Impact:
- Code reduction: -1,096 lines
- Binary size: 305KB → 304KB (-1KB)
- Build: PASS
- Sanity: 15.69M ops/s (3 runs avg)
- Larson: 1 crash observed (seed 43, likely existing instability)
Notes:
- Ultra HEAP never compiled (#if HAKMEM_TINY_ULTRA_HEAP undefined)
- BG Remote variables never initialized (g_bg_remote_enable always 0)
- Ultra SLIM (ultra_slim_alloc_box.h) preserved (active 4-layer path)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 04:35:47 +09:00
|
|
|
// Always skip - BG Remote feature removed
|
|
|
|
|
break;
|
2025-11-07 01:27:04 +09:00
|
|
|
|
|
|
|
|
// TLS miss tick per class
|
|
|
|
|
static __thread unsigned miss_tick[8];
|
|
|
|
|
unsigned t = ++miss_tick[class_idx];
|
|
|
|
|
int period = tiny_bg_remote_tryrate();
|
|
|
|
|
if (__builtin_expect(period <= 1 || (t % (unsigned)period) == 0, 0)) {
|
|
|
|
|
int budget = tiny_bg_remote_budget_default();
|
|
|
|
|
tiny_remote_bg_drain_step(class_idx, budget);
|
|
|
|
|
// Quick second chance from Ready after drain
|
2025-11-07 18:07:48 +09:00
|
|
|
uintptr_t ent2 = tiny_mail_ready_allowed() ? tiny_ready_pop(class_idx) : (uintptr_t)0;
|
2025-11-07 01:27:04 +09:00
|
|
|
if (ent2) {
|
|
|
|
|
SuperSlab* ss2 = slab_entry_ss(ent2);
|
|
|
|
|
int idx2 = slab_entry_idx(ent2);
|
|
|
|
|
uint32_t self_tid = tiny_self_u32();
|
|
|
|
|
SlabHandle h2 = slab_try_acquire(ss2, idx2, self_tid);
|
|
|
|
|
if (slab_is_valid(&h2)) {
|
|
|
|
|
if (slab_is_safe_to_bind(&h2)) {
|
|
|
|
|
tiny_tls_bind_slab(tls, h2.ss, h2.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h2.ss, h2.slab_idx);
|
|
|
|
|
extern unsigned long long g_rf_hit_ready[];
|
|
|
|
|
g_rf_hit_ready[class_idx]++;
|
|
|
|
|
slab_release(&h2);
|
|
|
|
|
return h2.ss;
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Ready Aggregator: peek mailbox and surface one hint into Ready
|
|
|
|
|
do {
|
2025-11-26 14:45:26 +09:00
|
|
|
const int agg_en = 0; // Ready aggregator ENV removed (fixed OFF)
|
2025-11-07 18:07:48 +09:00
|
|
|
if (agg_en && tiny_mail_ready_allowed()) {
|
2025-11-26 14:45:26 +09:00
|
|
|
const int mb = 1;
|
2025-11-07 01:27:04 +09:00
|
|
|
tiny_ready_bg_aggregate_step(class_idx, mb);
|
|
|
|
|
uintptr_t ent3 = tiny_ready_pop(class_idx);
|
|
|
|
|
if (ent3) {
|
|
|
|
|
SuperSlab* ss3 = slab_entry_ss(ent3);
|
|
|
|
|
int idx3 = slab_entry_idx(ent3);
|
|
|
|
|
uint32_t self_tid = tiny_self_u32();
|
|
|
|
|
SlabHandle h3 = slab_try_acquire(ss3, idx3, self_tid);
|
|
|
|
|
if (slab_is_valid(&h3)) {
|
|
|
|
|
if (slab_is_safe_to_bind(&h3)) {
|
|
|
|
|
tiny_tls_bind_slab(tls, h3.ss, h3.slab_idx);
|
|
|
|
|
tiny_sticky_save(class_idx, h3.ss, h3.slab_idx);
|
|
|
|
|
extern unsigned long long g_rf_hit_ready[];
|
|
|
|
|
g_rf_hit_ready[class_idx]++;
|
|
|
|
|
slab_release(&h3);
|
|
|
|
|
return h3.ss;
|
|
|
|
|
}
|
|
|
|
|
slab_release(&h3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
ROUTE_COMMIT(class_idx, 0xFF); // no candidate hit; fall back to slab/slow
|
2025-11-05 12:31:14 +09:00
|
|
|
return NULL;
|
|
|
|
|
}
|