Bug #14958
closedfakekernel: avoid LWP <defunc> threads
100%
Description
Kernel doesn't require to call thread_join() on threads, instead it uses reaper-thread. It brought LWP <defunc> leaking in libfakekernel, due to nobody calls thread_join() or thr_join() for almost all <defunc> threads.
This patch modifies thread_exit() wrapper:
"orders" to reap <defunc> thread to the call next ensuing.
Testing done:
#include <sys/cmn_err.h> #include <sys/thread.h> #include <sys/zone.h> #include <sys/proc.h> #include <atomic.h> #include <unistd.h> #define N 10 extern int rand(void); static void worker(void) { (void) sleep(rand() % N + 1); thread_exit(); } int main(int argc, char **argv) { unsigned i; kthread_t *tid; for (i = 0; i < 100000; i++) { tid = thread_create(NULL, 0, worker, NULL, 0, NULL, TS_RUN, 0); printf("tid: %ld\n", (uintptr_t)tid); (void) sleep(1); } return (0); }
Used this test program to generate threads and observed with mdb -k '::threadlist' the number of threads. Number of threads was ~10 all times - so the exited threads got reaped.
Updated by Toomas Soome about 1 year ago
Toomas Soome wrote:
Kernel doesn't require to call thread_join() on threads, instead it uses reaper-thread. It brought LWP <defunc> leaking in libfakekernel, due to nobody calls thread_join() or thr_join() for almost all <defunc> threads.
This patch modifies thread_exit() wrapper:
"orders" to reap <defunc> thread to the call next ensuing.This update is import from https://github.com/racktopsystems/illumos-gate:
[...]
I got alternate idea for fix - create reaper thread to call thr_join(). Also we can avoid recording thread id for thr_join() - so there is no chance we can miss some.
Testing done: crafted simple test program to spawn number of threads and then checking with mdb ::threadlist to make sure we have no leftover threads.
Updated by Toomas Soome about 1 year ago
- Category set to lib - userland libraries
- External Bug set to racktop:BSR-4063
Updated by Gordon Ross about 1 year ago
- Status changed from In Progress to Pending RTI
Updated by Electric Monk about 1 year ago
- Status changed from Pending RTI to Closed
- % Done changed from 90 to 100
git commit 589f9b6223af8482576c4b68c4acc0626246eb32
commit 589f9b6223af8482576c4b68c4acc0626246eb32 Author: Vitaliy Gusev <gusev.vitaliy@gmail.com> Date: 2022-09-23T06:51:53.000Z 14958 fakekernel: avoid LWP <defunc> threads Reviewed by: Toomas Soome <tsoome@racktopsystems.com> Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com> Reviewed by: Matt Barden <mbarden@tintri.com> Approved by: Patrick Mooney <pmooney@pfmooney.com>