Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3490716imu; Sun, 11 Nov 2018 16:17:16 -0800 (PST) X-Google-Smtp-Source: AJdET5fsHnS/6RvpcgyhINfbYoGQL8m2RlOkaWHa58IdGb+hj/Uxl8TxgMIiikk5lcB6FF6IWvpY X-Received: by 2002:a17:902:a81:: with SMTP id 1-v6mr3167483plp.20.1541981836372; Sun, 11 Nov 2018 16:17:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981836; cv=none; d=google.com; s=arc-20160816; b=VCbqbEeEghALWtbFJSANsM1TIkd+0T4lDnZHNz5hIcjxy+dnU57Nw4A6Y2nNWP/dMf yNedeETR1IpwLibAfKEpaM6ubNYASuBOtHAqXMc8Al3iZvS4B/AP2xqSi2W9ZAINpuMd 7Lk1jpXMmUmEksKByT968EBzuIv7BCN52iYaS9BpBL0MnMuWrGyOx9VPlAzAklPMTgPv sGedJZOPfJ3rz1/jUqI7xnFs+DlJHn7p4hI9LekKQdrVz0kPN//PzDy6sPzXRnRKwo6/ cdDcfHFfAgjjxpde1KWGpLNp/VcJgv0gD6SAbYodvKFqy5m1L1j/yuIgoA1hMNF1jtaO VMbw== 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=uL6dWQf08EaogYA2MxB+dg76pbwLqzlt/aHimz1sZQI=; b=rdJlWCEsTcL3mud0iw5RYwTA/GrWub82Q7bTLvFMqt/zEp1rDlrYBeMIdKG1hyZDsu 6HLbL9CK9vQjCYrF7/pNAeSZ8gG0qkLvZH3DWW2efLwrh3QsIhfagorOqEaKQSvlRn3Q SVwb9Iy183lsnXX8jZPdOll7drowWWiPiTnXQ5tX26RUHcHVMv9eaMn8zkf8oIVS+uHR hmXBcLGZSWlJAZaxkPzs2j7Y/8oXcAEJkfzAvbG/fqTtQ3G7jU9/8gPk9eAj2jfGUrxy HTZ4vNTTjlRY8TEjkhDhukYe0rbvDytfRh3bB4l3el69qDCA+S6ovHvhp63bOnUxXuKC Onlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lHNPWutH; 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 w19si9290026pgf.573.2018.11.11.16.17.01; Sun, 11 Nov 2018 16:17:16 -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=lHNPWutH; 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 S1730631AbeKLKHF (ORCPT + 99 others); Mon, 12 Nov 2018 05:07:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:59152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730124AbeKLIRF (ORCPT ); Mon, 12 Nov 2018 03:17:05 -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 0B77D22353; Sun, 11 Nov 2018 22:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975229; bh=sqz+niQs7PNeydEtgFVeUslfSp5UbDcQscW6LMzcQns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lHNPWutHYN48zb583/UMu9p/WO5Cy5U3CMNuSURqfz0/A24ujLs/BDK/cXnUPe4ke ZEpTBwvO5DGn89aN8ts0V2niekf+2lqngLjHbDJGLPeSvcXwcwjOs4bhEKsIW/z9bi hfgb4CMuOMSNzT8r6u3pKRV8I0/pLAG23njENVJk= 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.19 050/361] locking/lockdep: Fix debug_locks off performance problem Date: Sun, 11 Nov 2018 14:16:37 -0800 Message-Id: <20181111221627.042283758@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -4122,7 +4122,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)) @@ -4142,7 +4142,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;