From nobody Sat May 20 12:48:28 2023 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 4QNk65059cz4C2Yb; Sat, 20 May 2023 12:48:29 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QNk646dpfz49sr; Sat, 20 May 2023 12:48:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684586908; 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=+pa1yPvWUDtefP6qZaq9wHg6ZsmVYjsNllQDzXaDV8w=; b=M1e1nVSMOheNf44iafs4ueMujuNWbuIZumAYhBe6A3kJdG8D/oOQS7fwKcXqoMEeJ2ilR3 +x9zUMabvH7YTi6B3ZwwQ5XVRr1p1a7SGgmKPl4PA/1TPg6PO+babOqToKGhIqgHzumfh7 94FOJQqVEVYhg9DwvR+ZW5hbEM3fXJ/8BUqZMCxZ4tybILSl7YUC3VOG1+gDtb11XiUhlu HHYD1Uqca+UfEYBmOjcrgV54uSBzjGe9LSvNe8/3MuFnyQzf1LYrEogbFNNVPmQqIvQvFo XECtJMcq9uX2fs0UchJS2Mzge5mnhTY66apfWpweRpf+L3fo39P2hoKfWzBX7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684586908; 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=+pa1yPvWUDtefP6qZaq9wHg6ZsmVYjsNllQDzXaDV8w=; b=xGUEjOZxAF/z/HFPd/CTTxfPEMMuOTqS64eowjEJyv8Xg5QDGmMFDG+LLqo1fvd9PBOvjf C2shMCOwoP2FJiCpToRqoTY9yR53m/RXEI2HgffsJQ/2EY/U2uSWEnpZHK03BYho4LGL6z FfMpiSrvby/oHwqy+P2RaHktlXH7rh2t4Yb8pWxhM3kOWYMFHhyAi6VpG5JOBRcORJ1KAo jxugkcHqFDfk+PKBLIjey8lYgzHs/pSdy827z1VTM0b6CecWy8VbLPnl/sdxDqN7p39Ch6 VOC6SZaA6IK2RhApm7IJHYQ0qO2m1RFFaGB8SVPEmydhhjRDeUPTM17DQ2fAdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684586908; a=rsa-sha256; cv=none; b=OtyaYl/vWc/DgUOadfVsT1I619Doz9ksm+d31Wvnlxx1PP+CBOepUA6oaQMdfdIq7gCSYh YHuPyxSze9lhe0G1DO9vYTfBe8zl29qEFA/288fk5cdfG6ohdqLdMTMmxt8ZePnhlI2Aa3 MM1rGQU4CqzzsGtoVgfer0zOnZiGSV1qiFB7Wbz8w605VOEA3/7oUCRZUbcEYiSESNS+Zx MGge5AfNB2Cq8Ync/npGVHD5MyeMeoMovVbMWtZaIJl1z6ILc9vEiDnBT80WuP9c8p50d7 c6WTduh77jjyADRH/eup+M8Gq7o3j7j3q6z+2rngK4ianX3KtxGQiEWbE2vQyw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QNk645kDzz18r8; Sat, 20 May 2023 12:48:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34KCmSHh034024; Sat, 20 May 2023 12:48:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34KCmSgW034023; Sat, 20 May 2023 12:48:28 GMT (envelope-from git) Date: Sat, 20 May 2023 12:48:28 GMT Message-Id: <202305201248.34KCmSgW034023@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: bbe62559c78f - main - rlimit: line up with other clean up in thread_reap_domain 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bbe62559c78f22e2774e12a058981ee8e46afbee Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=bbe62559c78f22e2774e12a058981ee8e46afbee commit bbe62559c78f22e2774e12a058981ee8e46afbee Author: Mateusz Guzik AuthorDate: 2022-08-19 19:37:33 +0000 Commit: Mateusz Guzik CommitDate: 2023-05-20 12:46:46 +0000 rlimit: line up with other clean up in thread_reap_domain NFC --- sys/kern/kern_resource.c | 27 +++++++++++++++++++++++++++ sys/kern/kern_thread.c | 24 +++++++++--------------- sys/sys/resourcevar.h | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index be81f97847de..b1ce9526d4cc 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1276,6 +1276,33 @@ lim_freen(struct plimit *limp, int n) free((void *)limp, M_PLIMIT); } +void +limbatch_add(struct limbatch *lb, struct thread *td) +{ + struct plimit *limp; + + MPASS(td->td_limit != NULL); + limp = td->td_limit; + + if (lb->limp != limp) { + if (lb->count != 0) { + lim_freen(lb->limp, lb->count); + lb->count = 0; + } + lb->limp = limp; + } + + lb->count++; +} + +void +limbatch_final(struct limbatch *lb) +{ + + MPASS(lb->count != 0); + lim_freen(lb->limp, lb->count); +} + /* * Make a copy of the plimit structure. * We share these structures copy-on-write after fork. diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index b62bfafa58be..585531d3ab3a 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -588,9 +588,8 @@ thread_reap_domain(struct thread_domain_data *tdd) struct thread *itd, *ntd; struct tidbatch tidbatch; struct credbatch credbatch; + struct limbatch limbatch; int tdcount; - struct plimit *lim; - int limcount; /* * Reading upfront is pessimal if followed by concurrent atomic_swap, @@ -612,42 +611,37 @@ thread_reap_domain(struct thread_domain_data *tdd) tidbatch_prep(&tidbatch); credbatch_prep(&credbatch); + limbatch_prep(&limbatch); tdcount = 0; - lim = NULL; - limcount = 0; while (itd != NULL) { ntd = itd->td_zombie; EVENTHANDLER_DIRECT_INVOKE(thread_dtor, itd); + tidbatch_add(&tidbatch, itd); credbatch_add(&credbatch, itd); - MPASS(itd->td_limit != NULL); - if (lim != itd->td_limit) { - if (limcount != 0) { - lim_freen(lim, limcount); - limcount = 0; - } - } - lim = itd->td_limit; - limcount++; + limbatch_add(&limbatch, itd); + thread_free_batched(itd); + tidbatch_process(&tidbatch); credbatch_process(&credbatch); + limbatch_process(&limbatch); tdcount++; if (tdcount == 32) { thread_count_sub(tdcount); tdcount = 0; } + itd = ntd; } tidbatch_final(&tidbatch); credbatch_final(&credbatch); + limbatch_final(&limbatch); if (tdcount != 0) { thread_count_sub(tdcount); } - MPASS(limcount != 0); - lim_freen(lim, limcount); } /* diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index bd57211c75f0..8b88c9321e70 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -82,6 +82,28 @@ struct plimit { int pl_refcnt; /* number of references */ }; +struct limbatch { + struct plimit *limp; + int count; +}; + +static inline void +limbatch_prep(struct limbatch *lb) +{ + lb->limp = NULL; + lb->count = 0; +} + +void limbatch_add(struct limbatch *lb, struct thread *td); + +static inline void +limbatch_process(struct limbatch *lb __unused) +{ + +} + +void limbatch_final(struct limbatch *lb); + struct racct; /*-