mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Create threads in detached state in userspace.
Currently, thread_create(), when called in userspace, creates a
joinable (i.e. not detached thread). This is the pthread default.
Unfortunately, this does not reproduce kthreads behavior (kthreads
are always detached). In addition, this contradicts the original
Solaris code which creates userspace threads in detached mode.
These joinable threads are never joined, which leads to a leakage of
pthread thread objects ("zombie threads"). This in turn results in
excessive ressource consumption, and possible ressource exhaustion in
extreme cases (e.g. long ztest runs).
This patch fixes the issue by creating userspace threads in detached
mode. The only exception is ztest worker threads which are meant to be
joinable.
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #989
This commit is contained in:
committed by
Brian Behlendorf
parent
6d1d976b2c
commit
0aebd4f9e3
@@ -141,7 +141,7 @@ zk_thread_helper(void *arg)
|
||||
|
||||
kthread_t *
|
||||
zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg,
|
||||
size_t len, proc_t *pp, int state, pri_t pri)
|
||||
size_t len, proc_t *pp, int state, pri_t pri, int detachstate)
|
||||
{
|
||||
kthread_t *kt;
|
||||
pthread_attr_t attr;
|
||||
@@ -181,6 +181,7 @@ zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg,
|
||||
VERIFY3S(pthread_attr_init(&attr), ==, 0);
|
||||
VERIFY3S(pthread_attr_setstacksize(&attr, stack), ==, 0);
|
||||
VERIFY3S(pthread_attr_setguardsize(&attr, PAGESIZE), ==, 0);
|
||||
VERIFY3S(pthread_attr_setdetachstate(&attr, detachstate), ==, 0);
|
||||
|
||||
VERIFY3S(pthread_create(&kt->t_tid, &attr, &zk_thread_helper, kt),
|
||||
==, 0);
|
||||
|
||||
Reference in New Issue
Block a user