Optimize C6 heavy and C7 ultra performance analysis with refined design refinements
- Update environment profile presets and visibility analysis - Enhance small object and tiny segment v4 box implementations - Refine C7 ultra and C6 heavy allocation strategies - Add comprehensive performance metrics and design documentation 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -3,11 +3,13 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "box/tiny_c7_ultra_box.h"
|
||||
#include "box/smallobject_hotbox_v3_box.h"
|
||||
#include "box/tiny_geometry_box.h"
|
||||
#include "tiny_region_id.h"
|
||||
#include "box/tiny_c7_ultra_segment_box.h"
|
||||
#include "box/tiny_front_v3_env_box.h"
|
||||
|
||||
static __thread tiny_c7_ultra_tls_t g_tiny_c7_ultra_tls;
|
||||
|
||||
@ -19,12 +21,24 @@ static inline void tiny_c7_ultra_clear(tiny_c7_ultra_tls_t* tls) {
|
||||
tls->freelist = NULL;
|
||||
tls->page_idx = 0;
|
||||
tls->page_meta = NULL;
|
||||
tls->headers_initialized = false;
|
||||
}
|
||||
|
||||
tiny_c7_ultra_tls_t* tiny_c7_ultra_tls_get(void) {
|
||||
return &g_tiny_c7_ultra_tls;
|
||||
}
|
||||
|
||||
// freelist next をヘッダを壊さずに保持する(ヘッダ byte の直後に保存)
|
||||
static inline void ultra_store_next(void* base, void* next) {
|
||||
memcpy((uint8_t*)base + 1, &next, sizeof(next));
|
||||
}
|
||||
|
||||
static inline void* ultra_load_next(void* base) {
|
||||
void* next = NULL;
|
||||
memcpy(&next, (uint8_t*)base + 1, sizeof(next));
|
||||
return next;
|
||||
}
|
||||
|
||||
// セグメントから C7 ページを 1 枚借りて自前で carve する
|
||||
static bool tiny_c7_ultra_lease_page(tiny_c7_ultra_tls_t* tls) {
|
||||
tiny_c7_ultra_segment_t* seg = tls->seg;
|
||||
@ -40,6 +54,8 @@ static bool tiny_c7_ultra_lease_page(tiny_c7_ultra_tls_t* tls) {
|
||||
uint32_t capacity = (uint32_t)(seg->page_size / block_sz);
|
||||
if (capacity == 0) return false;
|
||||
|
||||
const bool header_light = tiny_front_v3_c7_ultra_header_light_enabled();
|
||||
|
||||
// 空きページを 1 枚だけ拾う(UF-3 では最初の空きを線形探索)
|
||||
uint32_t chosen = seg->num_pages;
|
||||
for (uint32_t i = 0; i < seg->num_pages; i++) {
|
||||
@ -60,7 +76,11 @@ static bool tiny_c7_ultra_lease_page(tiny_c7_ultra_tls_t* tls) {
|
||||
void* head = NULL;
|
||||
for (int i = (int)capacity - 1; i >= 0; i--) {
|
||||
uint8_t* blk = base + ((size_t)i * block_sz);
|
||||
*(void**)blk = head;
|
||||
if (header_light) {
|
||||
// header_light 時は carve で 1 度だけヘッダを書き込む
|
||||
tiny_region_id_write_header(blk, 7);
|
||||
}
|
||||
ultra_store_next(blk, head);
|
||||
head = blk;
|
||||
}
|
||||
if (!head) {
|
||||
@ -78,17 +98,19 @@ static bool tiny_c7_ultra_lease_page(tiny_c7_ultra_tls_t* tls) {
|
||||
tls->freelist = head;
|
||||
tls->page_idx = chosen;
|
||||
tls->page_meta = page;
|
||||
tls->headers_initialized = header_light;
|
||||
return true;
|
||||
}
|
||||
|
||||
void* tiny_c7_ultra_alloc(size_t size) {
|
||||
(void)size; // C7 専用のため未使用
|
||||
tiny_c7_ultra_tls_t* tls = tiny_c7_ultra_tls_get();
|
||||
const bool header_light = tiny_front_v3_c7_ultra_header_light_enabled();
|
||||
|
||||
// 1) freelist hit
|
||||
void* p = tls->freelist;
|
||||
if (__builtin_expect(p != NULL, 1)) {
|
||||
void* next = *(void**)p;
|
||||
void* next = ultra_load_next(p);
|
||||
tls->freelist = next;
|
||||
if (tls->page_meta) {
|
||||
tls->page_meta->freelist = next;
|
||||
@ -99,6 +121,9 @@ void* tiny_c7_ultra_alloc(size_t size) {
|
||||
if (tls->used < tls->capacity) {
|
||||
tls->used++;
|
||||
}
|
||||
if (header_light && tls->headers_initialized) {
|
||||
return (uint8_t*)p + 1;
|
||||
}
|
||||
return tiny_region_id_write_header(p, 7);
|
||||
}
|
||||
|
||||
@ -112,7 +137,7 @@ void* tiny_c7_ultra_alloc(size_t size) {
|
||||
if (__builtin_expect(p == NULL, 0)) {
|
||||
return so_alloc(7);
|
||||
}
|
||||
void* next = *(void**)p;
|
||||
void* next = ultra_load_next(p);
|
||||
tls->freelist = next;
|
||||
if (tls->page_meta) {
|
||||
tls->page_meta->freelist = next;
|
||||
@ -123,6 +148,9 @@ void* tiny_c7_ultra_alloc(size_t size) {
|
||||
if (tls->used < tls->capacity) {
|
||||
tls->used++;
|
||||
}
|
||||
if (header_light && tls->headers_initialized) {
|
||||
return (uint8_t*)p + 1;
|
||||
}
|
||||
return tiny_region_id_write_header(p, 7);
|
||||
}
|
||||
|
||||
@ -158,7 +186,7 @@ void tiny_c7_ultra_free(void* ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
*(void**)ptr = page->freelist;
|
||||
ultra_store_next(ptr, page->freelist);
|
||||
page->freelist = ptr;
|
||||
if (page->used > 0) {
|
||||
page->used--;
|
||||
|
||||
Reference in New Issue
Block a user