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

Nithurshen Karthikeyan
2026-03-16T17:11:24Z

Hi Xiang,

Sorry for the confusion. I sent the v2 patch before reading your
v1 reply, as I noticed the quotes formatting was off in my first
submission and wanted to fix it.

On Mon, Mar 16, 2026 at 10:19 PM Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
>
> On 2026/3/16 23:13, Nithurshen wrote:
> > 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\`.
>
> Please just use `top`, `htop`, or `ps` here.

Yes, I have taken care of this in the updated commit message.

> > This utilizes \`prctl(PR_SET_NAME)\` on Linux and \`pthread_setname_np\`
> > on macOS to explicitly label these threads as \"erofs_compress\" upon
> > initialization.
>
> Why not just calling erofs_compressor, since those worker are really
> compressor.

I initially tested using "erofs_compressor", but the OS thread naming
API (`prctl` with `PR_SET_NAME`) has a strict 16-byte limit,
which includes the null terminator.

Because "erofs_compressor" is exactly 16 characters long, the null
byte pushes it to 17 bytes. As a result, the kernel truncates it, and
it actually shows up as "erofs_compresso" in `ps` and `top`.

To keep the output looking clean and intentional, I chose to use
"erofs_compress" (14 chars) instead. Please let me know if you are
okay with this, or if you'd prefer a different abbreviation.

> > +#if defined(__linux__)
> > + prctl(PR_SET_NAME, "erofs_compress");
> > +#elif defined(__APPLE__)
> > + pthread_setname_np("erofs_compress");
> > +#endif
>
> I don't think they should be added here, you could
> add in .on_start() of lib/compress.c instead.

Yes, it has been moved to lib/compress.c

Thanks,
Nithurshen