Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

CORTX-33740 : Analyse and fix memory leaks created by ctg module using s3 IOs. #2098

Merged
merged 6 commits into from
Aug 29, 2022
Merged
1 change: 0 additions & 1 deletion be/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,6 @@ static int64_t tree_get(struct node_op *op, struct segaddr *addr, int nxt)
return nxt;
}


/**
* Returns the tree to the free tree pool if the reference count for this tree
* reaches zero.
Expand Down
23 changes: 16 additions & 7 deletions cas/ctg_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ int m0_ctg_create(struct m0_be_seg *seg, struct m0_be_tx *tx,
bt.vsize = sizeof(struct meta_value);
break;
case CTT_DEADIDX:
bt.ksize = sizeof(struct meta_value);
bt.vsize = sizeof(void *);
bt.ksize = sizeof(struct generic_key *) + sizeof(void *);
bt.vsize = sizeof(void *);
break;
case CTT_CTIDX:
bt.ksize = sizeof(struct fid_key);
Expand Down Expand Up @@ -966,6 +966,10 @@ static void ctg_store_release(struct m0_ref *ref)

M0_ENTRY();
m0_mutex_fini(&ctg_store->cs_state_mutex);
// TODO: Cleanup all in-memory allocations done for indices in meta tree
ctg_fini(ctg_store->cs_state->cs_meta);
ctg_fini(ctg_store->cs_ctidx);
ctg_fini(ctg_store->cs_dead_index);
ctg_store->cs_state = NULL;
ctg_store->cs_ctidx = NULL;
m0_long_lock_fini(&ctg_store->cs_del_lock);
Expand Down Expand Up @@ -1382,14 +1386,14 @@ static int ctg_op_exec_normal(struct m0_ctg_op *ctg_op, int next_phase)
* m0_be_btree_insert_inplace() have 0 there.
*/

vsize = sizeof(struct generic_value);
vsize = sizeof(void *);
rec.r_key.k_data = M0_BUFVEC_INIT_BUF(&k_ptr, &ksize);
rec.r_val = M0_BUFVEC_INIT_BUF(&v_ptr, &vsize);
rec.r_crc_type = M0_BCT_NO_CRC;

rc = M0_BTREE_OP_SYNC_WITH_RC(&kv_op,
rc = M0_BTREE_OP_SYNC_WITH_RC(&kv_op,
m0_btree_put(btree, &rec, &cb,
&kv_op, tx));
&kv_op, tx));
m0_be_op_done(beop);
break;
case CTG_OP_COMBINE(CO_GET, CT_BTREE):
Expand Down Expand Up @@ -1425,6 +1429,8 @@ static int ctg_op_exec_normal(struct m0_ctg_op *ctg_op, int next_phase)
&kv_op, tx));
m0_be_op_done(beop);
break;
case CTG_OP_COMBINE(CO_DEL, CT_DEAD_INDEX):
ksize = sizeof(struct generic_key *) + sizeof(void *);
case CTG_OP_COMBINE(CO_DEL, CT_BTREE):
case CTG_OP_COMBINE(CO_DEL, CT_META):
m0_be_op_active(beop);
Expand Down Expand Up @@ -1665,8 +1671,11 @@ static int ctg_exec(struct m0_ctg_op *ctg_op,
{
int ret = M0_FSO_AGAIN;

ctg_op->co_ctg = ctg;
ctg_op->co_ct = CT_BTREE;
/* Do not overwrite ctg_op params if co_ct == CT_DEAD_INDEX. */
if (ctg_op->co_ct != CT_DEAD_INDEX) {
ctg_op->co_ctg = ctg;
ctg_op->co_ct = CT_BTREE;
}

if (!M0_IN(ctg_op->co_opcode, (CO_MIN, CO_TRUNC, CO_DROP)) &&
(ctg_op->co_opcode != CO_CUR ||
Expand Down
12 changes: 9 additions & 3 deletions cas/index_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ static int cgc_fom_tick(struct m0_fom *fom0)
fom->cg_ctg_op_initialized = true;
result = m0_ctg_drop(ctg_op, fom->cg_ctg,
CGC_LOCK_DEAD_INDEX);
/**
* Free the memory allocated for the root node after
* destroying the tree.
*/
m0_free0(&fom->cg_ctg->cc_tree);
} else {
M0_LOG(M0_DEBUG, "out of credits, commit & restart");
m0_long_unlock(m0_ctg_lock(m0_ctg_dead_index()),
Expand All @@ -387,13 +392,14 @@ static int cgc_fom_tick(struct m0_fom *fom0)
m0_ctg_op_fini(ctg_op);
m0_ctg_op_init(ctg_op, fom0, 0);
fom->cg_ctg_op_initialized = true;
fom->cg_ctg_key = M0_BUF_INIT(M0_CAS_CTG_KEY_HDR_SIZE,
&fom->cg_ctg);
fom->cg_ctg_key = M0_BUF_INIT_PTR(&fom->cg_ctg);
/*
* Now completely forget this ctg by deleting its descriptor
* from "dead index" catalogue.
*/
result = m0_ctg_delete(ctg_op, m0_ctg_dead_index(),
ctg_op->co_ct = CT_DEAD_INDEX;
ctg_op->co_ctg = m0_ctg_dead_index();
result = m0_ctg_delete(ctg_op, m0_ctg_dead_index(),
&fom->cg_ctg_key, CGC_SUCCESS);
break;
case CGC_SUCCESS:
Expand Down
Loading