diff --git a/doc/userguide/configuration/suricata-yaml.rst b/doc/userguide/configuration/suricata-yaml.rst index eb7edbe48c..3ff415777c 100644 --- a/doc/userguide/configuration/suricata-yaml.rst +++ b/doc/userguide/configuration/suricata-yaml.rst @@ -2289,17 +2289,22 @@ allocated on each of the NUMA nodes used by the Suricata deployment. DPDK memory pools hold packets received from NICs. These memory pools are -allocated in hugepages. One memory pool is allocated per interface. The size -of each memory pool can be individual and is set with the `mempool-size`. -Memory (in bytes) for one memory pool is calculated as: `mempool-size` * `mtu`. +allocated in hugepages. Each Suricata worker has independently allocated +memory pools per interface. The total size of all mempools of the interface is +set with the ``mempool-size``. The recommend size of the memory pool can be +auto-calculated by setting ``mempool-size: auto``. If ``mempool-size`` is set +manually (to e.g. ``mempool-size: 65536``), the value is divided by the number of +worker cores of the interface (on 4 worker threads, each worker is assigned +with a mempool containing 16383 packet objects). +Memory (in bytes) for interface's memory pools is calculated as: +``mempool-size`` * ``mtu``. The sum of memory pool requirements divided by the size of one hugepage results in the number of required hugepages. It causes no problem to allocate more memory than required, but it is vital for Suricata to not run out of hugepages. The mempool cache is local to the individual CPU cores and holds packets that -were recently processed. As the mempool is shared among all cores, the cache -tries to minimize the required inter-process synchronization. The recommended -size of the cache is covered in the YAML file. +were recently processed. The recommended size of the cache can be +auto-calculated by setting ``mempool-cache-size: auto``. To be able to run DPDK on Intel cards, it is required to change the default Intel driver to either `vfio-pci` or `igb_uio` driver. The process is diff --git a/doc/userguide/upgrade.rst b/doc/userguide/upgrade.rst index fb42fe328b..a88bc2e9ea 100644 --- a/doc/userguide/upgrade.rst +++ b/doc/userguide/upgrade.rst @@ -131,6 +131,9 @@ Major changes - DPDK interface settings can now be configured automatically by setting ``auto`` to ``mempool-size``, ``mempool-cache-size``, ``rx-descriptors``, ``tx-descriptors``. See :ref:`dpdk-automatic-interface-configuration`. +- DPDK interface mempools are now allocated per thread instead of per port. This + change improves performance and should not be visible from the user + configuration perspective. Removals ~~~~~~~~ diff --git a/src/Makefile.am b/src/Makefile.am index 389dc6eca7..09ee015d23 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -482,11 +482,12 @@ noinst_HEADERS = \ util-detect.h \ util-device.h \ util-dpdk.h \ + util-dpdk-bonding.h \ + util-dpdk-common.h \ util-dpdk-i40e.h \ util-dpdk-ice.h \ util-dpdk-ixgbe.h \ util-dpdk-mlx5.h \ - util-dpdk-bonding.h \ util-dpdk-rss.h \ util-ebpf.h \ util-enum.h \ @@ -1045,11 +1046,12 @@ libsuricata_c_a_SOURCES = \ util-detect.c \ util-device.c \ util-dpdk.c \ + util-dpdk-bonding.c \ + util-dpdk-common.c \ util-dpdk-i40e.c \ util-dpdk-ice.c \ util-dpdk-ixgbe.c \ util-dpdk-mlx5.c \ - util-dpdk-bonding.c \ util-dpdk-rss.c \ util-ebpf.c \ util-enum.c \ diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 27252964fb..6bc7954972 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -42,6 +42,7 @@ #include "util-device.h" #include "util-dpdk.h" #include "util-dpdk-bonding.h" +#include "util-dpdk-common.h" #include "util-dpdk-i40e.h" #include "util-dpdk-ice.h" #include "util-dpdk-ixgbe.h" @@ -333,10 +334,7 @@ static void DPDKDerefConfig(void *conf) DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf; if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) { - if (iconf->pkt_mempool != NULL) { - rte_mempool_free(iconf->pkt_mempool); - } - + DPDKDeviceResourcesDeinit(iconf->pkt_mempools); SCFree(iconf); } SCReturn; @@ -350,7 +348,6 @@ static void ConfigInit(DPDKIfaceConfig **iconf) if (ptr == NULL) FatalError("Could not allocate memory for DPDKIfaceConfig"); - ptr->pkt_mempool = NULL; ptr->out_port_id = -1; // make sure no port is set SC_ATOMIC_INIT(ptr->ref); (void)SC_ATOMIC_ADD(ptr->ref, 1); @@ -501,6 +498,12 @@ static int ConfigSetTxQueues(DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_ SCReturnInt(0); } +static uint32_t MempoolSizeCalculate( + uint32_t rx_queues, uint32_t rx_desc, uint32_t tx_queues, uint32_t tx_desc) +{ + return rx_queues * rx_desc + tx_queues * tx_desc; +} + static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, const char *entry_str) { SCEnter(); @@ -525,8 +528,8 @@ static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, const char *entry_str) SCReturnInt(-EINVAL); } - iconf->mempool_size = - iconf->nb_rx_queues * iconf->nb_rx_desc + iconf->nb_tx_queues * iconf->nb_tx_desc; + iconf->mempool_size = MempoolSizeCalculate( + iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues, iconf->nb_tx_desc); SCReturnInt(0); } @@ -536,6 +539,18 @@ static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, const char *entry_str) SCReturnInt(-EINVAL); } + if (MempoolSizeCalculate( + iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues, iconf->nb_tx_desc) > + iconf->mempool_size + 1) { // +1 to mask mempool size advice given in Suricata 7.0.x - + // mp_size should be n = (2^q - 1) + SCLogError("%s: mempool size is likely too small for the number of descriptors and queues, " + "set to \"auto\" or adjust to the value of \"%" PRIu32 "\"", + iconf->iface, + MempoolSizeCalculate(iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues, + iconf->nb_tx_desc)); + SCReturnInt(-ERANGE); + } + if (iconf->mempool_size == 0) { SCLogError("%s: mempool size requires a positive integer", iconf->iface); SCReturnInt(-ERANGE); @@ -544,22 +559,27 @@ static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, const char *entry_str) SCReturnInt(0); } +static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz) +{ + // It is advised to have mempool cache size lower or equal to: + // RTE_MEMPOOL_CACHE_MAX_SIZE (by default 512) and "mempool-size / 1.5" + // and at the same time "mempool-size modulo cache_size == 0". + uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, mp_sz / 1.5); + return GreatestDivisorUpTo(mp_sz, max_cache_size); +} + static int ConfigSetMempoolCacheSize(DPDKIfaceConfig *iconf, const char *entry_str) { SCEnter(); if (entry_str == NULL || entry_str[0] == '\0' || strcmp(entry_str, "auto") == 0) { // calculate the mempool size based on the mempool size (it needs to be already filled in) - // It is advised to have mempool cache size lower or equal to: - // RTE_MEMPOOL_CACHE_MAX_SIZE (by default 512) and "mempool-size / 1.5" - // and at the same time "mempool-size modulo cache_size == 0". if (iconf->mempool_size == 0) { SCLogError("%s: cannot calculate mempool cache size of a mempool with size %d", iconf->iface, iconf->mempool_size); SCReturnInt(-EINVAL); } - uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, iconf->mempool_size / 1.5); - iconf->mempool_cache_size = GreatestDivisorUpTo(iconf->mempool_size, max_cache_size); + iconf->mempool_cache_size = MempoolCacheSizeCalculate(iconf->mempool_size); SCReturnInt(0); } @@ -1356,26 +1376,33 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de { SCEnter(); int retval; - uint16_t mtu_size; - uint16_t mbuf_size; struct rte_eth_rxconf rxq_conf; struct rte_eth_txconf txq_conf; - char mempool_name[64]; - snprintf(mempool_name, 64, "mempool_%.20s", iconf->iface); + retval = DPDKDeviceResourcesInit(&(iconf->pkt_mempools), iconf->nb_rx_queues); + if (retval < 0) { + goto cleanup; + } + // +4 for VLAN header - mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4; - mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM; - SCLogConfig("%s: creating packet mbuf pool %s of size %d, cache size %d, mbuf size %d", - iconf->iface, mempool_name, iconf->mempool_size, iconf->mempool_cache_size, mbuf_size); - - iconf->pkt_mempool = rte_pktmbuf_pool_create(mempool_name, iconf->mempool_size, - iconf->mempool_cache_size, 0, mbuf_size, (int)iconf->socket_id); - if (iconf->pkt_mempool == NULL) { - retval = -rte_errno; - SCLogError("%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s): %s", - iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno)); - SCReturnInt(retval); + uint16_t mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4; + uint16_t mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM; + // ceil the div so e.g. mp_size of 262144 and 262143 both lead to 65535 on 4 rx queues + uint32_t q_mp_sz = (iconf->mempool_size + iconf->nb_rx_queues - 1) / iconf->nb_rx_queues - 1; + uint32_t q_mp_cache_sz = MempoolCacheSizeCalculate(q_mp_sz); + SCLogInfo("%s: creating %u packet mempools of size %u, cache size %u, mbuf size %u", + iconf->iface, iconf->nb_rx_queues, q_mp_sz, q_mp_cache_sz, mbuf_size); + for (int i = 0; i < iconf->nb_rx_queues; i++) { + char mempool_name[64]; + snprintf(mempool_name, sizeof(mempool_name), "mp_%d_%.20s", i, iconf->iface); + iconf->pkt_mempools->pkt_mp[i] = rte_pktmbuf_pool_create( + mempool_name, q_mp_sz, q_mp_cache_sz, 0, mbuf_size, (int)iconf->socket_id); + if (iconf->pkt_mempools->pkt_mp[i] == NULL) { + retval = -rte_errno; + SCLogError("%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s) - %s", + iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno)); + goto cleanup; + } } for (uint16_t queue_id = 0; queue_id < iconf->nb_rx_queues; queue_id++) { @@ -1394,12 +1421,11 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en); retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc, - iconf->socket_id, &rxq_conf, iconf->pkt_mempool); + iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]); if (retval < 0) { - rte_mempool_free(iconf->pkt_mempool); SCLogError("%s: failed to setup RX queue %u: %s", iconf->iface, queue_id, rte_strerror(-retval)); - SCReturnInt(retval); + goto cleanup; } } @@ -1416,14 +1442,17 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de retval = rte_eth_tx_queue_setup( iconf->port_id, queue_id, iconf->nb_tx_desc, iconf->socket_id, &txq_conf); if (retval < 0) { - rte_mempool_free(iconf->pkt_mempool); SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id, rte_strerror(-retval)); - SCReturnInt(retval); + goto cleanup; } } SCReturnInt(0); + +cleanup: + DPDKDeviceResourcesDeinit(iconf->pkt_mempools); + SCReturnInt(retval); } static int DeviceValidateOutIfaceConfig(DPDKIfaceConfig *iconf) @@ -1739,8 +1768,10 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface) if (ldev_instance == NULL) { FatalError("Device %s is not registered as a live device", iface); } - ldev_instance->dpdk_vars.pkt_mp = iconf->pkt_mempool; - iconf->pkt_mempool = NULL; + for (int32_t i = 0; i < iconf->threads; i++) { + ldev_instance->dpdk_vars = iconf->pkt_mempools; + iconf->pkt_mempools = NULL; + } return iconf; } diff --git a/src/source-dpdk.h b/src/source-dpdk.h index bd52dcfa88..28341c1704 100644 --- a/src/source-dpdk.h +++ b/src/source-dpdk.h @@ -25,6 +25,7 @@ #define SURICATA_SOURCE_DPDK_H #include "suricata-common.h" +#include "util-dpdk.h" #ifdef HAVE_DPDK #include @@ -73,7 +74,7 @@ typedef struct DPDKIfaceConfig_ { uint16_t nb_tx_desc; uint32_t mempool_size; uint32_t mempool_cache_size; - struct rte_mempool *pkt_mempool; + DPDKDeviceResources *pkt_mempools; SC_ATOMIC_DECLARE(unsigned int, ref); /* threads bind queue id one by one */ SC_ATOMIC_DECLARE(uint16_t, queue_id); diff --git a/src/util-device.h b/src/util-device.h index 0774825385..df4810aad1 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -18,12 +18,9 @@ #ifndef SURICATA_UTIL_DEVICE_H #define SURICATA_UTIL_DEVICE_H -#ifdef HAVE_DPDK -#include -#endif /* HAVE_DPDK */ - #include "queue.h" #include "util-storage.h" +#include "util-dpdk-common.h" #define OFFLOAD_FLAG_SG (1<<0) #define OFFLOAD_FLAG_TSO (1<<1) @@ -40,12 +37,6 @@ 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") */ @@ -65,7 +56,7 @@ typedef struct LiveDevice_ { 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; + DPDKDeviceResources *dpdk_vars; #endif /** storage handle as a flex array member */ Storage storage[]; diff --git a/src/util-dpdk-common.c b/src/util-dpdk-common.c new file mode 100644 index 0000000000..5ef967b141 --- /dev/null +++ b/src/util-dpdk-common.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2025 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * \file + * + * \author Lukas Sismis + */ + +#include "suricata-common.h" +#include "util-debug.h" +#include "util-dpdk-common.h" + +#ifdef HAVE_DPDK + +int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt) +{ + SCEnter(); + *dpdk_vars = SCCalloc(1, sizeof(*dpdk_vars[0])); + if (*dpdk_vars == NULL) { + SCLogError("failed to allocate memory for packet mempools structure"); + SCReturnInt(-ENOMEM); + } + + (*dpdk_vars)->pkt_mp = SCCalloc(mp_cnt, sizeof((*dpdk_vars)->pkt_mp[0])); + if ((*dpdk_vars)->pkt_mp == NULL) { + SCLogError("failed to allocate memory for packet mempools"); + SCReturnInt(-ENOMEM); + } + (*dpdk_vars)->pkt_mp_capa = mp_cnt; + (*dpdk_vars)->pkt_mp_cnt = 0; + + SCReturnInt(0); +} + +void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars) +{ + if (dpdk_vars != NULL) { + if (dpdk_vars->pkt_mp != NULL) { + for (int j = 0; j < dpdk_vars->pkt_mp_capa; j++) { + if (dpdk_vars->pkt_mp[j] != NULL) { + rte_mempool_free(dpdk_vars->pkt_mp[j]); + } + } + SCFree(dpdk_vars->pkt_mp); + dpdk_vars->pkt_mp_capa = 0; + dpdk_vars->pkt_mp_cnt = 0; + dpdk_vars->pkt_mp = NULL; + } + SCFree(dpdk_vars); + } +} + +#endif /* HAVE_DPDK */ \ No newline at end of file diff --git a/src/util-dpdk-common.h b/src/util-dpdk-common.h new file mode 100644 index 0000000000..02125ff7c2 --- /dev/null +++ b/src/util-dpdk-common.h @@ -0,0 +1,127 @@ +/* Copyright (C) 2025 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * \file + * + * \author Lukas Sismis + */ + +#ifndef UTIL_DPDK_COMMON_H +#define UTIL_DPDK_COMMON_H + +#ifdef HAVE_DPDK + +#include +#include +#ifdef HAVE_DPDK_BOND +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +#if RTE_VERSION < RTE_VERSION_NUM(22, 0, 0, 0) +#define RTE_ETH_MQ_RX_RSS ETH_MQ_RX_RSS +#endif + +#if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0) +#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE DEV_TX_OFFLOAD_MBUF_FAST_FREE + +#define RTE_ETH_RX_OFFLOAD_CHECKSUM DEV_RX_OFFLOAD_CHECKSUM + +#define RTE_ETH_RX_OFFLOAD_VLAN_STRIP DEV_RX_OFFLOAD_VLAN_STRIP +#define RTE_ETH_RX_OFFLOAD_IPV4_CKSUM DEV_RX_OFFLOAD_IPV4_CKSUM +#define RTE_ETH_RX_OFFLOAD_UDP_CKSUM DEV_RX_OFFLOAD_UDP_CKSUM +#define RTE_ETH_RX_OFFLOAD_TCP_CKSUM DEV_RX_OFFLOAD_TCP_CKSUM +#define RTE_ETH_RX_OFFLOAD_TCP_LRO DEV_RX_OFFLOAD_TCP_LRO +#define RTE_ETH_RX_OFFLOAD_QINQ_STRIP DEV_RX_OFFLOAD_QINQ_STRIP +#define RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM +#define RTE_ETH_RX_OFFLOAD_MACSEC_STRIP DEV_RX_OFFLOAD_MACSEC_STRIP +#define RTE_ETH_RX_OFFLOAD_HEADER_SPLIT DEV_RX_OFFLOAD_HEADER_SPLIT +#define RTE_ETH_RX_OFFLOAD_VLAN_FILTER DEV_RX_OFFLOAD_VLAN_FILTER +#define RTE_ETH_RX_OFFLOAD_VLAN_EXTEND DEV_RX_OFFLOAD_VLAN_EXTEND +#define RTE_ETH_RX_OFFLOAD_SCATTER DEV_RX_OFFLOAD_SCATTER +#define RTE_ETH_RX_OFFLOAD_TIMESTAMP DEV_RX_OFFLOAD_TIMESTAMP +#define RTE_ETH_RX_OFFLOAD_SECURITY DEV_RX_OFFLOAD_SECURITY +#define RTE_ETH_RX_OFFLOAD_KEEP_CRC DEV_RX_OFFLOAD_KEEP_CRC +#define RTE_ETH_RX_OFFLOAD_SCTP_CKSUM DEV_RX_OFFLOAD_SCTP_CKSUM +#define RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM DEV_RX_OFFLOAD_OUTER_UDP_CKSUM +#define RTE_ETH_RX_OFFLOAD_RSS_HASH DEV_RX_OFFLOAD_RSS_HASH + +#define RTE_ETH_MQ_TX_NONE ETH_MQ_TX_NONE + +#define RTE_ETH_MQ_RX_NONE ETH_MQ_RX_NONE + +#define RTE_ETH_RSS_IP ETH_RSS_IP +#define RTE_ETH_RSS_UDP ETH_RSS_UDP +#define RTE_ETH_RSS_TCP ETH_RSS_TCP +#define RTE_ETH_RSS_SCTP ETH_RSS_SCTP +#define RTE_ETH_RSS_TUNNEL ETH_RSS_TUNNEL + +#define RTE_ETH_RSS_L3_SRC_ONLY ETH_RSS_L3_SRC_ONLY +#define RTE_ETH_RSS_L3_DST_ONLY ETH_RSS_L3_DST_ONLY +#define RTE_ETH_RSS_L4_SRC_ONLY ETH_RSS_L4_SRC_ONLY +#define RTE_ETH_RSS_L4_DST_ONLY ETH_RSS_L4_DST_ONLY + +#define RTE_ETH_RSS_IPV4 ETH_RSS_IPV4 +#define RTE_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4 +#define RTE_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP +#define RTE_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP +#define RTE_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP +#define RTE_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER +#define RTE_ETH_RSS_IPV6 ETH_RSS_IPV6 +#define RTE_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6 +#define RTE_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP +#define RTE_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP +#define RTE_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP +#define RTE_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER +#define RTE_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD +#define RTE_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX +#define RTE_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX +#define RTE_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX +#define RTE_ETH_RSS_PORT ETH_RSS_PORT +#define RTE_ETH_RSS_VXLAN ETH_RSS_VXLAN +#define RTE_ETH_RSS_NVGRE ETH_RSS_NVGRE +#define RTE_ETH_RSS_GTPU ETH_RSS_GTPU + +#define RTE_MBUF_F_RX_IP_CKSUM_MASK PKT_RX_IP_CKSUM_MASK +#define RTE_MBUF_F_RX_IP_CKSUM_NONE PKT_RX_IP_CKSUM_NONE +#define RTE_MBUF_F_RX_IP_CKSUM_GOOD PKT_RX_IP_CKSUM_GOOD +#define RTE_MBUF_F_RX_IP_CKSUM_BAD PKT_RX_IP_CKSUM_BAD + +#define RTE_MBUF_F_RX_L4_CKSUM_MASK PKT_RX_L4_CKSUM_MASK +#define RTE_MBUF_F_RX_L4_CKSUM_GOOD PKT_RX_L4_CKSUM_GOOD +#define RTE_MBUF_F_RX_L4_CKSUM_BAD PKT_RX_L4_CKSUM_BAD +#endif + +typedef struct { + struct rte_mempool **pkt_mp; + uint16_t pkt_mp_cnt; + uint16_t pkt_mp_capa; +} DPDKDeviceResources; + +int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt); +void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars); + +#endif /* HAVE_DPDK */ + +#endif /* UTIL_DPDK_COMMON_H */ diff --git a/src/util-dpdk.c b/src/util-dpdk.c index b5f46a30a5..22ac12efc1 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -59,8 +59,8 @@ void DPDKFreeDevice(LiveDevice *ldev) (void)ldev; // avoid warnings of unused variable #ifdef HAVE_DPDK if (SCRunmodeGet() == RUNMODE_DPDK) { - SCLogDebug("%s: releasing packet mempool", ldev->dev); - rte_mempool_free(ldev->dpdk_vars.pkt_mp); + SCLogDebug("%s: releasing packet mempools", ldev->dev); + DPDKDeviceResourcesDeinit(ldev->dpdk_vars); } #endif } diff --git a/src/util-dpdk.h b/src/util-dpdk.h index 1fb3532f5d..ec3a0a8c5b 100644 --- a/src/util-dpdk.h +++ b/src/util-dpdk.h @@ -24,97 +24,7 @@ #ifndef UTIL_DPDK_H #define UTIL_DPDK_H -#ifdef HAVE_DPDK - -#include -#include -#ifdef HAVE_DPDK_BOND -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -#if RTE_VERSION < RTE_VERSION_NUM(22, 0, 0, 0) -#define RTE_ETH_MQ_RX_RSS ETH_MQ_RX_RSS -#endif - -#if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0) -#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE DEV_TX_OFFLOAD_MBUF_FAST_FREE - -#define RTE_ETH_RX_OFFLOAD_CHECKSUM DEV_RX_OFFLOAD_CHECKSUM - -#define RTE_ETH_RX_OFFLOAD_VLAN_STRIP DEV_RX_OFFLOAD_VLAN_STRIP -#define RTE_ETH_RX_OFFLOAD_IPV4_CKSUM DEV_RX_OFFLOAD_IPV4_CKSUM -#define RTE_ETH_RX_OFFLOAD_UDP_CKSUM DEV_RX_OFFLOAD_UDP_CKSUM -#define RTE_ETH_RX_OFFLOAD_TCP_CKSUM DEV_RX_OFFLOAD_TCP_CKSUM -#define RTE_ETH_RX_OFFLOAD_TCP_LRO DEV_RX_OFFLOAD_TCP_LRO -#define RTE_ETH_RX_OFFLOAD_QINQ_STRIP DEV_RX_OFFLOAD_QINQ_STRIP -#define RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM -#define RTE_ETH_RX_OFFLOAD_MACSEC_STRIP DEV_RX_OFFLOAD_MACSEC_STRIP -#define RTE_ETH_RX_OFFLOAD_HEADER_SPLIT DEV_RX_OFFLOAD_HEADER_SPLIT -#define RTE_ETH_RX_OFFLOAD_VLAN_FILTER DEV_RX_OFFLOAD_VLAN_FILTER -#define RTE_ETH_RX_OFFLOAD_VLAN_EXTEND DEV_RX_OFFLOAD_VLAN_EXTEND -#define RTE_ETH_RX_OFFLOAD_SCATTER DEV_RX_OFFLOAD_SCATTER -#define RTE_ETH_RX_OFFLOAD_TIMESTAMP DEV_RX_OFFLOAD_TIMESTAMP -#define RTE_ETH_RX_OFFLOAD_SECURITY DEV_RX_OFFLOAD_SECURITY -#define RTE_ETH_RX_OFFLOAD_KEEP_CRC DEV_RX_OFFLOAD_KEEP_CRC -#define RTE_ETH_RX_OFFLOAD_SCTP_CKSUM DEV_RX_OFFLOAD_SCTP_CKSUM -#define RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM DEV_RX_OFFLOAD_OUTER_UDP_CKSUM -#define RTE_ETH_RX_OFFLOAD_RSS_HASH DEV_RX_OFFLOAD_RSS_HASH - -#define RTE_ETH_MQ_TX_NONE ETH_MQ_TX_NONE - -#define RTE_ETH_MQ_RX_NONE ETH_MQ_RX_NONE - -#define RTE_ETH_RSS_IP ETH_RSS_IP -#define RTE_ETH_RSS_UDP ETH_RSS_UDP -#define RTE_ETH_RSS_TCP ETH_RSS_TCP -#define RTE_ETH_RSS_SCTP ETH_RSS_SCTP -#define RTE_ETH_RSS_TUNNEL ETH_RSS_TUNNEL - -#define RTE_ETH_RSS_L3_SRC_ONLY ETH_RSS_L3_SRC_ONLY -#define RTE_ETH_RSS_L3_DST_ONLY ETH_RSS_L3_DST_ONLY -#define RTE_ETH_RSS_L4_SRC_ONLY ETH_RSS_L4_SRC_ONLY -#define RTE_ETH_RSS_L4_DST_ONLY ETH_RSS_L4_DST_ONLY - -#define RTE_ETH_RSS_IPV4 ETH_RSS_IPV4 -#define RTE_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4 -#define RTE_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP -#define RTE_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP -#define RTE_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP -#define RTE_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER -#define RTE_ETH_RSS_IPV6 ETH_RSS_IPV6 -#define RTE_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6 -#define RTE_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP -#define RTE_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP -#define RTE_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP -#define RTE_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER -#define RTE_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD -#define RTE_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX -#define RTE_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX -#define RTE_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX -#define RTE_ETH_RSS_PORT ETH_RSS_PORT -#define RTE_ETH_RSS_VXLAN ETH_RSS_VXLAN -#define RTE_ETH_RSS_NVGRE ETH_RSS_NVGRE -#define RTE_ETH_RSS_GTPU ETH_RSS_GTPU - -#define RTE_MBUF_F_RX_IP_CKSUM_MASK PKT_RX_IP_CKSUM_MASK -#define RTE_MBUF_F_RX_IP_CKSUM_NONE PKT_RX_IP_CKSUM_NONE -#define RTE_MBUF_F_RX_IP_CKSUM_GOOD PKT_RX_IP_CKSUM_GOOD -#define RTE_MBUF_F_RX_IP_CKSUM_BAD PKT_RX_IP_CKSUM_BAD - -#define RTE_MBUF_F_RX_L4_CKSUM_MASK PKT_RX_L4_CKSUM_MASK -#define RTE_MBUF_F_RX_L4_CKSUM_GOOD PKT_RX_L4_CKSUM_GOOD -#define RTE_MBUF_F_RX_L4_CKSUM_BAD PKT_RX_L4_CKSUM_BAD -#endif - -#endif /* HAVE_DPDK */ - +#include "util-dpdk-common.h" #include "util-device.h" void DPDKCleanupEAL(void); diff --git a/suricata.yaml.in b/suricata.yaml.in index 520886543c..032a6d1550 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -822,10 +822,10 @@ dpdk: mtu: 1500 vlan-strip-offload: false rss-hash-functions: auto - mempool-size: 65535 - mempool-cache-size: 257 - rx-descriptors: 1024 - tx-descriptors: 1024 + mempool-size: auto + mempool-cache-size: auto + rx-descriptors: auto + tx-descriptors: auto copy-mode: none copy-iface: none