[dpdk-dev] [PATCH v2] service: fix memory leak by rte_service_init

Vipin Varghese vipin.varghese at intel.com
Thu Jan 11 19:20:53 CET 2018


This patch fixes the memory leak created by rte_service_init. When
secondary application which shares the huge page from primary, is
executed multiple times memory is initialized but not freed on exit

The rte_service_finalize checks if the service is initialized. If yes,
it frees up rte_services & lcore_states. The API has to be called at
end of application run.

renamed the function from rte_service_deinit to rte_service_finalize.

Signed-off-by: Vipin Varghese <vipin.varghese at intel.com>
---
 lib/librte_eal/common/include/rte_service.h | 14 ++++++++++++++
 lib/librte_eal/common/rte_service.c         | 13 +++++++++++++
 lib/librte_eal/rte_eal_version.map          |  1 +
 3 files changed, 28 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5a76383..45a8035 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -392,6 +392,20 @@ int32_t rte_service_run_iter_on_app_lcore(uint32_t id,
  */
 int32_t rte_service_dump(FILE *f, uint32_t id);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Finalize the service library.
+ *
+ * The service library, which is been initialized occupies DPDK memory.
+ * This routine cleans up the memory. It should be invoked prior to process
+ * termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c
index 372d0bb..a848232 100644
--- a/lib/librte_eal/common/rte_service.c
+++ b/lib/librte_eal/common/rte_service.c
@@ -108,6 +108,19 @@ int32_t rte_service_init(void)
 	return 0;
 }
 
+void rte_service_finalize(void)
+{
+	if (rte_service_library_initialized) {
+		if (rte_services)
+			rte_free(rte_services);
+		if (lcore_states)
+			rte_free(lcore_states);
+
+		rte_service_library_initialized = 0;
+	}
+}
+
+
 /* returns 1 if service is registered and has not been unregistered
  * Returns 0 if service never registered, or has been unregistered
  */
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index f4f46c1..c73a72f 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -234,5 +234,6 @@ EXPERIMENTAL {
 	rte_service_set_runstate_mapped_check;
 	rte_service_set_stats_enable;
 	rte_service_start_with_defaults;
+	rte_service_finalize;
 
 } DPDK_17.11;
-- 
1.9.1



More information about the dev mailing list