public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Congjie Zhou <zcjie0802@qq.com>
Subject: [PATCH v4] Subject: eal/linux: fix fbarray name collision in containers
Date: Tue, 13 Jan 2026 21:54:01 -0800	[thread overview]
Message-ID: <20260114055508.106779-1-stephen@networkplumber.org> (raw)
In-Reply-To: <tencent_C757C0BA2AC7438F65C6522E700005F53605@qq.com>

When multiple secondary processes run in different containers that
share the same hugetlbfs mount, the fbarray names can collide.
This happens because containers use separate PID namespaces, so
different processes in different containers can have the same PID.

Fix by replacing the PID with a timestamp-based value. The TSC
(timestamp counter) provides sufficient uniqueness since containers
starting at the same CPU cycle is practically impossible - even 1ms
of startup time difference means millions of cycles apart at GHz
frequencies.

Also, reduce the name buffer from PATH_MAX to RTE_FBARRAY_NAME_LEN
since it is only used for the fbarray name.

Signed-off-by: Congjie Zhou <zcjie0802@qq.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v4 - update comment and commit message
   - reduce name buffer from 4K to 64 to save stack space
     and catch any future format overflow
 lib/eal/linux/eal_memalloc.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index 1e60e21620..cbe22c98d0 100644
--- a/lib/eal/linux/eal_memalloc.c
+++ b/lib/eal/linux/eal_memalloc.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <inttypes.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -28,6 +29,7 @@
 #include <rte_log.h>
 #include <rte_eal.h>
 #include <rte_memory.h>
+#include <rte_cycles.h>
 
 #include "eal_filesystem.h"
 #include "eal_internal_cfg.h"
@@ -1380,7 +1382,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	struct rte_memseg_list *primary_msl, *local_msl;
-	char name[PATH_MAX];
+	char name[RTE_FBARRAY_NAME_LEN];
 	int msl_idx, ret;
 
 	if (msl->external)
@@ -1390,9 +1392,16 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
 	primary_msl = &mcfg->memsegs[msl_idx];
 	local_msl = &local_memsegs[msl_idx];
 
-	/* create distinct fbarrays for each secondary */
-	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
-		primary_msl->memseg_arr.name, getpid());
+	/*
+	 * Create distinct fbarrays for each secondary using TSC for uniqueness,
+	 * since PID is not unique across containers (different PID namespaces).
+	 * The worst case name length is:
+	 * Base name: "memseg-1048576k-99-99" ~21 chars
+	 * Suffix "_<pid>_<16hex>" +24
+	 * Total = 44 < RTE_FBARRAY_NAME_LEN 64
+	 */
+	snprintf(name, sizeof(name), "%s_%"PRIx64,
+		primary_msl->memseg_arr.name, rte_get_tsc_cycles());
 
 	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
 		primary_msl->memseg_arr.len,
-- 
2.51.0


  parent reply	other threads:[~2026-01-14  5:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  8:37 [PATCH] eal/linux: redefine the name for rte_fbarray_init() Congjie Zhou
2024-11-14 16:24 ` Stephen Hemminger
2024-11-14 17:06   ` Stephen Hemminger
2024-11-15  2:26     ` Zhou congjie
2024-11-15  5:32       ` Stephen Hemminger
2024-11-15  1:57   ` Zhou congjie
2024-11-15  2:00   ` Zhou congjie
2024-11-15  7:50 ` [PATCH v2] eal/linux: fix fbarray name with multiple secondary processes Congjie Zhou
2024-11-15 16:38   ` Stephen Hemminger
2024-11-15 20:09   ` Stephen Hemminger
2024-11-16  2:16     ` [PATCH v2] eal/linux: fix fbarray name with multiple secondaryprocesses Zhou congjie
2024-11-16  2:53     ` Zhou congjie
2024-11-16  4:07 ` [PATCH v3] eal/linux: fix fbarray name with multiple secondary processes Congjie Zhou
2026-01-14  5:25   ` Stephen Hemminger
2026-01-14  5:54   ` Stephen Hemminger [this message]
2026-02-13 21:50 ` [PATCH v5] Subject: eal/linux: fix fbarray name collision in containers Stephen Hemminger
2026-02-13 22:00 ` [PATCH v6] " Stephen Hemminger
2026-02-16 17:22   ` David Marchand
2026-02-16 22:26     ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260114055508.106779-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=zcjie0802@qq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox