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链表中

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值