From nobody Sun Sep 27 23:51:12 2026 X-Original-To: dev-commits-src-all@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 4htLn215M6z6tVfV for ; Sun, 27 Sep 2026 23:51:18 +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 4htLn15HjBz4jxP for ; Sun, 27 Sep 2026 23:51:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790553077; 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=Oow8dasULLTvhHu6NTEpGSfzA/2u1Pc1P+1NEpjtBnn600n6sN0Cgy4I4JoSo3YFF/2yZB qrOc0y06OXl3bd6Y2gkLu6RwGqNF7tWM/F8tchu/GPbOeHy1QbqwjhXjQASfLVCV9pJmHs jP5Jt1vUbjvZFRK3ssVTWvO9F3c6w8+1sedRBVBhYHTx8P4pbROeKp6c4IIvwdz1iBawsJ MkEvdDxuqRRVnfOeQF642MbyxnBC2j/KS130WbDb4sSn8Niks093057i2xJUPeE2KLz8Ft va1wfTip0BBlXJl74DyNEQspH3eQbzOYpyyI9OD06B4smvN6Pr1cyx+DnlHJDQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790553077; b=g5yVF97RLiNf1602U/Gpcchdu9NxKyFs72yZMWE0ScGC6wPSncO70st6tCtgXJVthD5R/F Sk+w/08WER5aLsMxmYDF3Bm4s54cuQ1kx/g3SP/ItKCO8rUAVEmazTZIppciiJ1QRJccyp GZWZLs6N5odewULLPUozATII7hcZ8iJB8P1TUCAz+raAbsIa5fDPeJk10uZfyeVtO0j3Yu 7rWdF75r7Bq4kFxqmTp6RloD1TnolDabdMl4Ft51L+6F8H5vkqe8LWsLg2+f3KkOFuPx0J ZIMgNr9ztjRPS+MaSxwC8Ekghw1jB/2erWBLrraMWTNndQDhkOr6LNL6QY7SLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790553077; 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=FC/1WvjmGbaAmGo3v8lpV9TVZOp8azkwIPRd82QmHXYFXxgNah2f0q5IPbyQu4FUATHcmE 581FH/TU/S+1f6QJTPDzAwqq3bHLvZPrQcf27X3zTnzF1epfs2s503XI0XkXulltc1Kh9J hWiKD9O0HAJXTunP5ei67EgFaAeVFKEwU6kvypd7pun4CY0+ZOlGu3YScIGkmWsyMauwQ7 orYJMYuyCrx7BjRKNNsK2JwGbGXTmaPID43XAvEjudyYEeTSmGA3DsnYPwcGRiTNCggwnd LwEv12eczUWqMjgxlzVBx0ZF02WaYjErnuxxy+iWUupXFguhFfPOKFtA61pP5g== 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 4htLn14G3Dz12Gj for ; Sun, 27 Sep 2026 23:51:17 +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 all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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); }