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

Message ID 1515694853-7949-1-git-send-email-vipin.varghese@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Varghese, Vipin Jan. 11, 2018, 6:20 p.m. UTC
  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@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(+)
  

Comments

Thomas Monjalon Jan. 25, 2018, 10:10 p.m. UTC | #1
11/01/2018 19:20, Vipin Varghese:
> 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.

This is a changelog. It should appear below ---

> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>

Why not keeping previous ack?

Your patches have been set to "Not Applicable" in patchwork.
What happened?
  
Van Haaren, Harry Jan. 26, 2018, 10:10 a.m. UTC | #2
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Thursday, January 25, 2018 10:11 PM
> To: Varghese, Vipin <vipin.varghese@intel.com>
> Cc: dev@dpdk.org; Van Haaren, Harry <harry.van.haaren@intel.com>;
> Richardson, Bruce <bruce.richardson@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v2] service: fix memory leak by
> rte_service_init
> 
> 11/01/2018 19:20, Vipin Varghese:
> > 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.
> 
> This is a changelog. It should appear below ---
> 
> > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> 
> Why not keeping previous ack?
> 
> Your patches have been set to "Not Applicable" in patchwork.
> What happened?


There was some confusion in my review-comments, and Vipin and I discussed
the best was to rework - I suggested marking the current patches as Not Applicable.

Is there a better state to put the patches in Patchwork if we don't want commiters to look at them?
Or would an email to the thread stating V+1 in progress be better?

A new version will hit the ML soon.
  
Thomas Monjalon Jan. 26, 2018, 1:18 p.m. UTC | #3
26/01/2018 11:10, Van Haaren, Harry:
> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > Your patches have been set to "Not Applicable" in patchwork.
> > What happened?
> 
> There was some confusion in my review-comments, and Vipin and I discussed
> the best was to rework - I suggested marking the current patches as Not Applicable.
> 
> Is there a better state to put the patches in Patchwork if we don't want commiters to look at them?
> Or would an email to the thread stating V+1 in progress be better?

Yes, an email is always good to notify about the status.
In patchwork, you can use the state "Changes requested".
"Not Applicable" is used for patches which were never intended
to be applicable.

> A new version will hit the ML soon.
  

Patch

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;