doc/developer-guide/thread-naming.md
Gluster processes spawn many threads; some threads are created by libglusterfs library, while others are created by xlators. When gfapi library is used in an application, some threads belong to the application and some are spawned by gluster libraries. We also have features where n number of threads are spawned to act as worker threads for same operation.
In all the above cases, it is useful to be able to determine the list of threads that exist in runtime. Naming threads when you create them is the easiest way to provide that information to kernel so that it can then be queried by any means.
We have two wrapper functions in libglusterfs for creating threads. They take name as an argument and set thread name after its creation.
gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg, const char *name)
gf_thread_create_detached (pthread_t *thread,
void *(*start_routine)(void *), void *arg,
const char *name)
As max name length for a thread in POSIX is only 16 characters including the '\0' character, you have to be a little creative with naming. Also, it is important that all Gluster threads have common prefix. Considering these conditions, we have "glfs_" as prefix for all the threads created by these wrapper functions. It is responsibility of the owner of thread to provide the suffix part of the name. It does not have to be a descriptive name, as it has only 10 letters to work with. However, it should be unique enough such that it can be matched with a table which describes it.
If n number of threads are spwaned to perform same function, it is must that the threads are numbered.
Thread names don't have to be a descriptive; however, it should be unique enough such that it can be matched with a table below without ambiguity.