Files
hakmem/core/box/smallobject_hotbox_v3_box.h

75 lines
2.2 KiB
C
Raw Normal View History

// smallobject_hotbox_v3_box.h - SmallObject HotHeap v3 (C7-first skeleton)
//
// Phase A/B: 型と TLS / stats を用意し、front が呼べる枠を置く。
// まだ中身は v1 fallbackso_alloc は NULL を返す)。
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdatomic.h>
#include "tiny_geometry_box.h"
#include "smallobject_hotbox_v3_env_box.h"
#include "tiny_region_id.h"
#ifndef SMALLOBJECT_NUM_CLASSES
#define SMALLOBJECT_NUM_CLASSES TINY_NUM_CLASSES
#endif
struct tiny_heap_page_t;
struct TinySlabMeta;
struct SuperSlab;
typedef struct so_page_v3 {
void* freelist;
uint32_t used;
uint32_t capacity;
uint32_t block_size;
uint32_t class_idx;
uint32_t flags;
void* base; // carve 後のユーザ領域先頭
void* slab_base; // 64KiB slab 基底page_of 用ヘッダを書き込む)
struct TinySlabMeta* meta;
struct SuperSlab* ss;
uint16_t slab_idx;
struct tiny_heap_page_t* lease_page;
void* slab_ref; // kept as a generic token; currently same as lease_page for v1
struct so_page_v3* next;
} so_page_v3;
typedef struct so_class_v3 {
so_page_v3* current;
so_page_v3* partial;
uint16_t max_partial_pages;
uint16_t partial_count;
uint32_t block_size;
} so_class_v3;
typedef struct so_ctx_v3 {
so_class_v3 cls[SMALLOBJECT_NUM_CLASSES];
} so_ctx_v3;
typedef struct so_stats_class_v3 {
_Atomic uint64_t route_hits;
_Atomic uint64_t alloc_calls;
_Atomic uint64_t alloc_refill;
_Atomic uint64_t alloc_fallback_v1;
_Atomic uint64_t free_calls;
_Atomic uint64_t free_fallback_v1;
} so_stats_class_v3;
// Stats helpers (defined in core/smallobject_hotbox_v3.c)
int so_v3_stats_enabled(void);
void so_v3_record_route_hit(uint8_t ci);
void so_v3_record_alloc_call(uint8_t ci);
void so_v3_record_alloc_refill(uint8_t ci);
void so_v3_record_alloc_fallback(uint8_t ci);
void so_v3_record_free_call(uint8_t ci);
void so_v3_record_free_fallback(uint8_t ci);
// TLS accessor (core/smallobject_hotbox_v3.c)
so_ctx_v3* so_tls_get(void);
// Hot path API (Phase B: stub → always fallback to v1)
void* so_alloc(uint32_t class_idx);
void so_free(uint32_t class_idx, void* ptr);