81 lines
2.6 KiB
C
81 lines
2.6 KiB
C
|
|
// smallobject_cold_iface_v1.h - Cold interface wrapper for SmallObject HotBox v3
|
||
|
|
// 役割:
|
||
|
|
// - SmallObject Hot Box (v3) と既存 v1 Tiny Cold 層の境界を 1 箇所にまとめる。
|
||
|
|
// - Phase A: C7 の refill/retire だけを v1 TinyHeap へラップする。
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include "tiny_heap_box.h"
|
||
|
|
#include "smallobject_hotbox_v3_box.h"
|
||
|
|
#include "../hakmem_tiny.h" // TINY_SLAB_SIZE for slab base mask
|
||
|
|
|
||
|
|
struct so_page_v3;
|
||
|
|
|
||
|
|
typedef struct SmallObjectColdIface {
|
||
|
|
struct so_page_v3* (*refill_page)(void* cold_ctx, uint32_t class_idx);
|
||
|
|
void (*retire_page)(void* cold_ctx, uint32_t class_idx, struct so_page_v3* page);
|
||
|
|
} SmallObjectColdIface;
|
||
|
|
|
||
|
|
static inline struct so_page_v3* smallobject_cold_refill_page_v1(void* cold_ctx, uint32_t class_idx) {
|
||
|
|
if (class_idx != 7 && class_idx != 6) {
|
||
|
|
return NULL; // Phase A-2: C7/C6 のみ対応
|
||
|
|
}
|
||
|
|
tiny_heap_ctx_t* ctx = cold_ctx ? (tiny_heap_ctx_t*)cold_ctx : tiny_heap_ctx_for_thread();
|
||
|
|
if (!ctx) return NULL;
|
||
|
|
tiny_heap_page_t* lease = tiny_heap_prepare_page(ctx, (int)class_idx);
|
||
|
|
if (!lease) return NULL;
|
||
|
|
|
||
|
|
so_page_v3* page = (so_page_v3*)calloc(1, sizeof(so_page_v3));
|
||
|
|
if (!page) return NULL;
|
||
|
|
|
||
|
|
page->lease_page = lease;
|
||
|
|
page->meta = lease->meta;
|
||
|
|
page->ss = lease->ss;
|
||
|
|
page->slab_idx = lease->slab_idx;
|
||
|
|
page->base = lease->base;
|
||
|
|
page->capacity = lease->capacity;
|
||
|
|
page->block_size = (uint32_t)tiny_stride_for_class((int)class_idx);
|
||
|
|
page->class_idx = class_idx;
|
||
|
|
page->slab_ref = lease;
|
||
|
|
return page;
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void smallobject_cold_retire_page_v1(void* cold_ctx, uint32_t class_idx, struct so_page_v3* page) {
|
||
|
|
if (!page || (class_idx != 7 && class_idx != 6)) {
|
||
|
|
if (page) {
|
||
|
|
free(page);
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
tiny_heap_ctx_t* ctx = cold_ctx ? (tiny_heap_ctx_t*)cold_ctx : tiny_heap_ctx_for_thread();
|
||
|
|
if (!ctx) {
|
||
|
|
free(page);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
tiny_heap_page_t* lease = page->lease_page;
|
||
|
|
if (!lease) {
|
||
|
|
free(page);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
lease->base = (uint8_t*)page->base;
|
||
|
|
lease->capacity = (uint16_t)page->capacity;
|
||
|
|
lease->used = (uint16_t)page->used;
|
||
|
|
lease->meta = page->meta;
|
||
|
|
lease->ss = page->ss;
|
||
|
|
lease->slab_idx = page->slab_idx;
|
||
|
|
lease->free_list = page->freelist;
|
||
|
|
|
||
|
|
tiny_heap_page_becomes_empty(ctx, (int)class_idx, lease);
|
||
|
|
free(page);
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline SmallObjectColdIface smallobject_cold_iface_v1(void) {
|
||
|
|
SmallObjectColdIface iface = {
|
||
|
|
.refill_page = smallobject_cold_refill_page_v1,
|
||
|
|
.retire_page = smallobject_cold_retire_page_v1,
|
||
|
|
};
|
||
|
|
return iface;
|
||
|
|
}
|