[PATCH v4] erofs-utils: lib: name worker threads erofscompressor

Nithurshen nithurshen.dev at gmail.com
Tue Mar 17 04:25:27 AEDT 2026


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 at 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..c924c1b 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



More information about the Linux-erofs mailing list