From owner-svn-src-head@freebsd.org Mon Oct 5 19:35:56 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 058AB42E281; Mon, 5 Oct 2020 19:35:56 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C4rRt6rrxz4PtY; Mon, 5 Oct 2020 19:35:54 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm1-x341.google.com with SMTP id e2so710780wme.1; Mon, 05 Oct 2020 12:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TR3xq2GtggHSdOO4TnUu85QEXUnEasNf3WMFvNpQBLM=; b=q6S/R1jcaR4KcHTLP8OfTqGd4UeZLF8C9z4cwWY6YUnrxhR3nOCOqIRRDvosalqkvk 1lZg1uwlen3On9UbK5jHBc/7hnOeiJ1vRu9rBa3A0k7zygvIn/MS0pzuaK/JB1jhDdTR 38npj1M8sEVUwC/dKpR+MGJewNqhmP8kUaogVVoiSJjNiKNCRVihVsDtXjyDPuZBbaBj +q0uzLh7c2lWVQq5YFSTohJld5ul2uFBuMnZZi5lc7BFbNTfQO3HHiiyaqKiZiSbPUpB AGuwGK+cHRCTikCZzXd+8Cv0wk8BKqv78KDvjdzI/D+Dj3VIrQg4/WgkbwXU8j7RqK4r c/eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TR3xq2GtggHSdOO4TnUu85QEXUnEasNf3WMFvNpQBLM=; b=FpLZJ/ThpKLuD5Ff2R13IAmUnOIgsRbONOHcwoS/K0dxFlHDLCX+lcamIUALfQFZu9 bcW0ArokIhVlqEBcRVImjCWvOsS8uBKANwW+OHGb7AYVx7UkAOoNnj5K/8l/pN2CrbeJ DrYLnXZNNfPJDSoV91OekuxFxuBMn3zSasCCN+YN08fcWYHFXHQz79S3yU3zqua3dsqk PqsF5Mcay4L6lytnodqRu9e8hAMg1icN2UKlxF/LbDbXJYY0pPFIN45BGW4EcTSfHvGp 4JIwT8MxymwOjEiWfwiYEiTMk2JTnXSJWMQ2nTOvVA3yLK3TXtvCZdFgtbgCqe74PqBg Zf+w== X-Gm-Message-State: AOAM531ky+6JsUgwgj4sKaIM8AkZ+ptfzfRHIfKtHsz0XNJoZgmzmth9 ITvShiIE9MOAtDJIfBvHYsRYK/6Zs8mdwK+0rRk= X-Google-Smtp-Source: ABdhPJy1ra/8/1a0sPEC61i8Iqc53A87YWyflo5IFKho+BLQ1nPLf3CqvkrIbd2MTdQrdMxfYkMpIJYI5t83azxCPq4= X-Received: by 2002:a1c:98d4:: with SMTP id a203mr963282wme.83.1601926552727; Mon, 05 Oct 2020 12:35:52 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6000:187:0:0:0:0 with HTTP; Mon, 5 Oct 2020 12:35:51 -0700 (PDT) In-Reply-To: <20201005011833.GI2643@kib.kiev.ua> References: <202010041633.094GXg4l044462@repo.freebsd.org> <20201005011833.GI2643@kib.kiev.ua> From: Mateusz Guzik Date: Mon, 5 Oct 2020 21:35:51 +0200 Message-ID: Subject: Re: svn commit: r366429 - in head/sys: kern sys To: Konstantin Belousov Cc: Rick Macklem , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4C4rRt6rrxz4PtY X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=q6S/R1jc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of mjguzik@gmail.com designates 2a00:1450:4864:20::341 as permitted sender) smtp.mailfrom=mjguzik@gmail.com X-Spamd-Result: default: False [-2.55 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(0.46)[0.464]; NEURAL_HAM_LONG(-1.02)[-1.016]; RCPT_COUNT_FIVE(0.00)[5]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::341:from]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[svn-src-all,svn-src-head]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2020 19:35:56 -0000 On 10/5/20, Konstantin Belousov wrote: > On Sun, Oct 04, 2020 at 09:06:02PM +0000, Rick Macklem wrote: >> Mateusz Guzik wrote: >> >Why is the process lock always taken? It looks like both routines just >> >check a thread-local flag, so perhaps this can get away without >> >serializing this process-wide? >> I did spot this slight difference between the initial version of >> sig_intr() and >> this one. At least w.r.t. copy_file_range(2), the call happens >> infrequently >> enough that the overhead of acquiring the lock is not significant. >> > Yes, the function should not be on any frequent path. > > That said, all signal delivery to process is covered by the process lock, > so checks under process lock make the advisory answer provide less false > negatives. If considered too importand in some cases (when ?), the > following > patch can be applied. > > diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c > index 8108d4cb3a5..ed4dd52b66d 100644 > --- a/sys/kern/kern_sig.c > +++ b/sys/kern/kern_sig.c > @@ -3212,6 +3212,9 @@ sig_intr(void) > int ret; > > td = curthread; > + if ((td->td_flags & (TDF_NEEDSIGCHK | TDF_NEEDSUSPCHK)) == 0) > + return (0); > + > p = td->td_proc; > > PROC_LOCK(p); > I presume copy_file_range will not be the only consumer going forward. The default for all new code should be to avoid locks or other atomics if it can be helped, otherwise it's just never ending whack-a-mole and this is bound to become a bottleneck at some point. So happens process lock is already quite contended (e.g., when running poudriere) and adding to it is the wrong way to go. -- Mateusz Guzik