The patch titled Subject: signals: avoid unnecessary taking of sighand->siglock has been added to the -mm tree. Its filename is signals-avoid-unnecessary-taking-of-sighand-siglock.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/signals-avoid-unnecessary-taking-of-sighand-siglock.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/signals-avoid-unnecessary-taking-of-sighand-siglock.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Waiman Long <Waiman.Long@xxxxxxx> Subject: signals: avoid unnecessary taking of sighand->siglock 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@xxxxxxx Signed-off-by: Waiman Long <Waiman.Long@xxxxxxx> Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Stas Sergeev <stsp@xxxxxxx> Cc: Scott J Norton <scott.norton@xxxxxxx> Cc: Douglas Hatch <doug.hatch@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/signal.h | 17 +++++++++++++++++ kernel/signal.c | 7 +++++++ 2 files changed, 24 insertions(+) diff -puN include/linux/signal.h~signals-avoid-unnecessary-taking-of-sighand-siglock include/linux/signal.h --- a/include/linux/signal.h~signals-avoid-unnecessary-taking-of-sighand-siglock +++ a/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 diff -puN kernel/signal.c~signals-avoid-unnecessary-taking-of-sighand-siglock kernel/signal.c --- a/kernel/signal.c~signals-avoid-unnecessary-taking-of-sighand-siglock +++ a/kernel/signal.c @@ -2485,6 +2485,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); _ Patches currently in -mm which might be from Waiman.Long@xxxxxxx are signals-avoid-unnecessary-taking-of-sighand-siglock.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html