Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3133739ybv; Mon, 24 Feb 2020 18:59:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxSKDNY1ZRwS8hr58MF/LuYxwIpjtAhs5y9O1JrhZIKjGilhOC5SiSqFF96e5zca7fJykkK X-Received: by 2002:aca:1704:: with SMTP id j4mr1692165oii.12.1582599559704; Mon, 24 Feb 2020 18:59:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582599559; cv=none; d=google.com; s=arc-20160816; b=sKpU6uNdODhKRu82JUwTGpoFQvCI1K33MWuy0u54BMdHYdWP80s27/SYdQf24BJFuM d5yVlj+43YjOaOlI+1nw149q4hEUezx4Q2esUgpPnJUnI2oFqZdegh5v4C0PbFboMXcU xRQH4x5g/hpnCk1p2nTxcl56h9EcQG/h0VGf2/4tEdd/JCCZWgwQGE1eDQwOTPZnKjfy cAHULfhEJs8ssSL0yH0EE9n6CPOeavbuVp3OYWst1oWJVWwB+Ske7gPbPpmVldMr+j+a NRFFliqfClBnFved5b5G73DuMoHGrdLRiyHW/2LTi8ChF9EaRbbwEFwLaNNz6POFCvBd nh+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JB3hSa44ln/kC8OS0UEyXTZbelH0h09YXYbk5Xyw82A=; b=stjo4WkeNJc0DieKxxMAsArBK5eEa906zXR78QC+cf8w/RGjXkCOiivnbrIcgti1F7 5bW7z3wjVSuAC+lrALfw957v3MS1/0Jh5reyVneSjuIfEWq48N1Rkv+Bx/znT6jrd2oK xIxmU5jGG2ZLyH/wJ8ejHeAPn+0DrCluB9NYXXHZiFGF2LwOVrYkB1YEPB+2FWN7olCL L36zXBi9JYJ6iigFNvntuTWZfpAIjnje9b6ZEZUtwAe5iP/VaLp9U1cE/cubmLd6PQta zBke5UGJLj1WxybV6WnOtgkJUR3/56yEngOowWVOXTW6QAhC4f2kYt1qbOD2Co2oHxUD tyoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si7512428otc.272.2020.02.24.18.59.06; Mon, 24 Feb 2020 18:59:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728843AbgBYC5y (ORCPT + 99 others); Mon, 24 Feb 2020 21:57:54 -0500 Received: from mga06.intel.com ([134.134.136.31]:39452 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgBYC5y (ORCPT ); Mon, 24 Feb 2020 21:57:54 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 18:57:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,482,1574150400"; d="scan'208";a="230023010" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.147.113]) by fmsmga007.fm.intel.com with ESMTP; 24 Feb 2020 18:57:48 -0800 Date: Tue, 25 Feb 2020 10:57:48 +0800 From: Feng Tang To: Linus Torvalds Cc: Oleg Nesterov , "Eric W. Biederman" , Jiri Olsa , Peter Zijlstra , kernel test robot , Ingo Molnar , Vince Weaver , Jiri Olsa , Alexander Shishkin , Arnaldo Carvalho de Melo , Arnaldo Carvalho de Melo , "Naveen N. Rao" , Ravi Bangoria , Stephane Eranian , Thomas Gleixner , LKML , lkp@lists.01.org, andi.kleen@intel.com, "Huang, Ying" Subject: Re: [LKP] Re: [perf/x86] 81ec3f3c4c: will-it-scale.per_process_ops -5.5% regression Message-ID: <20200225025748.GB63065@shbuild999.sh.intel.com> References: <20200221080325.GA67807@shbuild999.sh.intel.com> <20200221132048.GE652992@krava> <20200223141147.GA53531@shbuild999.sh.intel.com> <20200224003301.GA5061@shbuild999.sh.intel.com> <20200224021915.GC5061@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 24, 2020 at 12:47:14PM -0800, Linus Torvalds wrote: > [ Adding a few more people that tend to be involved in signal > handling. Just in case - even if they probably don't care ] > > On Mon, Feb 24, 2020 at 12:09 PM Linus Torvalds > > I've tested it, and the profiles on the silly microbenchmark look much > nicer. Now it's just the sigpending update shows up, the refcount case > clearly still occasionally happens, but it's now in the noise. > > I made slight changes to the __sigqueue_alloc() case to generate > better code: since we now use that atomic_inc_return() anyway, we > might as well then use the value that is returned for the > RLIMIT_SIGPENDING check too, instead of reading it again. > > That might avoid another potential cacheline bounce, plus the > generated code just looks better. > > Updated (and now slightly tested!) patch attached. > It would be interesting if this is noticeable on your benchmark > numbers. I didn't actually _time_ anything, I just looked at profiles. > > But my setup clearly isn't going to see the horrible contention case > anyway, so my timing numbers wouldn't be all that interesting. Thanks for the optimization patch for signal! It makes a big difference, that the performance score is tripled! bump from original 17000 to 54000. Also the gap between 5.0-rc6 and 5.0-rc6+Jiri's patch is reduced to around 2%. The test I run is inserting your patch right before 5.0-rc6, then run the test for 5.0-rc6 and 5.0-rc6+Jiri's patch. Sorry it took quite some time, as the test platform is not local but inside 0day's framework, which takes some time for scheduling, kbuilding and testing. Thanks, Feng > Linus > kernel/signal.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/kernel/signal.c b/kernel/signal.c > index 9ad8dea93dbb..5b2396350dd1 100644 > --- a/kernel/signal.c > +++ b/kernel/signal.c > @@ -413,27 +413,32 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi > { > struct sigqueue *q = NULL; > struct user_struct *user; > + int sigpending; > > /* > * Protect access to @t credentials. This can go away when all > * callers hold rcu read lock. > + * > + * NOTE! A pending signal will hold on to the user refcount, > + * and we get/put the refcount only when the sigpending count > + * changes from/to zero. > */ > rcu_read_lock(); > - user = get_uid(__task_cred(t)->user); > - atomic_inc(&user->sigpending); > + user = __task_cred(t)->user; > + sigpending = atomic_inc_return(&user->sigpending); > + if (sigpending == 1) > + get_uid(user); > rcu_read_unlock(); > > - if (override_rlimit || > - atomic_read(&user->sigpending) <= > - task_rlimit(t, RLIMIT_SIGPENDING)) { > + if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) { > q = kmem_cache_alloc(sigqueue_cachep, flags); > } else { > print_dropped_signal(sig); > } > > if (unlikely(q == NULL)) { > - atomic_dec(&user->sigpending); > - free_uid(user); > + if (atomic_dec_and_test(&user->sigpending)) > + free_uid(user); > } else { > INIT_LIST_HEAD(&q->list); > q->flags = 0; > @@ -447,8 +452,8 @@ static void __sigqueue_free(struct sigqueue *q) > { > if (q->flags & SIGQUEUE_PREALLOC) > return; > - atomic_dec(&q->user->sigpending); > - free_uid(q->user); > + if (atomic_dec_and_test(&q->user->sigpending)) > + free_uid(q->user); > kmem_cache_free(sigqueue_cachep, q); > } >