From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: tglx@kernel.org, mingo@redhat.com, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com,
shuah@kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH v2 4/4] selftests/futex: Remove the shared memory segments of the futex tests
Date: Sun, 8 Nov 2026 09:49:52 -0500 [thread overview]
Message-ID: <20261108144952.1531160-5-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <20261108144952.1531160-1-mathieu.desnoyers@efficios.com>
anon_page in futex_wait, and shared_waitv in futex_waitv, create System V
shared memory segments with shmget(IPC_PRIVATE). They detach them with
shmdt(), but never remove them. So each run leaks one segment for
anon_page, and 30 for shared_waitv. After about 136 runs of futex_waitv,
shmget() fails, at the default limit of 4096 segments.
Mark each segment for removal with shmctl(IPC_RMID) once it is attached.
The kernel then removes it at the last detach, or when the test exits.
With this patch, futex_waitv passed 2000 runs in a row in each of two
8-CPU VMs, and futex_wait 2000 runs.
Fixes: c3d128581f64 ("selftests: futex: Add futex wait test")
Fixes: 5e59c1d1c78c ("selftests: futex: Add sys_futex_waitv() test")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
tools/testing/selftests/futex/functional/futex_wait.c | 2 ++
tools/testing/selftests/futex/functional/futex_waitv.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tools/testing/selftests/futex/functional/futex_wait.c
index 4bf7d8ee238b..4b7550aff4d0 100644
--- a/tools/testing/selftests/futex/functional/futex_wait.c
+++ b/tools/testing/selftests/futex/functional/futex_wait.c
@@ -115,6 +115,8 @@ TEST(anon_page)
ASSERT_NE(shared_data, (void *)-1)
TH_LOG("shmat failed: %s", strerror(errno));
}
+ /* The segment goes away once detached. */
+ shmctl(shm_id, IPC_RMID, NULL);
*shared_data = 0;
futex = shared_data;
diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/testing/selftests/futex/functional/futex_waitv.c
index ccfa31fd20fa..94ada55b83cf 100644
--- a/tools/testing/selftests/futex/functional/futex_waitv.c
+++ b/tools/testing/selftests/futex/functional/futex_waitv.c
@@ -114,6 +114,8 @@ TEST(shared_waitv)
unsigned int *shared_data = shmat(shm_id, NULL, 0);
+ /* The segment goes away once detached. */
+ shmctl(shm_id, IPC_RMID, NULL);
*shared_data = 0;
waitv[i].uaddr = (uintptr_t)shared_data;
waitv[i].flags = FUTEX_32;
--
2.47.3
prev parent reply other threads:[~2026-11-08 14:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 14:49 [PATCH v2 0/4] selftests/futex: Fix flaky futex_wait and futex_waitv tests Mathieu Desnoyers
2026-11-08 14:49 ` [PATCH v2 1/4] selftests/futex: Let futex_waitv() take no timeout Mathieu Desnoyers
2026-11-08 14:49 ` [PATCH v2 2/4] selftests/futex: Retry the wake in futex_wait instead of sleeping Mathieu Desnoyers
2026-11-08 14:49 ` [PATCH v2 3/4] selftests/futex: Retry the wake in futex_waitv " Mathieu Desnoyers
2026-11-08 14:49 ` Mathieu Desnoyers [this message]
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=20261108144952.1531160-5-mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=andrealmeid@igalia.com \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
/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
all inboxes | Powered by JetHome®