Skip to content

Commit

Permalink
dpdk: release mempool after the device is closed
Browse files Browse the repository at this point in the history
Ticket: OISF#5936
  • Loading branch information
Lukas Sismis authored and lukashino committed Apr 18, 2023
1 parent 148377a commit f1eb5d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/runmode-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,10 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface)
// This counter is increased by worker threads that individually pick queue IDs.
SC_ATOMIC_RESET(iconf->queue_id);
SC_ATOMIC_RESET(iconf->inconsitent_numa_cnt);

// initialize LiveDev DPDK values
LiveDevice *ldev_instance = LiveGetDevice(iface);
ldev_instance->dpdk_vars.pkt_mp = iconf->pkt_mempool;
return iconf;
}

Expand Down
5 changes: 1 addition & 4 deletions src/source-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,7 @@ static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *tv, void *data)
rte_eth_dev_stop(ptv->out_port_id);
}

if (ptv->queue_id == 0 && ptv->pkt_mempool != NULL) {
rte_mempool_free(ptv->pkt_mempool);
ptv->pkt_mempool = NULL;
}
ptv->pkt_mempool = NULL; // MP is released when device is closed

SCFree(ptv);
SCReturnInt(TM_ECODE_OK);
Expand Down
14 changes: 14 additions & 0 deletions src/util-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#ifndef __UTIL_DEVICE_H__
#define __UTIL_DEVICE_H__

#ifdef HAVE_DPDK
#include <rte_mempool.h>
#endif /* HAVE_DPDK */

#include "queue.h"

#define OFFLOAD_FLAG_SG (1<<0)
Expand All @@ -35,6 +39,12 @@ int LiveGetOffload(void);

#define MAX_DEVNAME 10

#ifdef HAVE_DPDK
typedef struct {
struct rte_mempool *pkt_mp;
} DPDKDeviceResources;
#endif /* HAVE_DPDK */

/** storage for live device names */
typedef struct LiveDevice_ {
char *dev; /**< the device (e.g. "eth0") */
Expand All @@ -51,6 +61,10 @@ typedef struct LiveDevice_ {

uint32_t tenant_id; /**< tenant id in multi-tenancy */
uint32_t offload_orig; /**< original offload settings to restore @exit */
#ifdef HAVE_DPDK
// DPDK resources that needs to be cleaned after workers are stopped and devices closed
DPDKDeviceResources dpdk_vars;
#endif
} LiveDevice;

typedef struct LiveDeviceName_ {
Expand Down
3 changes: 3 additions & 0 deletions src/util-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void DPDKCloseDevice(LiveDevice *ldev)

SCLogInfo("%s: closing device", ldev->dev);
rte_eth_dev_close(port_id);

SCLogInfo("%s: releasing packet mempool", ldev->dev);
rte_mempool_free(ldev->dpdk_vars.pkt_mp);
}
#endif
}

0 comments on commit f1eb5d6

Please sign in to comment.