Boxify superslab registry, add bench profile, and document C7 hotpath experiments

This commit is contained in:
Moe Charm (CI)
2025-12-07 03:12:27 +09:00
parent 18faa6a1c4
commit fda6cd2e67
71 changed files with 2052 additions and 286 deletions

View File

@ -4,6 +4,7 @@
// Date: 2025-11-28
#include "hakmem_tiny_superslab_internal.h"
#include <stdlib.h>
// ============================================================================
// Global Statistics
@ -30,6 +31,11 @@ uint64_t g_ss_freed_by_class[8] = {0};
_Atomic uint64_t g_ss_mmap_count = 0;
_Atomic uint64_t g_final_fallback_mmap_count = 0;
// Superslab/slab observability (Tiny-only; relaxed updates)
_Atomic uint64_t g_ss_live_by_class[8] = {0};
_Atomic uint64_t g_ss_empty_events[8] = {0};
_Atomic uint64_t g_slab_live_events[8] = {0};
// ============================================================================
// Statistics Functions
// ============================================================================
@ -56,6 +62,35 @@ void ss_stats_cache_store(void) {
pthread_mutex_unlock(&g_superslab_lock);
}
void ss_stats_on_ss_alloc_class(int class_idx) {
if (class_idx >= 0 && class_idx < 8) {
atomic_fetch_add_explicit(&g_ss_live_by_class[class_idx], 1, memory_order_relaxed);
}
}
void ss_stats_on_ss_free_class(int class_idx) {
if (class_idx >= 0 && class_idx < 8) {
uint64_t prev = atomic_load_explicit(&g_ss_live_by_class[class_idx], memory_order_relaxed);
if (prev > 0) {
atomic_fetch_sub_explicit(&g_ss_live_by_class[class_idx], 1, memory_order_relaxed);
}
}
}
void ss_stats_on_ss_scan(int class_idx, int slab_live, int is_empty) {
if (class_idx < 0 || class_idx >= 8) {
return;
}
if (slab_live > 0) {
atomic_fetch_add_explicit(&g_slab_live_events[class_idx],
(uint64_t)slab_live,
memory_order_relaxed);
}
if (is_empty) {
atomic_fetch_add_explicit(&g_ss_empty_events[class_idx], 1, memory_order_relaxed);
}
}
// ============================================================================
// Diagnostics
// ============================================================================
@ -164,3 +199,23 @@ void superslab_print_global_stats(void) {
printf("Total bytes allocated: %lu MB\n", g_bytes_allocated / (1024 * 1024));
pthread_mutex_unlock(&g_superslab_lock);
}
void ss_stats_dump_if_requested(void) {
const char* env = getenv("HAKMEM_SS_STATS_DUMP");
if (!env || !*env || *env == '0') {
return;
}
fprintf(stderr, "[SS_STATS] class live empty_events slab_live_events\n");
for (int c = 0; c < 8; c++) {
uint64_t live = atomic_load_explicit(&g_ss_live_by_class[c], memory_order_relaxed);
uint64_t empty = atomic_load_explicit(&g_ss_empty_events[c], memory_order_relaxed);
uint64_t slab_live = atomic_load_explicit(&g_slab_live_events[c], memory_order_relaxed);
if (live || empty || slab_live) {
fprintf(stderr, " C%d: live=%llu empty=%llu slab_live=%llu\n",
c,
(unsigned long long)live,
(unsigned long long)empty,
(unsigned long long)slab_live);
}
}
}