Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2035724imm; Thu, 24 May 2018 04:54:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqSW4tqGpzifqCaOBl/NfC6s3nCxkbTBNbNj+evmT3eQNIt9WTgNDoF+gz/O96iiG6FJKLc X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr7075362plt.126.1527162883967; Thu, 24 May 2018 04:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527162883; cv=none; d=google.com; s=arc-20160816; b=oXRlSKaEiT+QOSFErqto/xPVIE5XKoMBLHgFKOVAOXPH8ms6E9rZH9njemXAcUlyHp PRqInPF355kp9267yyJ9AHGXeEv9OUB6miGqqMw8EbyopxjeuB0yCdX5c1qTM7PhzlmQ z6DmQ0qMDlhki0Cuv3Ql9jCwZaGxZHIWfTuR9eDDHEGd620iRdcRM9vjtzAS5iTh2D/0 Tx5XDP5nfT5Xvsdr48RkpkGC1R78jMpeF5btchMOyXd8jTqHoa5CrTmZ6fL1u6wz2vXw 8HnR7ikikUE5ZnMvpaADuzJFExkTXhRo/hUEe2KrFNkF1LlRwdYzSqRerD/wu8i31cKX K0kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=LJvEztUub5WfoG15eQ3fdL+9Ny/kIxItWy3FncFsPJU=; b=B7nAXDoWjm8KN4xsfW4BXiQLcLDhTtpXl/9kkQjC1gzU8RCA6gDEvp7SY4iA0goFn9 /Ws6tUcXThaYWjtkUetNvfAb7RC2EGuSatJ8zYUz+IuRL2dlDv5Ms3Jy3y7B6jdVXiKA SPsoNaeG3Ece7TipG2Im8oUHINMODZlXZYvMwt3/2Uc0DGcm91sHpn35V7nMNZwY/016 ZTf8mLlaIoMFObCJJfKJq5trZC0oNw0kavKwtxuDaCr2wZJOekBriyRkWMcsE1t8dd8y 7Vs2uXkTu07s8CDzBIBxYAHs68bVnYqz/O8Aa61dfuCXEQHe3eeliKVGqxJvtGCAl7py wmug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZCoPQRXw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si21303960pll.123.2018.05.24.04.54.29; Thu, 24 May 2018 04:54:43 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ZCoPQRXw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969393AbeEXLxi (ORCPT + 99 others); Thu, 24 May 2018 07:53:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:57540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966903AbeEXJqV (ORCPT ); Thu, 24 May 2018 05:46:21 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D25D20892; Thu, 24 May 2018 09:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155180; bh=7KFgUTCit3oV8BDliZONE2SprRrC1frNJWiS0dTASEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZCoPQRXw+EmxW3HwyI6CJ3T6rzQNbsiEfgPDUb25MNkIT+Mvwu2J5toFb3o9OYKOh E7j1cr6CoFmJvVgPCsvFYZ3Vzc0XMBZ3b6U2wQ3qtz3nM8300/CZKAmU2S8XkYZ0XF 2aSvJaPkxp/d4ph7QKdcXk8eiDKMF9vdrzt0NNxc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Oleg Nesterov , Ingo Molnar , Thomas Gleixner , Stas Sergeev , Scott J Norton , Douglas Hatch , Andrew Morton , Linus Torvalds , Mel Gorman Subject: [PATCH 4.4 51/92] signals: avoid unnecessary taking of sighand->siglock Date: Thu, 24 May 2018 11:38:28 +0200 Message-Id: <20180524093204.323977661@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Waiman Long commit c7be96af89d4b53211862d8599b2430e8900ed92 upstream. When running certain database workload on a high-end system with many CPUs, it was found that spinlock contention in the sigprocmask syscalls became a significant portion of the overall CPU cycles as shown below. 9.30% 9.30% 905387 dataserver /proc/kcore 0x7fff8163f4d2 [k] _raw_spin_lock_irq | ---_raw_spin_lock_irq | |--99.34%-- __set_current_blocked | sigprocmask | sys_rt_sigprocmask | system_call_fastpath | | | |--50.63%-- __swapcontext | | | | | |--99.91%-- upsleepgeneric | | | |--49.36%-- __setcontext | | ktskRun Looking further into the swapcontext function in glibc, it was found that the function always call sigprocmask() without checking if there are changes in the signal mask. A check was added to the __set_current_blocked() function to avoid taking the sighand->siglock spinlock if there is no change in the signal mask. This will prevent unneeded spinlock contention when many threads are trying to call sigprocmask(). With this patch applied, the spinlock contention in sigprocmask() was gone. Link: http://lkml.kernel.org/r/1474979209-11867-1-git-send-email-Waiman.Long@hpe.com Signed-off-by: Waiman Long Acked-by: Oleg Nesterov Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Stas Sergeev Cc: Scott J Norton Cc: Douglas Hatch Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Mel Gorman Signed-off-by: Greg Kroah-Hartman --- include/linux/signal.h | 17 +++++++++++++++++ kernel/signal.c | 7 +++++++ 2 files changed, 24 insertions(+) --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -97,6 +97,23 @@ static inline int sigisemptyset(sigset_t } } +static inline int sigequalsets(const sigset_t *set1, const sigset_t *set2) +{ + switch (_NSIG_WORDS) { + case 4: + return (set1->sig[3] == set2->sig[3]) && + (set1->sig[2] == set2->sig[2]) && + (set1->sig[1] == set2->sig[1]) && + (set1->sig[0] == set2->sig[0]); + case 2: + return (set1->sig[1] == set2->sig[1]) && + (set1->sig[0] == set2->sig[0]); + case 1: + return set1->sig[0] == set2->sig[0]; + } + return 0; +} + #define sigmask(sig) (1UL << ((sig) - 1)) #ifndef __HAVE_ARCH_SIG_SETOPS --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2495,6 +2495,13 @@ void __set_current_blocked(const sigset_ { struct task_struct *tsk = current; + /* + * In case the signal mask hasn't changed, there is nothing we need + * to do. The current->blocked shouldn't be modified by other task. + */ + if (sigequalsets(&tsk->blocked, newset)) + return; + spin_lock_irq(&tsk->sighand->siglock); __set_task_blocked(tsk, newset); spin_unlock_irq(&tsk->sighand->siglock);