Files
hakmem/mmap_trace_patch.h

46 lines
2.1 KiB
C
Raw Permalink Normal View History

// mmap_trace_patch.h - Lightweight mmap instrumentation
#ifndef MMAP_TRACE_PATCH_H
#define MMAP_TRACE_PATCH_H
#include <stdatomic.h>
#include <stdio.h>
// Global counters for mmap sources
static _Atomic uint64_t g_mmap_count_superslab = 0;
static _Atomic uint64_t g_mmap_count_mid = 0;
static _Atomic uint64_t g_mmap_count_l25 = 0;
static _Atomic uint64_t g_mmap_count_ace = 0;
static _Atomic uint64_t g_mmap_count_final = 0; // Final fallback in hak_alloc_api
static _Atomic uint64_t g_mmap_count_other = 0;
// Helper macros for instrumentation
#define MMAP_TRACE_SUPERSLAB() atomic_fetch_add(&g_mmap_count_superslab, 1)
#define MMAP_TRACE_MID() atomic_fetch_add(&g_mmap_count_mid, 1)
#define MMAP_TRACE_L25() atomic_fetch_add(&g_mmap_count_l25, 1)
#define MMAP_TRACE_ACE() atomic_fetch_add(&g_mmap_count_ace, 1)
#define MMAP_TRACE_FINAL() atomic_fetch_add(&g_mmap_count_final, 1)
#define MMAP_TRACE_OTHER() atomic_fetch_add(&g_mmap_count_other, 1)
// Print summary
static inline void mmap_trace_print_summary(void) {
uint64_t ss = atomic_load(&g_mmap_count_superslab);
uint64_t mid = atomic_load(&g_mmap_count_mid);
uint64_t l25 = atomic_load(&g_mmap_count_l25);
uint64_t ace = atomic_load(&g_mmap_count_ace);
uint64_t final = atomic_load(&g_mmap_count_final);
uint64_t other = atomic_load(&g_mmap_count_other);
uint64_t total = ss + mid + l25 + ace + final + other;
fprintf(stderr, "\n=== MMAP Source Breakdown ===\n");
fprintf(stderr, "SuperSlab: %6lu (%.1f%%)\n", ss, ss * 100.0 / total);
fprintf(stderr, "Mid allocator: %6lu (%.1f%%)\n", mid, mid * 100.0 / total);
fprintf(stderr, "L25 pool: %6lu (%.1f%%)\n", l25, l25 * 100.0 / total);
fprintf(stderr, "ACE: %6lu (%.1f%%)\n", ace, ace * 100.0 / total);
fprintf(stderr, "Final fallback: %6lu (%.1f%%) ← Header overflow!\n", final, final * 100.0 / total);
fprintf(stderr, "Other: %6lu (%.1f%%)\n", other, other * 100.0 / total);
fprintf(stderr, "----------------------------\n");
fprintf(stderr, "TOTAL: %6lu\n", total);
}
#endif // MMAP_TRACE_PATCH_H