Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp179298imd; Wed, 31 Oct 2018 16:55:29 -0700 (PDT) X-Google-Smtp-Source: AJdET5eXgN+Ge656RF5k0ezSbZdWNzlX9oyU3jbHmf8uVwDmy8CP/CRyOZx+e5EZPfnt/2Dsv68U X-Received: by 2002:a17:902:144:: with SMTP id 62-v6mr5248012plb.142.1541030129057; Wed, 31 Oct 2018 16:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030129; cv=none; d=google.com; s=arc-20160816; b=i1L6P+58CMR20Wy8wGHVwfLX/hL+3gQooQFGTlfslzfYIRdn8D0AR/IvQpGVidVfor kdy/401wG+7hZg2t45DCF97ZJFwrAo/KyWIqO2cJqzCiTVWcxlgzQRcC3l3ovjqScTVh 8ukD09dnVvCGSYyvfK0vZ3zrlZP24nEos1dA+Gb+Ac4ffDERaU/fit8zhHAJHxKy5Ff+ bqaEgP1KAzZA9tXU9vypgU40xJGpgl/h3D47Baa3jPUkWT8w500zuDndo2CHAsMboGss h4UBmx1YjqXwQo7YCPBAkp92R/RexseRMmOunlre5jVmxCTW+pfgMveEt/IdVdRy9uFm F1nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=/TH5dKBLtF+QN5cyXS9x7eGqwr+B/w2zdyx8dDXhLtk=; b=qu19t8gmIPAZEwb1NM+hTpuYH+w8OXSJ/Ql1+mX83nnC+95mribQJLoa6n6ROGkz8D Bhlypc+an1fU82Aa8h7cIHE5bLy8OJSXM1jEasRc6ksjCm3Pn20Zd3r5LfBBNvuxf1cE ulG8OzGdD01jC/gtu+tHi5Lp5exrlC4b/FaKBbv10OKiTxBUFGNzLSe9Ctqbezz3od13 /slvyGgE2EdChKsv7WkcN6WxsFRfGYrN2+pL73u0IaYYhzFJmbqdTaLb4zvoR0rrFc2s RJXUlhSaR3/dlq/ILyx7FLKZirl4d3OLSeNV0HkTGWaz4KSJ3l2EME+LO91vlnIIM3K6 bOzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rpUmOUk2; 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 j193si8303626pge.332.2018.10.31.16.55.14; Wed, 31 Oct 2018 16:55:29 -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=rpUmOUk2; 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 S1726693AbeKAIF6 (ORCPT + 99 others); Thu, 1 Nov 2018 04:05:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:52556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbeKAIF6 (ORCPT ); Thu, 1 Nov 2018 04:05:58 -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 D039A20830; Wed, 31 Oct 2018 23:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027146; bh=sxPiJ37QJMlphcA2WATCxoPZlszE6fz5E1pgQkBPxlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rpUmOUk2aEmSGKsN7/VQ8LuGTYsMnhQjQ3WBGDtbcliSnzRiCqrska3qMTaGPHwYp FbYmNbeF8MtfU6MLqwVVFbyl0wvWuUVP0mATz+IKhWzn8zfcb3T6VuBgLwXT7qdK9K paC//liARSCF87gEo3Xgae9ttRnsGiaS34xOKLog= 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.19 004/146] locking/lockdep: Fix debug_locks off performance problem Date: Wed, 31 Oct 2018 19:03:19 -0400 Message-Id: <20181031230541.28822-4-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> 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 dd13f865ad40..26b57e24476f 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -4122,7 +4122,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)) @@ -4142,7 +4142,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