From nobody Mon Sep 05 16:07:08 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 4MLtgy6wvzz1HGpG; Mon, 5 Sep 2022 16:07:10 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MLtgy5wjBz42ty; Mon, 5 Sep 2022 16:07:10 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-lf1-x12b.google.com with SMTP id w8so13659782lft.12; Mon, 05 Sep 2022 09:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date; bh=CuYxkzuO/HdmChdVZpyXJi3SXHdbGEd4iJfytU+Or6U=; b=SPdflnWT/zIlRbL03oInnZPwS4cVqgFcPm7gxsmpl0y++KpufM8igJfuJ0jTP/itKd tjTSnnEkrICi6yHftBOb2Lh85x5IjPAYhmNHvU3TDHuT6VCqVooOUwB0dqyRyojZ96XO ii0M6WZApR8MwCkUeczD8Z395MTsQ7Ctk+QoOfz0K3iUPSMxTce7Tl7XN48+ER+KAYPS ooR13FIquhAi6Mr186MLbg2F/TWSY/U20DcUSHTRffvn8/mF4p0lI0nMXblyNqnOM4JX UnYAGpFVj5BKfHnPR97gvFeTqfEsUf19T4itQ13nWBtbLVecqvCzw+w0JMAExNphi8f0 AZ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=CuYxkzuO/HdmChdVZpyXJi3SXHdbGEd4iJfytU+Or6U=; b=0RI/n6I5lGW53P9rwEgjF+MJDaJcaqLtDjI+/WhVEuj3x4hBbeDHJQrob/eeS458D0 dlcpBXnD3ywdDQvKg8E3Y0DZIabDPwfkJQ9FNTSIj6IHgf2G9iy+GrpZX+P6m13chfSF kizWskH6Kr/n8Z3RwRDj2iglzmv93nHyCiiT5qormzRn141XQcMv4CTXRqUzuL12oCRk uuT9cWM2vIYzi9fIW9kh2eJgWuOTWAaF+AAg7p80HK81mj2UlZ+pZEhlJuqc1n6adbl0 OXIQjQHcpQuQK65+tfRRrJ7NbKCA3WhoYuwKu+ehr7wyZWWHgqLh6fCaTiXnNGTUuIGQ s6PA== X-Gm-Message-State: ACgBeo3c4wOYN4lmSKlYnaaIJZmeMzN+X9ZecWpaSm8qmqwnBlof1MaI SPvW5z52bkiHc5MitCW7BHj70fU8/80q7vAQsApFSfSN X-Google-Smtp-Source: AA6agR7j3rxZTAcI1RLEbstOK15RhYbERbl1LNVRnXmwAEPoWdhb5xt0UAVIDSsLZV45TztSNWf11L/SRs3rchmuA/I= X-Received: by 2002:a05:6512:c04:b0:494:7e65:7c70 with SMTP id z4-20020a0565120c0400b004947e657c70mr10524673lfu.612.1662394029015; Mon, 05 Sep 2022 09:07:09 -0700 (PDT) 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 Received: by 2002:a05:6520:14d:b0:211:6cae:be17 with HTTP; Mon, 5 Sep 2022 09:07:08 -0700 (PDT) In-Reply-To: References: <202209051156.285BuFWK076782@gitrepo.freebsd.org> From: Mateusz Guzik Date: Mon, 5 Sep 2022 18:07:08 +0200 Message-ID: Subject: Re: git: 69413598d266 - main - signal: use proc_iterate to save on work To: Konstantin Belousov Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Rspamd-Queue-Id: 4MLtgy5wjBz42ty X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On 9/5/22, Konstantin Belousov wrote: > On Mon, Sep 05, 2022 at 11:56:15AM +0000, Mateusz Guzik wrote: >> 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) > Extra () > >> + 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) { > > I believe before your change, kill(-1) would kill all processes in the > jail, which includes all processes in the nested jails. Now, it seems > that linkage prevents iterating over the nested jails, am I missing it? > See the pr_childcount check. If any jails pop up, there is a full scan like right now. And if the count transitions 0 -> 1 -> 0 during the iteration of the loop, there is nobody left to signal. All previously existing races remain unaffected. -- Mateusz Guzik