From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Congjie Zhou <zcjie0802@qq.com>,
stable@dpdk.org, Stephen Hemminger <stephen@networkplumber.org>,
Anatoly Burakov <anatoly.burakov@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v6] eal/linux: fix fbarray name collision in containers
Date: Fri, 13 Feb 2026 14:00:23 -0800 [thread overview]
Message-ID: <20260213220127.265020-1-stephen@networkplumber.org> (raw)
In-Reply-To: <tencent_B09D0FCCA142E4AE5ABFE584E92DCED8CB0A@qq.com>
From: Congjie Zhou <zcjie0802@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.
Fixes: 046aa5c4477b ("mem: add memalloc init stage")
Cc: stable@dpdk.org
Signed-off-by: Congjie Zhou <zcjie0802@qq.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v6 - fix typo in subject
- add pid to name because if two secondary spawn at once
in theory could collide.
lib/eal/linux/eal_memalloc.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index 4dee224ac5..dfbedf4626 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"
@@ -1387,7 +1389,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)
@@ -1397,12 +1399,21 @@ 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 */
- ret = snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
- primary_msl->memseg_arr.name, getpid());
- if (ret >= RTE_FBARRAY_NAME_LEN) {
- EAL_LOG(ERR, "fbarray name %s_%i is too long",
- 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
+ */
+ uint64_t tsc = rte_get_tsc_cycles();
+ pid_t pid = getpid();
+ ret = snprintf(name, sizeof(name), "%s_%d_%"PRIx64,
+ primary_msl->memseg_arr.name, pid, tsc);
+ if (ret >= (int)sizeof(name)) {
+ EAL_LOG(ERR, "fbarray name \"%s_%d_%"PRIx64"\" is too long",
+ primary_msl->memseg_arr.name, pid, tsc);
return -1;
}
--
2.51.0
next prev parent reply other threads:[~2026-02-13 22:01 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 ` [PATCH v4] Subject: eal/linux: fix fbarray name collision in containers Stephen Hemminger
2026-02-13 21:50 ` [PATCH v5] " Stephen Hemminger
2026-02-13 22:00 ` Stephen Hemminger [this message]
2026-02-16 17:22 ` [PATCH v6] " 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=20260213220127.265020-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stable@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