From nobody Mon Sep 05 11:56:15 2022 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 4MLn6T1HRJz4cB6D; Mon, 5 Sep 2022 11:56:17 +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 4MLn6S3P3Wz3Yqt; Mon, 5 Sep 2022 11:56:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662378976; 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=cpZUC8rGBri98TQ9vwbWBHfPeLu07kA9evPak3mwWF4=; b=fJFzxQMGlMlLmR67c0loXX0zT+o3O5UvWJbgfXIbm/lJymkOaRWSMFzt/PwhCDHVPKS+Le 60UtpA8t3J6r4R6B4eNXwcy5E2zeYbVs3djZbQvpl1sHkIzSvM2BjcYQpexGBxQv7rPSpR SuK62xrgFO76Lf/K8g/Q71vPwZeHPxi0qn62O+xj4OjjUYDE90hfmD1AaHQiE+e5wZeW/u zc+Lp2yRmAxa8otWT/3S6Bc2tQWPK9pV5YeDYoIcKsRmc418itybPxpiHcWKowTjoKGK2L ge/MyClMsH7ErBbrDHzrShD7To1Om56Uc/j4BQhwm/rwznkcRGRK0aUAzhWnqA== 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 4MLn6S0S4xzprm; Mon, 5 Sep 2022 11:56:16 +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 285BuFjJ076783; Mon, 5 Sep 2022 11:56:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 285BuFWK076782; Mon, 5 Sep 2022 11:56:15 GMT (envelope-from git) Date: Mon, 5 Sep 2022 11:56:15 GMT Message-Id: <202209051156.285BuFWK076782@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: 69413598d266 - main - signal: use proc_iterate to save on work 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: 69413598d2660054e29cac9454fe18c08e3bf36d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662378976; 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=cpZUC8rGBri98TQ9vwbWBHfPeLu07kA9evPak3mwWF4=; b=EiNncxk+Ty3tg/l7yparBQa+N+LxFHG8Rm6nCQeAtDXjAeQ4hHPIujkoHcSw8Ha8xwB6Ts aCyjHabsTotIuh83/h06xcbxlmwT+53b6RuDDTzorJuxGga7uh77nnpXH0WAQRo2vRABvq 8bvysbrG8sMMJkiaoyZPFki81UMXKUzllKlgtMQ+HpujLacA1oryVonajXssclCBvCiWyx yjIdTV41UGL2TDH4cQaAUQd+A3ECTWf32eLyYHWSxz0H/yHcWTcnzizIKXM/LmFyEhTDe9 NTZtDxkpfdThFqafnpx2fVq50ERay8V/l4l+V2KAz+fmTmULcoBL4v2RyNXzRA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662378976; a=rsa-sha256; cv=none; b=bKUCGliupnRHsouuKUAMJpuYa2LFWKDKoMVBEvFtfjV+aNXjuPdbURxBXlY7Wf+6UpmuGG 3cnQntFXiXP7+z0upQqCJrCA8Rw4iS+Gg9jSARTdR6GsQc/zmBpyFaNBVY5pFcchHUsjRU 1006AujRoYYfmRkaRNdMtelHLgX2XZp0qSrhAUvkaUY+vmh/nyq0eybOnr7EW38QkHelzy vXyHn2/kmSK63we7HKst8IW3Q10QpqA1IEsMRhv6UHO2OuB8TObZWDMiX+6kPmKGc0QDXf HnupSxmGNGmreaNL0jwk4M/EXoSLM+l+tju/7eCuaYSFOvWhUYxSmz9nY33i8g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=69413598d2660054e29cac9454fe18c08e3bf36d commit 69413598d2660054e29cac9454fe18c08e3bf36d Author: Mateusz Guzik AuthorDate: 2022-03-10 18:58:12 +0000 Commit: Mateusz Guzik CommitDate: 2022-09-05 11:54:47 +0000 signal: use proc_iterate to save on work Most notably poudriere performs kill -9 -1 in jails for each port being built. This reduces the scan from hundrends of processes to literally 1. Reviewed by: jamie, markj Differential Revision: https://reviews.freebsd.org/D34522 --- sys/kern/kern_sig.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 6fd3eca0a14e..c50a37de07e6 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1776,18 +1776,13 @@ struct killpg1_ctx { }; static void -killpg1_sendsig(struct proc *p, bool notself, struct killpg1_ctx *arg) +killpg1_sendsig_locked(struct proc *p, struct killpg1_ctx *arg) { int err; - if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 || - (notself && p == arg->td->td_proc) || p->p_state == PRS_NEW) - return; - PROC_LOCK(p); err = p_cansignal(arg->td, p, arg->sig); if (err == 0 && arg->sig != 0) pksignal(p, arg->sig, arg->ksi); - PROC_UNLOCK(p); if (err != ESRCH) arg->found = true; if (err == 0) @@ -1796,6 +1791,31 @@ killpg1_sendsig(struct proc *p, bool notself, struct killpg1_ctx *arg) arg->ret = err; } +static void +killpg1_sendsig(struct proc *p, bool notself, struct killpg1_ctx *arg) +{ + + if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 || + (notself && p == arg->td->td_proc) || p->p_state == PRS_NEW) + return; + + PROC_LOCK(p); + killpg1_sendsig_locked(p, arg); + PROC_UNLOCK(p); +} + +static void +kill_processes_prison_cb(struct proc *p, void *arg) +{ + struct killpg1_ctx *ctx = arg; + + if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 || + (p == ctx->td->td_proc) || p->p_state == PRS_NEW) + return; + + killpg1_sendsig_locked(p, ctx); +} + /* * Common code for kill process group/broadcast kill. * cp is calling process. @@ -1817,11 +1837,8 @@ killpg1(struct thread *td, int sig, int pgid, int all, ksiginfo_t *ksi) /* * broadcast */ - sx_slock(&allproc_lock); - FOREACH_PROC_IN_SYSTEM(p) { - killpg1_sendsig(p, true, &arg); - } - sx_sunlock(&allproc_lock); + prison_proc_iterate(td->td_ucred->cr_prison, + kill_processes_prison_cb, &arg); } else { sx_slock(&proctree_lock); if (pgid == 0) {