Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3439777imu; Sun, 11 Nov 2018 15:08:10 -0800 (PST) X-Google-Smtp-Source: AJdET5eZ/4OIbcNk+X4Sn0TSGI0kzBKPUNpwfSDM93q8eoKVZ8o3xjSm918aRJumI554JWwKoywN X-Received: by 2002:a17:902:bb83:: with SMTP id m3-v6mr707768pls.144.1541977690039; Sun, 11 Nov 2018 15:08:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977690; cv=none; d=google.com; s=arc-20160816; b=WkPEuoo1nsxNihJPy5Ios1vpSlMA9rW9SPIzYS56PxOX7X+uirPV4Oy+83lhp+xmv+ ZFARSCY7GjJl7K50sKYxxrkxgisvrCS7JpZqpTfyWw9PXs48+ISiRus7CsXj7Iv7mc9Q s3fGguiHLwyKzmabhT+cZ9p2MchiwEqPoS0G6hWAAcwhVTd8M+xsDt6MGeSBe0S4dDD3 WvAzdJRnqO61d+K8kdA4dX1Mlzq2O5XlW/7GdyebN1n/NQ0KYlJfl5abc3ZkHSTv0JKA 2sU5gpIh4bW8vlgYJLF5ypiZeqEZY3YLVCdkBsFiXK7rqhlnn+3zZp5i8cmCDeksNiXs 6EVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+PN4ORUVZvbIfM+mWmZlvevicPT7IqFpgNo0X3PIpoA=; b=AehPWZGNKtAIoRrwJlnsd89e+Y+WOtKn1fj7jvJKcgLWhHpIa98nTf52CLHelbfyLU yNLIG8fPvXwVnLSohg0ltr3K9l/jbJsnPFOHnXsK6zAXpn8aD2HL3vA996/iJT3GvQ3C uKR+MDtPYDqSkIFL573T45pB+JQbZ/JDCy0vzLiB/QhI297/ZDrdAM2m9m2Z5/i0itvk frB1m4L8Drp8IP7JXDAyMzVbPw66TVH2W7crUz0UMghJuevfzNU9vw/Spn5qyW0OUU/d D08VLMHLktop6SXKjnlAZGn+CjWKDKGLhDjLvB2Z8F3PMMGGwI3CQyZtMCrjspS6bxZK mOiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CMi078bs; 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 e39-v6si15485778plg.366.2018.11.11.15.07.55; Sun, 11 Nov 2018 15:08:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=CMi078bs; 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 S2390305AbeKLIWJ (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:51232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390276AbeKLIWI (ORCPT ); Mon, 12 Nov 2018 03:22:08 -0500 Received: from localhost (unknown [206.108.79.134]) (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 DC9352241E; Sun, 11 Nov 2018 22:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975530; bh=bZjBCr2byS1GUHy2AvAwRp32O49qr+E3PuaJQch557g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMi078bsAR79QOKbbUqXkqZgHNXxhIOVdWvl8wOubt7f/GqxMt/1BaNC93UTnO3NQ OyL+uUjEam/GSreQlpjO+hsl+dew3Ok43KuORjV0MKUYo2RhAzhncUOh5c0WU7rcoj NY2C7THAffm90h6aDsB8mmtfLuO8R+xHaHARBYS8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Andrew Morton , Linus Torvalds , "Paul E. McKenney" , Peter Zijlstra , Thomas Gleixner , Will Deacon , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 039/222] locking/lockdep: Fix debug_locks off performance problem Date: Sun, 11 Nov 2018 14:22:16 -0800 Message-Id: <20181111221651.679122759@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- kernel/locking/lockdep.c | 4 ++-- lib/debug_locks.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -4215,7 +4215,7 @@ void lock_contended(struct lockdep_map * { unsigned long flags; - if (unlikely(!lock_stat)) + if (unlikely(!lock_stat || !debug_locks)) return; if (unlikely(current->lockdep_recursion)) @@ -4235,7 +4235,7 @@ void lock_acquired(struct lockdep_map *l { unsigned long flags; - if (unlikely(!lock_stat)) + if (unlikely(!lock_stat || !debug_locks)) return; if (unlikely(current->lockdep_recursion)) --- 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;