Aerospike partition tree的内存管理
as_namespaces_init:
1、uint32_t stage_capacity = as_mem_check()
for (capacity = MAX_STAGE_CAPACITY; capacity >= MIN_STAGE_CAPACITY; capacity /= 2) {
if (check_capacity(capacity)) {
break;
}
}
申请的内存大小以16M开始,如果内存大小不够用,则申请16/2M依次类推,小大小是2M
2、as_namespaces_setup(cold_start_cmd, instance, stage_capacity);
->setup_namespace(g_config.namespaces[i], stage_capacity);
->ns->arena = (cf_arenax*)cf_malloc(cf_arenax_sizeof());
cf_arenax_err arena_result = cf_arenax_create(ns->arena, 0,
as_index_size_get(ns), stage_capacity, 0, CF_ARENAX_BIGLOCK);
->uint64_t stage_size = (uint64_t)stage_capacity * sizeof(as_index);
memset(this->stages, 0, sizeof(this->stages));
uint8_t* p_stage = (uint8_t*)cf_malloc(this->stage_size);
this->stages[this->stage_count++] = p_stage;
memset(cf_arenax_resolve(this, 0), 0, sizeof(as_index));
ns->arena->stages[256]共有256个内存stage。
开始,只申请对个stages申请16M*sizeof(as_index)的内存空间。
3、as_partition_init(ns, pid);
->p->vp = as_index_tree_create(&ns->tree_shared, ns->arena);
->tree->arena = arena;
对partition进行初始化,树的内存都是共用一个arena,即ns->arena
run_index_tree_gc:线程回收tree的内存
1、从g_gc_queue队列中pop出回收的tree,然后调用as_index_tree_destroy函数回收
while (cf_queue_pop(&g_gc_queue, &tree, CF_QUEUE_FOREVER) == CF_QUEUE_OK) {
as_index_tree_destroy(tree);
}
2、递归调用as_index_sprig_traverse_purge进行回收
即将tree的每个element的handle回收到arena的free_h链表中
————————————————
版权声明:本文为CSDN博主「yzs87」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yanzongshuai/article/details/78573028
相关文章