绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
Aerospike partition tree的内存管理
2022-06-21 15:52:35

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

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Aerospike
创建时间:2022-04-14 10:06:31
Aerospike
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • LCR_
    专家
戳我,来吐槽~