From owner-freebsd-current@freebsd.org Thu Oct 24 18:57:25 2019 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1BFD3177528 for ; Thu, 24 Oct 2019 18:57:25 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound2m.ore.mailhop.org (outbound2m.ore.mailhop.org [54.149.155.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46zc1c52KZz4SmM for ; Thu, 24 Oct 2019 18:57:24 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1571943443; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=eJaSA1692xBbQdmEtArfQtzieke9+KbK0cY6sg2s/og6B3o4xpXAVSVkO4NLOiMEdz4BA0pWK14KE z3wRW8sZ3low7S5JnYVcq47cVAZ/J3+Au2RS6ls/lN1yJxJqKNpoRPPM20lwSw3IvWi28mrtDCaa4p 2hWZsglxSmUmdHgRaVmEXg6KKcAbLtjn1kR3UB3kMLhUeQByDjF+aHhIaCbnzGC0xh/yoq7//mLamp ah4sOfr20BIlTwDnDPI6/GGKRekqpVJ2rc92Wrqnguk55HM+KhNHWxmSSH/UlyxtHEJbb8yRXsTZsK N2hhGSkP+Ro2mZCVBUp5EBGmJVGAfRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:dkim-signature:from; bh=I0HcuDF5QGk/rsWzYIO1E2BODIB+gIDaIpxWTyqutTo=; b=i1upWuADBUSrmXJGSQ7Vc68sgj70p4MCboM8C2a+/kgDCOM/V7cjGoQ2XgsOEyFyMhnN6tFxy/ZTO PWiwh0mgXzi7Zu4X1MueIOfDXXzUhYY6VU9RVf7zIwetoZGrZHBU1dEbCgoze3pnF/8fJCkKoZQNog ZvDzk1EDC4K8h3MRxHy1NWKJc0pnpCXV3YZU+zrjWwJPLqt+Pprnz1Zq8MV2/aEqwhdFlebRZBHQxe A+b9emG1F4I3k3v3OHPKvFqieAGe2vzoZxLF7AFsbjehsItz22bqsp/utdKNpWL5dGFsJWHielzt8J zj67tFnnggI6QqyuV1eLom5v6KDl8Ug== ARC-Authentication-Results: i=1; outbound4.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:from; bh=I0HcuDF5QGk/rsWzYIO1E2BODIB+gIDaIpxWTyqutTo=; b=rMB9aMDkAV560yAMu8XiiFOTm+t1/TkM21rZybbMt9niN/IvXcBxbQRrtoyuTMT1Z2zx093lW7oEs pMQ4pBHByWPFQhIjAFoh4J7eqk6IopZZcdYETPRx+uIMrD7Wv0HFNnIiDMTU9L90VB3iV03T5P3PP+ ueulkILjsh1c/ngBihRqHtYm1lC9/9HJYhUr/Ue3rP8eiMPQ/R7AWwPBzgFJei7+f/Vb63uWdf3bhk T3+Lt/llROuNBv+aK0tEX8os6v1Zf0yN56NHpvSFWE4jf5YgzN/gYHcCxrn6NDL6HKku5PcF5XkzJ6 l0niTlWKKVKtdUgD6jIBqsDEyFh1bEg== X-MHO-RoutePath: aGlwcGll X-MHO-User: 1b7a1107-f690-11e9-829e-79a40d15cccd X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [67.177.211.60]) by outbound4.ore.mailhop.org (Halon) with ESMTPSA id 1b7a1107-f690-11e9-829e-79a40d15cccd; Thu, 24 Oct 2019 18:57:21 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id x9OIvKlV045892; Thu, 24 Oct 2019 12:57:20 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: Subject: Re: Best thread pool implementation for the base system? From: Ian Lepore To: Alan Somers , FreeBSD CURRENT Date: Thu, 24 Oct 2019 12:57:20 -0600 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 46zc1c52KZz4SmM X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-1.87 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-0.88)[-0.875,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:16509, ipnet:54.148.0.0/15, country:US] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Oct 2019 18:57:25 -0000 On Thu, 2019-10-24 at 12:46 -0600, Alan Somers wrote: > I count 5 thread pool implementations in contrib: > * cddl/compat/opensolaris/misc/thread_pool.c > * contrib/apr-util/misc/apr_thread_pool.c > * contrib/llvm/lib/Support/ThreadPool.cpp > * contrib/openmp/runtime/src/kmp_tasking.cpp > * contrib/ofed/opensm/complib/cl_threadpool.c > > However, I can't find any examples outside of contrib. I'd like to > use one > in /sbin/geli. Shall I roll my own (as everybody else apparently > does), or > is there something I'm not aware of? > > Whenever the subject of thread pools comes up at $work I pose this question: What task is it you need to accomplish where the cost of pthread_create/delete is significant in relation to the actual work that will be done during the lifetime of the thread? Over the years, the answers have been such that we never created a thread pool class or helpers. What we did eventually come up with was basically an async taskqueue that had a single thread, because almost always the answer to the question was something like "the work to be done is really tiny and not-time-critical, it just needs to be done on a different thread to avoid [recursion|deadlock|whatever]." So I'd say the first thing to do is be sure that the best solution isn't just to pthread_create() as needed. If it turns out the cost of pthread_create() is like 1-2% of the total work to be done, you may not need a pool of pre-created threads. -- Ian