From nobody Sun Sep 27 23:51:12 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4htLmw6cQ4z6tVTx for ; Sun, 27 Sep 2026 23:51:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4htLmw41xKz4jxv for ; Sun, 27 Sep 2026 23:51:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790553072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=shyP884tJTl6oQrPhIW7sfMcpIAsY3gfw8BqJt2W2FA=; b=f2KpvoFW8xbZXFK+D1GJkK4dvVS3zJpxmxfGhavlCz1raDWsp/8fVoK/ZOczHqjdsEMkU2 agqid2Nsgw6pi/lpwuSE2uNF1M//NW3Ov1RQVfkiO5hZbBXq23wNfzF1VBxlGdHRbUhg1A L9acgO0k3LyV+JEK6zjRxW48ItTQZCS9UPrOBnAxPf8WaTVn5bOMjoU36NhJWMCVwKE7a5 l7ZywsEU0/Py10/F3SKmIjQbYpCrGZ0hhuUTZ/cGOGF4pOrKPgX4+PrvIrxjlNuxgIxDGn N/2wV8N5nmHYRS2LYuREDZBroL5JGfGEzaDBodpMgodYKgV7qVcTIRiayxiCwQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790553072; b=shMgFUf7oDAC6EhD4MDogR7n4zkzn3mj2q8mxzQDOviaNQyF1h2kCBem7DWJfQCMhMuoCR KysNVdZ3H2ypr5w07wNGBhFOGVdp0NmKq8kOZT7QJs9lC7ZXUI4c4uhDmVdJpQk0UnIGZV qFUOa8HOuSVkKzqQVgOhNxIIyXSF1PNcE1qfMYy/VqmxHjeZnoJi9OW/FEegFxHsqX/+pv I7/BoIXmwIn645EP5snnz7Armwvx5ulkXXWxtYzMQSmTOPeYJy/yRXcjYi9UoS1RjHE/at dAWil8qDJXgvxhQ8KnWdmBkYhRDWHs1XlCSePoqrymikJe5FAyvqaxonqccL2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790553072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=shyP884tJTl6oQrPhIW7sfMcpIAsY3gfw8BqJt2W2FA=; b=MK108Djv7UyJ90bvw5F5kNI68wnyP6eZDv2nED3GH57rWxfISZowIqRhjq4pZRhQPCTCxZ CWYa1ugnzIj+2nyxGmxSGlrjeFoLTl0dqOJBhUuOxienQNl3nwjNYQc6ULNVQADxEuiSCL zhbZVrv4rcLVWbDSgfZItpaUaL3eWkQT9ixnokE1GXTqO4WJEkW4xD+MrAWXiP+S9AjTym kmcH5FX/dWvPn3j24wq7C9RrgH+KjOo/Y1ZmKUpNIQbx4zJ9VAFZ1XO3vpWO5stmYHDCMT PREgtVRe14L4Xd6/BtBAIKvkim0jSlSFR42pY3yIyjiEqkTD+/nhjtCR1zed7A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4htLmw36Nyz13DK for ; Sun, 27 Sep 2026 23:51:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 366a5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 27 Sep 2026 23:51:12 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4472a048cf95 - main - libthr: GC pshared locks not more than each 25msecs by default List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4472a048cf95c9c1593a8b04655a59096b44b0c9 Auto-Submitted: auto-generated Date: Sun, 27 Sep 2026 23:51:12 +0000 Message-Id: <6ab9abf0.366a5.3ba70b7b@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4472a048cf95c9c1593a8b04655a59096b44b0c9 commit 4472a048cf95c9c1593a8b04655a59096b44b0c9 Author: Konstantin Belousov AuthorDate: 2026-09-27 22:16:33 +0000 Commit: Konstantin Belousov CommitDate: 2026-09-27 22:30:00 +0000 libthr: GC pshared locks not more than each 25msecs by default Provide a tunable env variable to request immediate GC on destroy to allow to return to the previous behavior. Based on the report and patch by Atle Solbakken . PR: 268532 Sponsored by: The FreeBSD Foundation MFC after: 1 week --- lib/libthr/thread/thr_init.c | 3 +++ lib/libthr/thread/thr_private.h | 1 + lib/libthr/thread/thr_pshared.c | 25 ++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 0f9e3749d75f..162ef7dfe7a9 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -539,6 +539,9 @@ init_private(void) mint, NULL, NULL); } } + env = getenv("LIBPTHREAD_PSHARED_LOCK_DESTROY_IMMEDIATE_GC"); + if (env) + __thr_pshared_destroy_imm_gc = true; } init_once = 1; } diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index d7b889930365..2edf09d761ae 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -780,6 +780,7 @@ extern struct pthread *_single_thread __hidden; extern bool _thr_after_fork __hidden; extern int __thr_new_flags; +extern bool __thr_pshared_destroy_imm_gc __hidden; /* * Function prototype definitions. diff --git a/lib/libthr/thread/thr_pshared.c b/lib/libthr/thread/thr_pshared.c index d20d66e21ea3..698cc5e6adc7 100644 --- a/lib/libthr/thread/thr_pshared.c +++ b/lib/libthr/thread/thr_pshared.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "namespace.h" #include #include "un-namespace.h" @@ -49,6 +50,10 @@ static struct pshared_hash_head pshared_hash[HASH_SIZE]; static struct urwlock pshared_lock = DEFAULT_URWLOCK; static int page_size; +#define GC_INTERVAL_USEC 25000 +static struct timeval pshared_gc_time = {0, 0}; +bool __thr_pshared_destroy_imm_gc = false; + void __thr_pshared_init(void) { @@ -94,9 +99,8 @@ pshared_unlock(struct pthread *curthread) * mapped off-page. * * Mitigate the problem by checking the liveness of all hashed keys - * periodically. Right now this is executed on each - * pthread_lock_destroy(), but may be done less often if found to be - * too time-consuming. + * periodically. Right now this is executed on pthread_lock_destroy() + * if previous gc happen later than 25msecs. */ static void pshared_gc(struct pthread *curthread) @@ -104,8 +108,18 @@ pshared_gc(struct pthread *curthread) struct pshared_hash_head *hd; struct psh *h, *h1; int error, i; + struct timeval now, diff; pshared_wlock(curthread); + + if (!__thr_pshared_destroy_imm_gc && gettimeofday(&now, NULL) == 0) { + timersub(&now, &pshared_gc_time, &diff); + if (diff.tv_sec == 0 && diff.tv_usec < GC_INTERVAL_USEC) { + pshared_unlock(curthread); + return; + } + } + for (i = 0; i < HASH_SIZE; i++) { hd = &pshared_hash[i]; LIST_FOREACH_SAFE(h, hd, link, h1) { @@ -118,6 +132,11 @@ pshared_gc(struct pthread *curthread) free(h); } } + + if (!__thr_pshared_destroy_imm_gc && gettimeofday(&now, NULL) == 0) { + pshared_gc_time = now; + } + pshared_unlock(curthread); }