51 lines
1.8 KiB
C
51 lines
1.8 KiB
C
|
|
#include "shared_pool_box.h"
|
||
|
|
|
||
|
|
#include <stdatomic.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
// 既存の g_shared_pool 配列上に「論理的な上限」だけを被せる。
|
||
|
|
static _Atomic uint32_t g_sp_total_limit = 0; // 0 = 無制限(現行のまま)
|
||
|
|
static _Atomic uint32_t g_sp_class_limit = 0; // 0 = 無制限
|
||
|
|
static _Atomic int g_sp_profile_inited = 0;
|
||
|
|
|
||
|
|
static void shared_pool_apply_profile(const char* profile) {
|
||
|
|
if (g_sp_profile_inited) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const char* env_profile = profile ? profile : getenv("HAKMEM_PROFILE");
|
||
|
|
int is_bench = (env_profile && strcmp(env_profile, "bench") == 0);
|
||
|
|
|
||
|
|
uint32_t total_limit = 0;
|
||
|
|
uint32_t class_limit = 0;
|
||
|
|
if (is_bench) {
|
||
|
|
// bench 用: ひとまず控えめな論理上限だけ入れる
|
||
|
|
total_limit = 65536; // 元の 1M よりかなり少ない
|
||
|
|
class_limit = 2048; // クラスあたりの active slot 上限の目安
|
||
|
|
}
|
||
|
|
|
||
|
|
atomic_store_explicit(&g_sp_total_limit, total_limit, memory_order_relaxed);
|
||
|
|
atomic_store_explicit(&g_sp_class_limit, class_limit, memory_order_relaxed);
|
||
|
|
atomic_store_explicit(&g_sp_profile_inited, 1, memory_order_release);
|
||
|
|
}
|
||
|
|
|
||
|
|
void shared_pool_box_init(SharedPoolBox* box, const char* profile) {
|
||
|
|
(void)box;
|
||
|
|
shared_pool_apply_profile(profile);
|
||
|
|
}
|
||
|
|
|
||
|
|
uint32_t shared_pool_effective_total_slots(void) {
|
||
|
|
if (!atomic_load_explicit(&g_sp_profile_inited, memory_order_acquire)) {
|
||
|
|
shared_pool_apply_profile(NULL);
|
||
|
|
}
|
||
|
|
return atomic_load_explicit(&g_sp_total_limit, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
|
||
|
|
uint32_t shared_pool_effective_class_slots(int class_idx) {
|
||
|
|
(void)class_idx;
|
||
|
|
if (!atomic_load_explicit(&g_sp_profile_inited, memory_order_acquire)) {
|
||
|
|
shared_pool_apply_profile(NULL);
|
||
|
|
}
|
||
|
|
return atomic_load_explicit(&g_sp_class_limit, memory_order_relaxed);
|
||
|
|
}
|