[PATCH v3] erofs-utils: lib: name worker threads erofs_compress

Nithurshen nithurshen.dev at gmail.com
Tue Mar 17 04:02:33 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 utilizes prctl(PR_SET_NAME) on Linux and pthread_setname_np
on macOS to explicitly label these threads as "erofs_compressor" upon
initialization in the workqueue's .on_start() callback.

Signed-off-by: Nithurshen <nithurshen.dev at gmail.com>
---
 lib/compress.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/compress.c b/lib/compress.c
index 4a0d890..66b3b8b 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -26,6 +26,9 @@
 #include "liberofs_compress.h"
 #include "liberofs_fragments.h"
 #include "liberofs_metabox.h"
+#if defined(__linux__)
+#include <sys/prctl.h>
+#endif
 
 #define Z_EROFS_DESTBUF_SZ	(Z_EROFS_PCLUSTER_MAX_SIZE + EROFS_MAX_BLOCK_SIZE * 2)
 
@@ -1427,6 +1430,12 @@ void *z_erofs_mt_wq_tls_alloc(struct erofs_workqueue *wq, void *ptr)
 {
 	struct erofs_compress_wq_tls *tls;
 
+#if defined(__linux__)
+	prctl(PR_SET_NAME, "erofs_compress");
+#elif defined(__APPLE__)
+	pthread_setname_np("erofs_compress");
+#endif
+
 	tls = calloc(1, sizeof(*tls));
 	if (!tls)
 		return NULL;
-- 
2.51.0



More information about the Linux-erofs mailing list