fix memory leak
cover fix memory leak
This patch set fix memory leak in vdev and example hotplug_mp.
Wenjun Wu (2):
bus/vdev: fix memory leak
examples/multi_process: fix memory leak
drivers/bus/vdev/vdev.c | 5 +++++ examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++ 2 files changed, 27 insertions(+)
Signature · 1 line
2.34.1
PATCH 1/2 bus/vdev: fix memory leak
In hotplug usecase, devargs will be allocated in secondary process in the function alloc_devargs. Since it will not be insert into the devarg_list, it will have no chance to be freed.
This patch adds additional memory free for device structure member devargs in the secondary process in rte_vdev_uninit.
--- drivers/bus/vdev/vdev.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/bus/vdev/vdev.c +5 -0
@@ -373,6 +373,11 @@ rte_vdev_uninit(const char *name)TAILQ_REMOVE (&vdev_device_list, dev, next);rte_devargs_remove (dev->device.devargs); +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + dev->device.devargs !=NULL ) { +rte_devargs_reset (dev->device.devargs); +free (dev->device.devargs); + }free (dev); unlock:
Signature · 1 line
2.34.1
Re: [PATCH v1 1/2] bus/vdev: fix memory leak
Quoted 20 lines · Wenjun Wu
In hotplug usecase, devargs will be allocated in secondary process in the function
alloc_devargs. Since it will not be insert into thedevarg_list, it will have no chance to be freed.This patch adds additional memory free for device structure member devargs in the secondary process in
rte_vdev_uninit.Fixes f5b2eff0847d ("bus/vdev: fix devargs after multi-process bus scan")Signed-off-by Wenjun Wu <[email protected]>--- drivers/bus/vdev/vdev.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/bus/vdev/vdev.c +0
-0
drivers/bus/vdev/vdev.c rte_vdev_uninit(const char *name) · line 377
Quoted 5 lines
drivers/bus/vdev/vdev.c +2
-0@@ -373,6 +373,11 @@ rte_vdev_uninit(const char *name)TAILQ_REMOVE (&vdev_device_list, dev, next);rte_devargs_remove (dev->device.devargs); +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + dev->device.devargs !=NULL ) {
The prerequisite is that rte_vdev_init is invoked only in main process.
Suggest more general impl:
ret = rte_devargs_remove(dev->device.devargs);
if (ret != 0) {
rte_devargs_reset(dev->device.devargs);
free(dev->device.devargs);
}Quoted 7 lines
drivers/bus/vdev/vdev.c +3
-0+rte_devargs_reset (dev->device.devargs); +free (dev->device.devargs); + }free (dev); unlock:
PATCH 2/2 examples/multi_process: fix memory leak
In reply to Wenjun WuThe device should be detached before quit, otherwise it will cause memory leak.
--- examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+)
examples/multi_process/hotplug_mp/commands.c +22 -0
@@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,struct cmdline *cl, __rte_unused void *data) { + uint16_t port_id; +char dev_name[RTE_DEV_NAME_MAX_LEN ]; +struct rte_devargs da; + +RTE_ETH_FOREACH_DEV (port_id) { +rte_eth_dev_get_name_by_port (port_id, dev_name); +memset (&da,0 ,sizeof (da)); + +if (rte_devargs_parsef (&da,"%s" , dev_name)) { +cmdline_printf (cl, +"cannot parse devargs for device %s\n" , + dev_name); + } +printf ("detaching before quit...\n" ); +if (!rte_eal_hotplug_remove (rte_bus_name (da.bus), da.name)) +cmdline_printf (cl,"detached device %s\n" , + da.name); +else +cmdline_printf (cl,"failed to detach device %s\n" , + da.name); + + }cmdline_quit (cl); }
Signature · 1 line
2.34.1
Re: [PATCH v1 2/2] examples/multi_process: fix memory leak
Quoted 2 lines · Wenjun Wu
The device should be detached before quit, otherwise it will cause memory leak.
Which memory will leak?
For mp, if secondary process quit, it only needs to properly handle the memory shared with other process.
Quoted 43 lines
Fixes 05f1d6842fc3 ("examples/multi_process: add hotplug sample")Signed-off-by Wenjun Wu <[email protected]>--- examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+)examples/multi_process/hotplug_mp/commands.c +22
-0@@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,struct cmdline *cl, __rte_unused void *data) { + uint16_t port_id; +char dev_name[RTE_DEV_NAME_MAX_LEN ]; +struct rte_devargs da; + +RTE_ETH_FOREACH_DEV (port_id) { +rte_eth_dev_get_name_by_port (port_id, dev_name); +memset (&da,0 ,sizeof (da)); + +if (rte_devargs_parsef (&da,"%s" , dev_name)) { +cmdline_printf (cl, +"cannot parse devargs for device %s\n" , + dev_name); + } +printf ("detaching before quit...\n" ); +if (!rte_eal_hotplug_remove (rte_bus_name (da.bus), da.name)) +cmdline_printf (cl,"detached device %s\n" , + da.name); +else +cmdline_printf (cl,"failed to detach device %s\n" , + da.name); + + }cmdline_quit (cl); }
RE: [PATCH v1 2/2] examples/multi_process: fix memory leak
Hi Chengwen,
Thanks for reviewing.
The memory leak occurs similar as what mentioned in https://patches.dpdk.org/project/dpdk/patch/[email protected]/.
I will perfect the commit description in V2 version.
Thanks,
Wenjun
Quoted 64 lines
-----Original Message-----
From: fengchengwen <[email protected]>
Sent: Thursday, July 6, 2023 9:02 AM
To: Wu, Wenjun1 <[email protected]>; [email protected]; Burakov, Anatoly <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: Su, Simei <[email protected]>; [email protected]
Subject: Re: [PATCH v1 2/2] examples/multi_process: fix memory leakQuoted 2 lines · Wenjun Wu
The device should be detached before quit, otherwise it will cause memory leak.
Which memory will leak?
For mp, if secondary process quit, it only needs to properly handle the memory shared with other process.
examples/multi_process/hotplug_mp/commands.c static void cmd_quit_parsed(__rte_unused void
Quoted 16 lines
Fixes 05f1d6842fc3 ("examples/multi_process: add hotplug sample")Signed-off-by Wenjun Wu <[email protected]>--- examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+)examples/multi_process/hotplug_mp/commands.c +0
-0@@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void
*parsed_result,Quoted 8 lines
examples/multi_process/hotplug_mp/commands.c +5
-0struct cmdline *cl, __rte_unused void *data) { + uint16_t port_id; +char dev_name[RTE_DEV_NAME_MAX_LEN ]; +struct rte_devargs da; + +RTE_ETH_FOREACH_DEV (port_id) {examples/multi_process/hotplug_mp/commands.c static void cmd_quit_parsed(__rte_unused void *parsed_result,
Quoted 10 lines
examples/multi_process/hotplug_mp/commands.c +10
-0+rte_eth_dev_get_name_by_port (port_id, dev_name); +memset (&da,0 ,sizeof (da)); + +if (rte_devargs_parsef (&da,"%s" , dev_name)) { +cmdline_printf (cl, +"cannot parse devargs for device %s\n" , + dev_name); + } +printf ("detaching before quit...\n" ); + if (!rte_eal_hotplug_remove(rte_bus_name(da.bus),da.name))
Quoted 11 lines
examples/multi_process/hotplug_mp/commands.c +7
-0+cmdline_printf (cl,"detached device %s\n" , + da.name); + else + cmdline_printf(cl, "failed to detach device %s\n", + da.name); + + }cmdline_quit (cl); }