Skip to contentSkip to conversation

net/pcap: fix indentation and numa node

PATCH In review Stephen Hemminger 2 participants 3 messages Apr 5, 2025 – Apr 7, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/pcap: fix indentation and numa node

The process private data allocation was indented incorrectly in the source code, and had unnecessary cast. It is better that the data be allocated on same numa node as the device structure.

---
 drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -9
index 728ef85d53..aefa74c7be 100644
@@ -1208,10 +1208,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
-
+	pp = rte_zmalloc_socket(NULL, sizeof(struct pmd_process_private),
+				RTE_CACHE_LINE_SIZE, numa_node);
 	if (pp == NULL) {
 		PMD_LOG(ERR,
 			"Failed to allocate memory for process private");
@@ -1578,11 +1576,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
-
+		pp = rte_zmalloc_socket(NULL, sizeof(struct pmd_process_private),
+					RTE_CACHE_LINE_SIZE, dev->device.numa_node);
 		if (pp == NULL) {
 			PMD_LOG(ERR,
 				"Failed to allocate memory for process private");
Signature · 1 line
2.47.2
#1 lore raw
Quoted 17 lines · Stephen Hemminger

The process private data allocation was indented incorrectly in the source code, and had unnecessary cast. It is better that the data be allocated on same numa node as the device structure.

---
 drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +0 -0
index 728ef85d53..aefa74c7be 100644
@@ -1208,10 +1208,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);

drivers/net/pcap/pcap_ethdev.c pmd_init_internals(struct rte_vdev_device *vdev, · line 1215

Quoted 10 lines
drivers/net/pcap/pcap_ethdev.c +2 -4
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
-
+	pp = rte_zmalloc_socket(NULL, sizeof(struct pmd_process_private),
+				RTE_CACHE_LINE_SIZE, numa_node);
 	if (pp == NULL) {
 		PMD_LOG(ERR,
 			"Failed to allocate memory for process private");

My concern there is that by forcing the numa node parameter, you are going to make it impossible to run with memory on the "wrong" numa node. Admittedly, this is less of a problem with virtual devices like pcap, than physical ones, but I still wonder if, on error, you should fallback to a regular "rte_malloc" call to allow the allocation to succeed so long as there is some hugepage memory available somewhere.

/Bruce

#2 lore raw
Quoted 36 lines · On Mon, 7 Apr 2025 10:51:37 +0100 Bruce Richardson…
Quoted 17 lines · Stephen Hemminger

The process private data allocation was indented incorrectly in the source code, and had unnecessary cast. It is better that the data be allocated on same numa node as the device structure.

---
 drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +0 -0
index 728ef85d53..aefa74c7be 100644
@@ -1208,10 +1208,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);

drivers/net/pcap/pcap_ethdev.c pmd_init_internals(struct rte_vdev_device *vdev, · line 1215

Quoted 10 lines
drivers/net/pcap/pcap_ethdev.c +2 -4
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
-
+	pp = rte_zmalloc_socket(NULL, sizeof(struct pmd_process_private),
+				RTE_CACHE_LINE_SIZE, numa_node);
 	if (pp == NULL) {
 		PMD_LOG(ERR,
 			"Failed to allocate memory for process private");  

My concern there is that by forcing the numa node parameter, you are going to make it impossible to run with memory on the "wrong" numa node. Admittedly, this is less of a problem with virtual devices like pcap, than physical ones, but I still wonder if, on error, you should fallback to a regular "rte_malloc" call to allow the allocation to succeed so long as there is some hugepage memory available somewhere.

Quoted 1 line

/Bruce

There already is a numa_node parameter on the eth dev, this was just trying to put the private part on the same node as the existing eth dev.