From nobody Wed Apr 27 23:27:51 2022 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 26B3D1AA91D6; Wed, 27 Apr 2022 23:27:53 +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 4KpZfw0pmQz4YbH; Wed, 27 Apr 2022 23:27:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651102072; 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=5r8+/O/AKCCksMoEEm2bUYyymnfu5az/nVCsZCN4RZI=; b=xLgmcZA/NTIc6HF+a9zGU6oMK3E20gvzm2HPcyJ7wTK19PZEMh1zl+BnwREdX9bQmKT4s1 i8+Ai4ngS18tUhUeIUDWqJFgvQosi68E1vlXZPc99HgMZAxB7dxEhaIE6XPdRPph4fzHVr bpWBaXIX+wJtN6i3UeX5XUoMDZpPgzbX9ooVV7g0mvnJEaq7ru/VxyjUM3MrsBR715fusA op1opaMqGi1RAL5hchcwg8i2dQO0fBsDzwj3z4Qjlc1HXVuzUE9YsC2ianQEjoFtbjdvRS DKKRmINlxQvUjCLTg6M7/uB2uFB5Gg/3nuwq9oKVP5G93eeFdB3bjBP8ryOjTw== 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 BD0035647; Wed, 27 Apr 2022 23:27:51 +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 23RNRp1b071887; Wed, 27 Apr 2022 23:27:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23RNRp2W071886; Wed, 27 Apr 2022 23:27:51 GMT (envelope-from git) Date: Wed, 27 Apr 2022 23:27:51 GMT Message-Id: <202204272327.23RNRp2W071886@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 54a11adbd9c2 - main - reap_kill(): split children and subtree killers into helpers 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: 54a11adbd9c2b1fa9b42181ac883ed6ed2a6998c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651102072; 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=5r8+/O/AKCCksMoEEm2bUYyymnfu5az/nVCsZCN4RZI=; b=TJXUM8gwuFlyEeggPtFzyTocHrUCnQwNriRhuoOcmfHW8mDBxd4bJEwRt3tf1qzRn7XwLU gRxaiSQrRvOKrOXfDY+nXYM6zUs80Tlk4SnsjwAcY4QYXfSNiexRXkLakcvZoC6k9u3Wb/ N3tsXhhhVDp0ijDop05QHDElg5fxdnvBhglPedHTijsGD1D1OMB+Pcl4DRpo7cC1MpCq1O Yr3gY7oe5DHJRHosnzDfI/tzogfVVQFUal+fX7+qLT1UQu1sb14YmyN8a8OqYbAofiz4cs kIP9ueppETuSkVbCE00XS+F3CdWxePwmsKwFZqubX5Zh/7wp17ZWG+JOjMKPSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651102072; a=rsa-sha256; cv=none; b=CnIBhSvDk2sbOVOAhmBvItFuUC2RR/bRjfkL1U8i1WYOJ1l/ure9VEopfIiYibtA18RWYw TDzgeFz3Z3ucmmaVUjdo+7/X9FzG6ce2L5LSQJE7fTNlBkwj3rzK2v7LxpttkZw+/fAaIF /zPUz4GL//lpvd6bW8oIgRwBytJ63T5NTapc/q3swlFqYMWwaLY50k60y1mA99g3gRJ5Mo hFWLA9YmhtbTfHv4F7+daNk+a7YYNnLUvX39Rl5I/kNIIcyhuvKuHCiPpGFegad7AYOqp9 VSrXs5aTrSrB0uTvi0DaN/RDYs34A8qKH7l76ddJvjbTfTU0AoIjT8kB909DDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=54a11adbd9c2b1fa9b42181ac883ed6ed2a6998c commit 54a11adbd9c2b1fa9b42181ac883ed6ed2a6998c Author: Konstantin Belousov AuthorDate: 2022-04-20 21:12:05 +0000 Commit: Konstantin Belousov CommitDate: 2022-04-27 23:27:34 +0000 reap_kill(): split children and subtree killers into helpers Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D35014 --- sys/kern/kern_procctl.c | 71 ++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/sys/kern/kern_procctl.c b/sys/kern/kern_procctl.c index a8c56f7ae8ff..bc7ba14a6f97 100644 --- a/sys/kern/kern_procctl.c +++ b/sys/kern/kern_procctl.c @@ -278,13 +278,52 @@ reap_kill_sched(struct reap_kill_tracker_head *tracker, struct proc *p2) TAILQ_INSERT_TAIL(tracker, t, link); } +static void +reap_kill_children(struct thread *td, struct proc *reaper, + struct procctl_reaper_kill *rk, ksiginfo_t *ksi, int *error) +{ + struct proc *p2; + + LIST_FOREACH(p2, &reaper->p_children, p_sibling) { + reap_kill_proc(td, p2, ksi, rk, error); + /* + * Do not end the loop on error, signal everything we + * can. + */ + } +} + +static void +reap_kill_subtree(struct thread *td, struct proc *p, struct proc *reaper, + struct procctl_reaper_kill *rk, ksiginfo_t *ksi, int *error) +{ + struct reap_kill_tracker_head tracker; + struct reap_kill_tracker *t; + struct proc *p2; + + TAILQ_INIT(&tracker); + reap_kill_sched(&tracker, reaper); + while ((t = TAILQ_FIRST(&tracker)) != NULL) { + MPASS((t->parent->p_treeflag & P_TREE_REAPER) != 0); + TAILQ_REMOVE(&tracker, t, link); + LIST_FOREACH(p2, &t->parent->p_reaplist, p_reapsibling) { + if (t->parent == reaper && + (rk->rk_flags & REAPER_KILL_SUBTREE) != 0 && + p2->p_reapsubtree != rk->rk_subtree) + continue; + if ((p2->p_treeflag & P_TREE_REAPER) != 0) + reap_kill_sched(&tracker, p2); + reap_kill_proc(td, p2, ksi, rk, error); + } + free(t, M_TEMP); + } +} + static int reap_kill(struct thread *td, struct proc *p, void *data) { - struct proc *reaper, *p2; + struct proc *reaper; ksiginfo_t ksi; - struct reap_kill_tracker_head tracker; - struct reap_kill_tracker *t; struct procctl_reaper_kill *rk; int error; @@ -309,31 +348,9 @@ reap_kill(struct thread *td, struct proc *p, void *data) rk->rk_killed = 0; rk->rk_fpid = -1; if ((rk->rk_flags & REAPER_KILL_CHILDREN) != 0) { - LIST_FOREACH(p2, &reaper->p_children, p_sibling) { - reap_kill_proc(td, p2, &ksi, rk, &error); - /* - * Do not end the loop on error, signal - * everything we can. - */ - } + reap_kill_children(td, reaper, rk, &ksi, &error); } else { - TAILQ_INIT(&tracker); - reap_kill_sched(&tracker, reaper); - while ((t = TAILQ_FIRST(&tracker)) != NULL) { - MPASS((t->parent->p_treeflag & P_TREE_REAPER) != 0); - TAILQ_REMOVE(&tracker, t, link); - LIST_FOREACH(p2, &t->parent->p_reaplist, - p_reapsibling) { - if (t->parent == reaper && - (rk->rk_flags & REAPER_KILL_SUBTREE) != 0 && - p2->p_reapsubtree != rk->rk_subtree) - continue; - if ((p2->p_treeflag & P_TREE_REAPER) != 0) - reap_kill_sched(&tracker, p2); - reap_kill_proc(td, p2, &ksi, rk, &error); - } - free(t, M_TEMP); - } + reap_kill_subtree(td, p, reaper, rk, &ksi, &error); } PROC_LOCK(p); return (error);