net/pcap: fix indentation and numa node

Message ID 20250405153623.200771-1-stephen@networkplumber.org (mailing list archive)
State Rejected
Delegated to: Stephen Hemminger
Headers
Series net/pcap: fix indentation and numa node |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Stephen Hemminger April 5, 2025, 3:36 p.m. UTC
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.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
  

Comments

Bruce Richardson April 7, 2025, 9:51 a.m. UTC | #1
On Sat, Apr 05, 2025 at 08:36:23AM -0700, Stephen Hemminger wrote:
> 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.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> index 728ef85d53..aefa74c7be 100644
> --- a/drivers/net/pcap/pcap_ethdev.c
> +++ b/drivers/net/pcap/pcap_ethdev.c
> @@ -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");

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
  
Stephen Hemminger April 7, 2025, 3:08 p.m. UTC | #2
On Mon, 7 Apr 2025 10:51:37 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:

> On Sat, Apr 05, 2025 at 08:36:23AM -0700, Stephen Hemminger wrote:
> > 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.
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  drivers/net/pcap/pcap_ethdev.c | 13 ++++---------
> >  1 file changed, 4 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> > index 728ef85d53..aefa74c7be 100644
> > --- a/drivers/net/pcap/pcap_ethdev.c
> > +++ b/drivers/net/pcap/pcap_ethdev.c
> > @@ -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");  
> 
> 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

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.
  

Patch

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index 728ef85d53..aefa74c7be 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -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");