From: Nithurshen <nithurshen.dev@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, hsiangkao@linux.alibaba.com,
Nithurshen <nithurshen.dev@gmail.com>
Subject: [PATCH v5] erofs-utils: lib: name worker threads erofscompressor
Date: Mon, 16 Mar 2026 23:31:06 +0530 [thread overview]
Message-ID: <20260316180106.5991-1-nithurshen.dev@gmail.com> (raw)
In-Reply-To: <6edda81f-5d2e-49d0-9b31-181e3fdf0b18@linux.alibaba.com>
Set a specific thread name for the multi-threaded workqueue workers
to make debugging, profiling, and process monitoring significantly
easier.
Previously, worker threads inherited the name of the parent process
(e.g., mkfs.erofs), making it difficult to distinguish them from the
main thread in tools like top, htop, or ps.
This introduces a new OS-independent wrapper, erofs_set_thread_name(),
which utilizes prctl(PR_SET_NAME) on Linux and pthread_setname_np on
macOS. This helper is now called during the workqueue's .on_start()
callback in compress.c to explicitly label the worker threads as
"erofscompressor".
Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
---
include/erofs/workqueue.h | 2 ++
lib/compress.c | 2 ++
lib/workqueue.c | 13 +++++++++++++
3 files changed, 17 insertions(+)
diff --git a/include/erofs/workqueue.h b/include/erofs/workqueue.h
index 36037c3..27d3ba4 100644
--- a/include/erofs/workqueue.h
+++ b/include/erofs/workqueue.h
@@ -31,4 +31,6 @@ int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker,
erofs_wq_func_t on_exit);
int erofs_queue_work(struct erofs_workqueue *wq, struct erofs_work *work);
int erofs_destroy_workqueue(struct erofs_workqueue *wq);
+
+void erofs_set_thread_name(const char *name);
#endif
diff --git a/lib/compress.c b/lib/compress.c
index 4a0d890..65971c9 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -1427,6 +1427,8 @@ void *z_erofs_mt_wq_tls_alloc(struct erofs_workqueue *wq, void *ptr)
{
struct erofs_compress_wq_tls *tls;
+ erofs_set_thread_name("erofscompressor");
+
tls = calloc(1, sizeof(*tls));
if (!tls)
return NULL;
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 18ee0f9..1811c9c 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -3,6 +3,19 @@
#include <stdlib.h>
#include "erofs/workqueue.h"
+#if defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
+void erofs_set_thread_name(const char *name)
+{
+#if defined(__linux__)
+ prctl(PR_SET_NAME, name);
+#elif defined(__APPLE__)
+ pthread_setname_np(name);
+#endif
+}
+
static void *worker_thread(void *arg)
{
struct erofs_workqueue *wq = arg;
--
2.51.0
prev parent reply other threads:[~2026-03-16 18:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 15:13 [PATCH] erofs-utils: lib: name worker threads erofs_compress Nithurshen
2026-03-16 16:49 ` Gao Xiang
2026-03-16 16:54 ` [PATCH v2] " Nithurshen
2026-03-16 17:00 ` Gao Xiang
2026-03-16 17:02 ` [PATCH v3] " Nithurshen
2026-03-16 17:05 ` Gao Xiang
2026-03-16 17:11 ` [PATCH] " Nithurshen Karthikeyan
2026-03-16 17:15 ` Gao Xiang
2026-03-16 17:25 ` [PATCH v4] erofs-utils: lib: name worker threads erofscompressor Nithurshen
2026-03-16 17:58 ` Gao Xiang
2026-03-16 18:01 ` Nithurshen [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=20260316180106.5991-1-nithurshen.dev@gmail.com \
--to=nithurshen.dev@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@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