From: Robert Sanford <rsanford2@gmail.com>
To: dev@dpdk.org
Cc: andrew.rybchenko@oktetlabs.ru, mb@smartsharesystems.com,
olivier.matz@6wind.com, Robert Sanford <rsanford@akamai.com>
Subject: [PATCH v3 3/3] test/mempool: add list walk race test
Date: Mon, 9 Nov 2026 09:40:54 -0500 [thread overview]
Message-ID: <20261109144054.3784583-4-rsanford2@gmail.com> (raw)
In-Reply-To: <20261109144054.3784583-1-rsanford2@gmail.com>
From: Robert Sanford <rsanford@akamai.com>
Walk, look up and dump the mempool list on some lcores while other
lcores create and free mempools, in two phases of 500 ms. In the
first phase, mempools are created and freed as fast as possible. In
the second phase, every other mempool is created empty and populated
after a short delay, so that the walkers also find mempools that are
not populated yet. In that phase, the walk callback also dumps each
mempool, and it checks rte_mempool_is_created() before querying the
mempool driver, as documented for rte_mempool_walk().
Without either of the two previous patches, the test crashes. It
needs at least 3 lcores and is skipped otherwise. It adds about one
second to mempool_autotest.
Signed-off-by: Robert Sanford <rsanford@akamai.com>
---
app/test/test_mempool.c | 144 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 144 insertions(+)
diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c
index 0a4d794346..ac26ef55a6 100644
--- a/app/test/test_mempool.c
+++ b/app/test/test_mempool.c
@@ -839,6 +839,146 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)
#pragma pop_macro("RTE_TEST_TRACE_FAILURE")
+/*
+ * Walk, look up and dump the mempool list on some lcores while other lcores
+ * create and free mempools. In the first phase the creators free mempools as
+ * fast as possible. In the second phase every other mempool is created empty
+ * and populated after a short delay, so that the walkers also find mempools
+ * that are not populated yet, and dump them.
+ */
+#define LIST_RACE_PHASE_MS 500
+#define LIST_RACE_NB_OBJ 63
+#define LIST_RACE_ELT_SIZE 64
+
+static RTE_ATOMIC(uint32_t) list_race_stop;
+static int list_race_populate_later;
+static FILE *list_race_dump;
+
+static int
+test_mempool_list_race_create(__rte_unused void *arg)
+{
+ char name[RTE_MEMPOOL_NAMESIZE];
+ struct rte_mempool *mp;
+ int populate_later = 0;
+
+ snprintf(name, sizeof(name), "test_list_race_%u", rte_lcore_id());
+ while (rte_atomic_load_explicit(&list_race_stop,
+ rte_memory_order_relaxed) == 0) {
+ if (populate_later) {
+ mp = rte_mempool_create_empty(name, LIST_RACE_NB_OBJ,
+ LIST_RACE_ELT_SIZE, 0, 0, SOCKET_ID_ANY, 0);
+ if (mp == NULL)
+ RET_ERR();
+ rte_delay_us(100);
+ if (rte_mempool_set_ops_byname(mp,
+ rte_mbuf_best_mempool_ops(), NULL) < 0 ||
+ rte_mempool_populate_default(mp) < 0) {
+ rte_mempool_free(mp);
+ RET_ERR();
+ }
+ } else {
+ mp = rte_mempool_create(name, LIST_RACE_NB_OBJ,
+ LIST_RACE_ELT_SIZE, 0, 0, NULL, NULL, NULL, NULL,
+ SOCKET_ID_ANY, 0);
+ if (mp == NULL)
+ RET_ERR();
+ }
+ rte_mempool_free(mp);
+ if (list_race_populate_later)
+ populate_later = !populate_later;
+ }
+ return 0;
+}
+
+static void
+test_mempool_list_race_walk_cb(struct rte_mempool *mp, void *arg)
+{
+ unsigned int *count = arg;
+
+ /* rte_mempool_dump() must handle mempools that are not populated yet */
+ if (list_race_dump != NULL)
+ rte_mempool_dump(list_race_dump, mp);
+
+ /* as documented for rte_mempool_walk(), check this first */
+ if (!rte_mempool_is_created(mp))
+ return;
+ /* access the store */
+ *count += mp->size + rte_mempool_avail_count(mp);
+}
+
+static int
+test_mempool_list_race_walk(__rte_unused void *arg)
+{
+ unsigned int count = 0;
+
+ while (rte_atomic_load_explicit(&list_race_stop,
+ rte_memory_order_relaxed) == 0) {
+ rte_mempool_walk(test_mempool_list_race_walk_cb, &count);
+ if (rte_mempool_lookup("test_list_race_none") != NULL)
+ RET_ERR();
+ if (list_race_dump != NULL)
+ rte_mempool_list_dump(list_race_dump);
+ }
+ return 0;
+}
+
+static int
+test_mempool_list_race_phase(int populate_later, FILE *dump)
+{
+ unsigned int nb_creators = (rte_lcore_count() - 1) / 2;
+ unsigned int lcore_id, i = 0;
+ int ret = 0;
+
+ list_race_populate_later = populate_later;
+ list_race_dump = dump;
+ rte_atomic_store_explicit(&list_race_stop, 0, rte_memory_order_relaxed);
+ RTE_LCORE_FOREACH_WORKER(lcore_id) {
+ lcore_function_t *func = i++ < nb_creators ?
+ test_mempool_list_race_create :
+ test_mempool_list_race_walk;
+
+ if (rte_eal_remote_launch(func, NULL, lcore_id) != 0)
+ ret = -1;
+ }
+
+ rte_delay_ms(LIST_RACE_PHASE_MS);
+ rte_atomic_store_explicit(&list_race_stop, 1, rte_memory_order_relaxed);
+
+ RTE_LCORE_FOREACH_WORKER(lcore_id) {
+ if (rte_eal_wait_lcore(lcore_id) < 0)
+ ret = -1;
+ }
+ return ret;
+}
+
+static int
+test_mempool_list_race(void)
+{
+ FILE *f;
+ int ret;
+
+ if (rte_lcore_count() < 3) {
+ printf("%s skipped: needs at least 3 lcores\n", __func__);
+ return 0;
+ }
+
+ /* mempools freed while the list is walked */
+ ret = test_mempool_list_race_phase(0, NULL);
+ if (ret != 0) {
+ LOG_ERR();
+ return ret;
+ }
+
+ /* mempools not populated yet while the list is walked and dumped */
+ f = fopen("/dev/null", "w");
+ ret = test_mempool_list_race_phase(1, f);
+ if (f != NULL)
+ fclose(f);
+ if (ret != 0)
+ LOG_ERR();
+ return ret;
+}
+
static int
test_mempool(void)
{
@@ -1105,6 +1245,10 @@ test_mempool(void)
if (test_mempool_flag_non_io_unset_when_populated_with_valid_iova() < 0)
GOTO_ERR(ret, err);
+ /* test walking the mempool list while mempools are created and freed */
+ if (test_mempool_list_race() < 0)
+ GOTO_ERR(ret, err);
+
rte_mempool_list_dump(stdout);
ret = 0;
--
2.34.1
next prev parent reply other threads:[~2026-11-09 14:41 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 1:11 [PATCH v1 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-03 1:11 ` [PATCH v1 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-03 13:54 ` Morten Brørup
2026-11-03 1:11 ` [PATCH v1 2/3] mempool: skip unpopulated pools in walk and dump Robert Sanford
2026-11-03 14:12 ` Morten Brørup
2026-11-03 1:11 ` [PATCH v1 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-03 14:15 ` Morten Brørup
2026-11-03 17:35 ` [PATCH v2 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-03 17:35 ` [PATCH v2 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-03 17:35 ` [PATCH v2 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-06 8:43 ` Morten Brørup
2026-11-06 18:43 ` Robert Sanford
2026-11-06 19:24 ` Morten Brørup
2026-11-03 17:35 ` [PATCH v2 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-09 14:40 ` [PATCH v3 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-09 14:40 ` [PATCH v3 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-09 14:40 ` [PATCH v3 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-09 14:40 ` Robert Sanford [this message]
2026-11-11 13:00 ` [PATCH v3 3/3] test/mempool: add list walk race test Morten Brørup
2026-11-12 15:43 ` [PATCH v4 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-12 15:43 ` [PATCH v4 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-12 15:43 ` [PATCH v4 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-12 15:43 ` [PATCH v4 3/3] test/mempool: add list walk race test Robert Sanford
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=20261109144054.3784583-4-rsanford2@gmail.com \
--to=rsanford2@gmail.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=olivier.matz@6wind.com \
--cc=rsanford@akamai.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