Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp150401imd; Wed, 31 Oct 2018 16:19:44 -0700 (PDT) X-Google-Smtp-Source: AJdET5cActgl54t+U7B5AVsUpK4sLHZi/uWgIC2AD8VF8Oi4ypAeyYQfFYvzm0dGLUCyS/WkYoYP X-Received: by 2002:a65:55ca:: with SMTP id k10mr4927039pgs.448.1541027984732; Wed, 31 Oct 2018 16:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027984; cv=none; d=google.com; s=arc-20160816; b=getxqvMI0e2S7WrBypVNrPVpa3zll7qZbpli2lMzflsNKALLXW7PamDsMlwwBhofew 1LXH/HnLg+m73Clp+uPzaeoC+q61hRFcJLU7JSO76eN/iNyEgfiFJ/j5tFeTjqjpbnvk ZbmZYJ23iDfJk+V+xukNwB+nldbfZiMdUSQvKloiJ00+bGu5He1EPUYE3noNa7bmUAqw qmhynTWpAtduj3tgF9qJ6SZg5ejPCYaozSKvKyhZEav5uIa6QdbU0HZNNOpCdC07IkyJ cLCgLX76OxDR3bsIV1frelZaaNE5QfjEK+qjXGPN8IRBBNzYvahom5qZAVdVVvnAE5Ms Z3Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=TPirMNGMLdfhi1GjaY6wXMkdUQEpPNE8qRx8ou10dRI=; b=feAjGXGuN9Sb9eEWbD/NEq57B6Y5YdSExvmh6Tk2Jvk5q4r75FPN0w9AoE3LV/Bpbo zqVu1nCXkaKdbgFoBG3BDHfvYbG7Y+A9Ii41GdSa1clv4JxGruaL3nxuTvgUvov24dzF 5GqYsKWFamXEW8IIrp7sVcE8Nr+/hIi8F7EkFhxifHd2rN7qwgXogiGKFQfo/bYPCXkA wHUnRC1ETlz3h+lzR+5+zU/7gQPYGoyFpUDyD0YMbcKzXzpCeqGY8crPMESvWYtHLrSd yShua+LKeyhhLF8YWS/0G45Qkke536qffkNlcSGCDJ1D32HQTxlKojyg51aiZrmwUNSv AxsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=co3j0Y5E; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v66-v6si24489643pgv.289.2018.10.31.16.19.30; Wed, 31 Oct 2018 16:19:44 -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=co3j0Y5E; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731896AbeKAILx (ORCPT + 99 others); Thu, 1 Nov 2018 04:11:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:36010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729986AbeKAILw (ORCPT ); Thu, 1 Nov 2018 04:11:52 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 457F82081B; Wed, 31 Oct 2018 23:11:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027499; bh=RxKFeqp2nE39RpNCWxY0//3LE+aMGvDdSyUl0552jQQ=; h=From:To:Cc:Subject:Date:From; b=co3j0Y5EmHWsk7rkyahc0yMpy2NcQ13M4wadnleyFeAQBV3H6ZzGl0K1/RJ98T3A8 jl6x1ZmuTSJoz6tKyuGzQ7TOCiznjCVNUPgck8LoxVT8rlzTe0ZLvVc5ZvfwLvNqiY HnjXew2F+UZmIVaOxmzPKT3CTx8NCoLKhJIPjryA= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Waiman Long , Andrew Morton , Linus Torvalds , "Paul E . McKenney" , Peter Zijlstra , Thomas Gleixner , Will Deacon , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL 4.4 01/32] locking/lockdep: Fix debug_locks off performance problem Date: Wed, 31 Oct 2018 19:11:06 -0400 Message-Id: <20181031231137.29429-1-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long [ Upstream commit 9506a7425b094d2f1d9c877ed5a78f416669269b ] It was found that when debug_locks was turned off because of a problem found by the lockdep code, the system performance could drop quite significantly when the lock_stat code was also configured into the kernel. For instance, parallel kernel build time on a 4-socket x86-64 server nearly doubled. Further analysis into the cause of the slowdown traced back to the frequent call to debug_locks_off() from the __lock_acquired() function probably due to some inconsistent lockdep states with debug_locks off. The debug_locks_off() function did an unconditional atomic xchg to write a 0 value into debug_locks which had already been set to 0. This led to severe cacheline contention in the cacheline that held debug_locks. As debug_locks is being referenced in quite a few different places in the kernel, this greatly slow down the system performance. To prevent that trashing of debug_locks cacheline, lock_acquired() and lock_contended() now checks the state of debug_locks before proceeding. The debug_locks_off() function is also modified to check debug_locks before calling __debug_locks_off(). Signed-off-by: Waiman Long Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Link: http://lkml.kernel.org/r/1539913518-15598-1-git-send-email-longman@redhat.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/lockdep.c | 4 ++-- lib/debug_locks.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 6e171b547a80..774ab79d3ec7 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3826,7 +3826,7 @@ void lock_contended(struct lockdep_map *lock, unsigned long ip) { unsigned long flags; - if (unlikely(!lock_stat)) + if (unlikely(!lock_stat || !debug_locks)) return; if (unlikely(current->lockdep_recursion)) @@ -3846,7 +3846,7 @@ void lock_acquired(struct lockdep_map *lock, unsigned long ip) { unsigned long flags; - if (unlikely(!lock_stat)) + if (unlikely(!lock_stat || !debug_locks)) return; if (unlikely(current->lockdep_recursion)) diff --git a/lib/debug_locks.c b/lib/debug_locks.c index 96c4c633d95e..124fdf238b3d 100644 --- a/lib/debug_locks.c +++ b/lib/debug_locks.c @@ -37,7 +37,7 @@ EXPORT_SYMBOL_GPL(debug_locks_silent); */ int debug_locks_off(void) { - if (__debug_locks_off()) { + if (debug_locks && __debug_locks_off()) { if (!debug_locks_silent) { console_verbose(); return 1; -- 2.17.1