From ec2de064ee7aebb6559ac25171262dad5eaa6fe5 Mon Sep 17 00:00:00 2001 From: "Vinoth.V" Date: Wed, 3 Aug 2022 05:27:16 -0600 Subject: [PATCH] CORTX-32859: Fix m0_fid_arr_copy memory leak - During profile_decode, m0_fid_arr_copy is allocating memory for af_elems and it is not freed in profile_delete - Explicit free of af_elems in profile_delete Signed-off-by: Vinoth.V --- conf/objs/profile.c | 1 + fid/fid.c | 6 +++ fid/fid.h | 1 + .../seagate/cortx/motr/bin/motr_mini_prov.py | 38 ++++++++++--------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/conf/objs/profile.c b/conf/objs/profile.c index 58d4af0035e..e20c641cacf 100644 --- a/conf/objs/profile.c +++ b/conf/objs/profile.c @@ -78,6 +78,7 @@ static void profile_delete(struct m0_conf_obj *obj) struct m0_conf_profile *x = M0_CONF_CAST(obj, m0_conf_profile); m0_conf_profile_bob_fini(x); + m0_fid_arr_free(&x->cp_pools); m0_free(x); } diff --git a/fid/fid.c b/fid/fid.c index abcf10b5bb2..9467d8d6a20 100644 --- a/fid/fid.c +++ b/fid/fid.c @@ -316,6 +316,12 @@ M0_INTERNAL int m0_fid_arr_copy(struct m0_fid_arr *to, return M0_RC(0); } +M0_INTERNAL void m0_fid_arr_free(struct m0_fid_arr *a) +{ + m0_free(a->af_elems); +} + + M0_INTERNAL bool m0_fid_arr_eq(const struct m0_fid_arr *a, const struct m0_fid_arr *b) { diff --git a/fid/fid.h b/fid/fid.h index c21821c8552..62f8c374975 100644 --- a/fid/fid.h +++ b/fid/fid.h @@ -119,6 +119,7 @@ M0_INTERNAL uint64_t m0_fid_hash(const struct m0_fid *fid); M0_INTERNAL int m0_fid_arr_copy(struct m0_fid_arr *to, const struct m0_fid_arr *from); +M0_INTERNAL void m0_fid_arr_free(struct m0_fid_arr *a); M0_INTERNAL bool m0_fid_arr_eq(const struct m0_fid_arr *a, const struct m0_fid_arr *b); M0_INTERNAL bool m0_fid_arr_all_unique(const struct m0_fid_arr *a); diff --git a/scripts/install/opt/seagate/cortx/motr/bin/motr_mini_prov.py b/scripts/install/opt/seagate/cortx/motr/bin/motr_mini_prov.py index 6575238797f..dfdf7f6d751 100644 --- a/scripts/install/opt/seagate/cortx/motr/bin/motr_mini_prov.py +++ b/scripts/install/opt/seagate/cortx/motr/bin/motr_mini_prov.py @@ -508,12 +508,9 @@ def motr_tune_memory_config(self): create_dirs(self, [f"{MOTR_LOCAL_SYSCONFIG_DIR}"]) MOTR_M0D_CONF_FILE_PATH = f"{MOTR_LOCAL_SYSCONFIG_DIR}/{machine_id}/motr" - # Copy motr to motr-io - cmd = f"cp {MOTR_M0D_CONF_FILE_PATH} {MOTR_M0D_CONF_FILE_PATH}-io" - execute_command(self, cmd) if not os.path.exists(MOTR_M0D_CONF_FILE_PATH): - self.logger.info(f"FILE not founf {MOTR_M0D_CONF_FILE_PATH}\n") + self.logger.debug(f"FILE not found {MOTR_M0D_CONF_FILE_PATH}\n") return # collect the memory and cpu limits. @@ -525,33 +522,40 @@ def motr_tune_memory_config(self): cpu_min = arr_elem['cpu']['min'] cpu_max = arr_elem['cpu']['max'] - self.logger.info(f"Avaiable memory {mem_min} {mem_max}\n") - self.logger.info(f"Avaiable CPU {cpu_min} {cpu_max}\n") + self.logger.debug(f"memory for io {mem_min} {mem_max}\n") + self.logger.debug(f"Avaiable memory {mem_min} {mem_max}\n") + self.logger.debug(f"Avaiable CPU {cpu_min} {cpu_max}\n") M1 = int(calc_resource_sz(self, mem_min) / (1024 * 1024)) M2 = int(calc_resource_sz(self, mem_max) / (1024 * 1024)) if M1 == 0 or M2 == 0: - self.logger.info(f"memory for io mem req:{M1} mem limit: {M2}\n") + self.logger.debug(f"memory for io mem req:{M1} mem limit: {M2}\n") return - if M2 > 4096: + # update motr config using formula + factor_1 = math.floor(M2/512) + self.logger.info(f"memory for io {M1} {M2} {factor_1}\n") + + if M2 < 4096: + MIN_RPC_RECVQ_LEN = 2 ** factor_1 + else: MIN_RPC_RECVQ_LEN = 512 - self.logger.info(f"setting MOTR_M0D_MIN_RPC_RECVQ_LEN to {MIN_RPC_RECVQ_LEN}\n") - cmd = f'sed -i "/MOTR_M0D_MIN_RPC_RECVQ_LEN=/s/.*/MOTR_M0D_MIN_RPC_RECVQ_LEN={MIN_RPC_RECVQ_LEN}/" {MOTR_M0D_CONF_FILE_PATH}' - execute_command(self, cmd) + self.logger.debug(f"setting MOTR_M0D_MIN_RPC_RECVQ_LEN to {MIN_RPC_RECVQ_LEN}\n") + cmd = f'sed -i "/MOTR_M0D_MIN_RPC_RECVQ_LEN/s/.*/MOTR_M0D_MIN_RPC_RECVQ_LEN={MIN_RPC_RECVQ_LEN}/" {MOTR_M0D_CONF_FILE_PATH}' + execute_command(self, cmd) - IOS_BUFFER_POOL_SIZE = MIN_RPC_RECVQ_LEN * 2 - self.logger.info(f"setting MOTR_M0D_IOS_BUFFER_POOL_SIZE to {IOS_BUFFER_POOL_SIZE}\n") - cmd = f'sed -i "/MOTR_M0D_IOS_BUFFER_POOL_SIZE=/s/.*/MOTR_M0D_IOS_BUFFER_POOL_SIZE={IOS_BUFFER_POOL_SIZE}/" {MOTR_M0D_CONF_FILE_PATH}' - execute_command(self, cmd) + IOS_BUFFER_POOL_SIZE = 16 * (2 ** (factor_1 - 1)) + self.logger.debug(f"setting MOTR_M0D_IOS_BUFFER_POOL_SIZE to {IOS_BUFFER_POOL_SIZE}\n") + cmd = f'sed -i "/MOTR_M0D_IOS_BUFFER_POOL_SIZE/s/.*/MOTR_M0D_IOS_BUFFER_POOL_SIZE={IOS_BUFFER_POOL_SIZE}/" {MOTR_M0D_CONF_FILE_PATH}' + execute_command(self, cmd) if M2 <= 1024: SNS_BUFFER_POOL_SIZE = 32 else: SNS_BUFFER_POOL_SIZE = 64 - self.logger.info(f"setting MOTR_M0D_SNS_BUFFER_POOL_SIZE to {SNS_BUFFER_POOL_SIZE}\n") - cmd = f'sed -i "/MOTR_M0D_SNS_BUFFER_POOL_SIZE=/s/.*/MOTR_M0D_SNS_BUFFER_POOL_SIZE={SNS_BUFFER_POOL_SIZE}/" {MOTR_M0D_CONF_FILE_PATH}' + self.logger.debug(f"setting MOTR_M0D_SNS_BUFFER_POOL_SIZE to {SNS_BUFFER_POOL_SIZE}\n") + cmd = f'sed -i "/MOTR_M0D_SNS_BUFFER_POOL_SIZE/s/.*/MOTR_M0D_SNS_BUFFER_POOL_SIZE={SNS_BUFFER_POOL_SIZE}/" {MOTR_M0D_CONF_FILE_PATH}' execute_command(self, cmd) # Get lists of metadata disks from Confstore of all cvgs