Project

General

Profile

Actions

Bug #14958

closed

fakekernel: avoid LWP <defunc> threads

Added by Toomas Soome 24 days ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:
racktop:BSR-4063

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.

Actions #1

Updated by Electric Monk 24 days ago

  • Gerrit CR set to 2340
Actions #2

Updated by Toomas Soome 24 days ago

  • Description updated (diff)
Actions #3

Updated by Toomas Soome 14 days 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.

Actions #4

Updated by Toomas Soome 13 days ago

  • Description updated (diff)
Actions #5

Updated by Toomas Soome 11 days ago

  • Category set to lib - userland libraries
  • External Bug set to racktop:BSR-4063
Actions #6

Updated by Toomas Soome 11 days ago

  • Description updated (diff)
Actions #7

Updated by Toomas Soome 11 days ago

  • Description updated (diff)
Actions #8

Updated by Gordon Ross 11 days ago

  • Status changed from In Progress to Pending RTI
Actions #9

Updated by Electric Monk 8 days 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>

Actions

Also available in: Atom PDF