From nobody Wed Sep 7 09:36:03 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 4MMxvp34wPz4c2q6; Wed, 7 Sep 2022 09:36:06 +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 4MMxvp26gyz4JfW; Wed, 7 Sep 2022 09:36:06 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-lf1-x12b.google.com with SMTP id m15so1848043lfl.9; Wed, 07 Sep 2022 02:36:06 -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=591eeg31qkkTh1YpCI0xycI1QM8VENBZroo8CIk3Dtc=; b=e1NYhBkpF9jCE/kty2wqpABgKpiui//c6J58kY78zvnV82RVFQ+KtNQUJEW57cel44 Rsxoq0ZsI3MvPNxAwa/8sNnzsoRtaFDqFxRah6US3sF+YLmmdX7eGKSsPknBYL5sB2eL 5rVzZov4MpCeYaeug9AtGlrFcDoD2CsxyiHeIwpa6YhSRIcC5AddQxxRJ1U6Cb/k4ZpL pFKMM6JbSLHLCyNUhg9OkOLUPHyZFj7gO9Fg+d2D+8S/6soUoPOSWnJqyCjbvF8MzxMe 3YQg2Kw1+GorLh8ZQslNpy1tXQdStHLk7B0nuWprvN4En7H1cwgdSX2M6o2cBL4kpxB/ Ug9A== 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=591eeg31qkkTh1YpCI0xycI1QM8VENBZroo8CIk3Dtc=; b=IlMHE2QA1bKwxEljej7PU5HuAxOY2oyMY/olnw24Y6SwHbmjtQr3QNgeQ3h45YUpFR t/c6DNkMMP+LonqlFsqhNolxelGqvrRf9w5gIG3BcoNnW77CQYqgWmG8gDIFbSUJ4nzR 9p+maYmQNW2DkpPmkhIHEyOf1Ql7N8u7J1t77cXEMX07FnxaXfC0GcRmf377YjpoEOPo vExPO7efLDSvPCTEZn/hZ804u76kcIVDl+Aodto7XoquVw96cUIU6uOQqH4m+GRqHL1i RJcvId6/AV7JIQy1K6Vz8kkrsTAri8q5VTDzZfY88o5shiqGZO/2PlOhVqgv2XyNfaAq 8H/w== X-Gm-Message-State: ACgBeo0GTiDnlwX1KmoCqy3bet/ZVRzvnXkNQuzV0imNlDjS/J3+FJ0c kYBxpA4GPUdeXPXPynnF1EtOf55zILp4ue3dYaeXAhgQ X-Google-Smtp-Source: AA6agR53T9mYtwE0MfsvlbJZcSJtmdjveIMviAdzoNoNtcHJMfJ3LwfH6IrPo9VGZDxizHM1LkPnpC14SnuB3hz0jRk= X-Received: by 2002:a05:6512:3fa7:b0:497:369b:47db with SMTP id x39-20020a0565123fa700b00497369b47dbmr780950lfa.657.1662543364492; Wed, 07 Sep 2022 02:36:04 -0700 (PDT) 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 Received: by 2002:a05:6520:14d:b0:211:6cae:be17 with HTTP; Wed, 7 Sep 2022 02:36:03 -0700 (PDT) In-Reply-To: References: <202209051156.285BuFWK076782@gitrepo.freebsd.org> From: Mateusz Guzik Date: Wed, 7 Sep 2022 11:36:03 +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: 4MMxvp26gyz4JfW 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/7/22, Konstantin Belousov wrote: > On Mon, Sep 05, 2022 at 06:07:08PM +0200, Mateusz Guzik wrote: >> 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. > I see. > >> >> All previously existing races remain unaffected. > No, now you are potentially signalling some processes more than once. > Sending the signal is not idempotent operation. > You have a point, I was pretty fixated on just kill -9 -1. I'm going going to have to ponder a little bit, perhaps it is time to finally fix the races. -- Mateusz Guzik