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

Message ID 1514731568-3979-1-git-send-email-vipin.varghese@intel.com (mailing list archive)
State Not Applicable, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Varghese, Vipin Dec. 31, 2017, 2:46 p.m. UTC
  This patch fixes the memory leak created by rte_service_init, when
run from secondary application. Running secondary application which
shares the huge page memory from primary multiple times causes memory
to be initialized but not free when application exit.

The rte_service_deinit check 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.

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

Comments

Van Haaren, Harry Jan. 8, 2018, 10:17 a.m. UTC | #1
> From: Varghese, Vipin
> Sent: Sunday, December 31, 2017 2:46 PM
> To: dev@dpdk.org; Van Haaren, Harry <harry.van.haaren@intel.com>
> Cc: Jain, Deepak K <deepak.k.jain@intel.com>; Varghese, Vipin
> <vipin.varghese@intel.com>
> Subject: [PATCH v1] service: fix memory leak by rte_service_init
> 
> This patch fixes the memory leak created by rte_service_init, when
> run from secondary application. Running secondary application which
> shares the huge page memory from primary multiple times causes memory
> to be initialized but not free when application exit.
> 
> The rte_service_deinit check 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.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>

<snip>

> +++ b/lib/librte_eal/common/rte_service.c
> @@ -98,6 +98,20 @@ struct core_state {
>  static struct core_state *lcore_states;
>  static uint32_t rte_service_library_initialized;
> 
> +void rte_service_deinit(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;
> +	}
> +	return;
> +}

No return required from void functions

> +
> +
>  int32_t rte_service_init(void)
>  {
>  	if (rte_service_library_initialized) {
> diff --git a/lib/librte_eal/rte_eal_version.map
> b/lib/librte_eal/rte_eal_version.map
> index f4f46c1..0f14409 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_deinit;

Alphabetical ordering in the .map files (vim has a nice feature; visual select service functions  then  :sort )

With above changes;
Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
  
Bruce Richardson Jan. 8, 2018, 2:40 p.m. UTC | #2
On Mon, Jan 08, 2018 at 10:17:14AM +0000, Van Haaren, Harry wrote:
> > From: Varghese, Vipin
> > Sent: Sunday, December 31, 2017 2:46 PM
> > To: dev@dpdk.org; Van Haaren, Harry <harry.van.haaren@intel.com>
> > Cc: Jain, Deepak K <deepak.k.jain@intel.com>; Varghese, Vipin
> > <vipin.varghese@intel.com>
> > Subject: [PATCH v1] service: fix memory leak by rte_service_init
> > 
> > This patch fixes the memory leak created by rte_service_init, when
> > run from secondary application. Running secondary application which
> > shares the huge page memory from primary multiple times causes memory
> > to be initialized but not free when application exit.
> > 
> > The rte_service_deinit check 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.
> > 
> > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> 
> <snip>
> 
> > +++ b/lib/librte_eal/common/rte_service.c
> > @@ -98,6 +98,20 @@ struct core_state {
> >  static struct core_state *lcore_states;
> >  static uint32_t rte_service_library_initialized;
> > 
> > +void rte_service_deinit(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;
> > +	}
> > +	return;
> > +}
> 
> No return required from void functions
> 
> > +
> > +
> >  int32_t rte_service_init(void)
> >  {
> >  	if (rte_service_library_initialized) {
> > diff --git a/lib/librte_eal/rte_eal_version.map
> > b/lib/librte_eal/rte_eal_version.map
> > index f4f46c1..0f14409 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_deinit;
> 
> Alphabetical ordering in the .map files (vim has a nice feature; visual select service functions  then  :sort )
> 
> With above changes;
> Acked-by: Harry van Haaren <harry.van.haaren@intel.com>

Is the opposite of init not "uninit" rather than "deinit"?
Alternatively, "finalize" could be used as the opposite of "initialize",
which would be close to ".init" and ".fini" as used in ELF files.

/Bruce
  

Patch

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 9272440..ad2649e 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -420,6 +420,15 @@  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
+ *
+ * Fress all memory that is internally used.
+ */
+
+void rte_service_deinit(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c
index ae97e6b..017bc67 100644
--- a/lib/librte_eal/common/rte_service.c
+++ b/lib/librte_eal/common/rte_service.c
@@ -98,6 +98,20 @@  struct core_state {
 static struct core_state *lcore_states;
 static uint32_t rte_service_library_initialized;
 
+void rte_service_deinit(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;
+	}
+	return;
+}
+
+
 int32_t rte_service_init(void)
 {
 	if (rte_service_library_initialized) {
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index f4f46c1..0f14409 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_deinit;
 
 } DPDK_17.11;