Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp799862pxb; Thu, 5 Nov 2020 13:21:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKWffhAoAKGIxtTZuoNhr7vHLmnynQuGDeSjO6UJ2i18Ntd9PvzUuBkqcidwDSe0EIdS5H X-Received: by 2002:a17:906:82d7:: with SMTP id a23mr4213548ejy.505.1604611314325; Thu, 05 Nov 2020 13:21:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604611314; cv=none; d=google.com; s=arc-20160816; b=T6AetkpOs9YkpRDr6cy8DZJoLbVVVpNUDlfCX6QiSBuPDHCkmisCU1VvnscjdF9Q/O JL3+p9GFHW2GgmSi17khSxvLY/qGyK/BKxI8iR7z791YGWAoh57FcLShQqa6m5FeNU0e GPIskFdN1vOm8IXp1BHj2SuvEpwh0EzsO3MhfUjYcCnXme2o9xigmPOrmJuwQDEmvkD2 U6vQesGUfRm0pwkOeT1NnMpsPIeKin4mZcCDlCni6mWIwvD4fdAr7MX0hwY3LziTwHf8 1iH8lbp6/ENXxvhpI0tDGwwCCsaQVXeiyN5gdUOyhTXSBPcJyzjkBrbMoRjC9R/fTrRr SEDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=CWQ9UWAzLNf25Gm+QM5JO9SZkGZbnesBYaj1Ii23SGw=; b=ZJGanWs/8XNHI0+XyHAqTUXggLzdHuBVZDcMZ+rN0cVoulL/o91hEKxh7CMAvIHhqc Wdp9PO5skWNpdWkQ4d7rR1tXRCcfIb7gh22IxXQoVs05nzVq9ZP4mUlmoYCAhKBEm6E0 xlH556c+lgXQoB26LfyVe9I29yUoBVvab+Sko3etWtF22hqwGupOUfic3jh+deMaIzko rHhZBZJrwuL9luE70RZ3sOphUMB/kIi8NU27I0j3MHWF68DwIW2YTfLzlPnmF7S2ql25 NsL3pov4lM+7VZ6FGM042/SdrKfYTcdwsm/yhvOOql/cGNR6bg0VazLuqvxcyNs028Nd 8tjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ntxuuYSI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si2363517edi.432.2020.11.05.13.21.31; Thu, 05 Nov 2020 13:21:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ntxuuYSI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732295AbgKEVRt (ORCPT + 99 others); Thu, 5 Nov 2020 16:17:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgKEVRr (ORCPT ); Thu, 5 Nov 2020 16:17:47 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F1FC0613CF for ; Thu, 5 Nov 2020 13:17:47 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id d21so1773129qtp.2 for ; Thu, 05 Nov 2020 13:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=CWQ9UWAzLNf25Gm+QM5JO9SZkGZbnesBYaj1Ii23SGw=; b=ntxuuYSIC//Ipv5nwAlhlbI0u2ggda1uKlvsAZpzhngQvdJ5Euw0QzjPIzMUnqk711 xPRn/iciXDVVRfKK+PBec4MFO87PHwxvg0uMnVYNNVa3jSMq6YyuRmjhHHglUk1Exnxe iB6/5Ctz+2u/X1VxprIqJeLyV/G/968LJ16ay5VUty5Br/gG1FDTWEQUT8xWe2Lgnc21 9ZOCpcgjpEAjGVQ2g+e5vAO0FCz2eCrdVp/VzKWtTEnaCXxReKaJ7A6kULLy2l3VlUA0 9jjqv5XxPm4Qp7Ix5Dk7as94TeIo+0G0gIfqTT6nyNB0M5iRtbov7p8qLpcijJzqeGdD Nz6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=CWQ9UWAzLNf25Gm+QM5JO9SZkGZbnesBYaj1Ii23SGw=; b=tT8JMTcVNMZ7wrdq+TNBdCjQyMK4Wz/UJK0PV7V3EG4y5FnH5SnlrHDyOHmaduRoRK jCNPvSfT4BgFNuy/hUJh3MkfwT6U5vr4676pqNU1Tp7scMqcTKlaRfPY6egMdhSGObl8 k4xBb7jsdbpO12R0EiS/cfVA1J1s1rGriuTq3jrTiP1cQrFsfVw7mnadoMfrNygHfG/t YS+zsycAA/u8J0TSCvUEu6V8ZH/TrQHH46kECvaLoZPVC3g+TfSZHR0UOxnxbmxtWWmr +fRhAFi98wfp02jGAtZonFOp1v/ARDBbXo3HlBmM8L4rZpyiLwZyk1EcdfzTLoozL8DM Yl+A== X-Gm-Message-State: AOAM530OrKWjhWiTY4oSdRj6JsdoQyw58tQyTKyFLI4OeUpzn0gI2XKQ GSbHDe5gLwAxxQiNxve5mausCVBA5ITsiDtcQaok Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:f693:9fff:feef:c8f8]) (user=axelrasmussen job=sendgmr) by 2002:ad4:4041:: with SMTP id r1mr2103637qvp.49.1604611066573; Thu, 05 Nov 2020 13:17:46 -0800 (PST) Date: Thu, 5 Nov 2020 13:17:38 -0800 Message-Id: <20201105211739.568279-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v6 0/1] mmap_lock: add tracepoints around lock acquisition From: Axel Rasmussen To: Steven Rostedt , Ingo Molnar , Andrew Morton , Michel Lespinasse , Vlastimil Babka , Daniel Jordan , Jann Horn , Chinwen Chang , Davidlohr Bueso , David Rientjes , Laurent Dufour Cc: Yafang Shao , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchset adds tracepoints around mmap_lock acquisition. This is useful so we can measure the latency of lock acquisition, in order to detect contention. This version is based on v5.10-rc2. Changes since v5: - Michel pointed out that rwsem_release in mmap_read_trylock_non_owner doesn't actually release the lock, it just releases lockdep's ownership tracking. So, it's incorrect to call __mmap_lock_trace_released there, so the call has been removed. Changes since v4: - Redesigned buffer allocation to deal with the fact that a trace event might be interrupted by e.g. an IRQ, for which a per-cpu buffer is insufficient. Now we allocate one buffer per CPU * one buffer per context we might be called in (currently 4: normal, irq, softirq, NMI). We have three trace events which can potentially all be enabled, and all of which need a buffer; to avoid further multiplying the number of buffers by 3, they share the same set of buffers, which requires a spinlock + counter setup so we only allocate the buffers once, and then free them only when *all* of the trace events are _unreg()-ed. Changes since v3: - Switched EXPORT_SYMBOL to EXPORT_TRACEPOINT_SYMBOL, removed comment. - Removed redundant trace_..._enabled() check. - Defined the three TRACE_EVENTs separately, instead of sharing an event class. The tradeoff is 524 more bytes in .text, but the start_locking and released events no longer have a vestigial "success" field, so they're simpler + faster. Changes since v2: - Refactored tracing helper functions so the helpers are simper, but the locking functinos are slightly more verbose. Overall, this decreased the delta to mmap_lock.h slightly. - Fixed a typo in a comment. :) Changes since v1: - Functions renamed to reserve the "trace_" prefix for actual tracepoints. - We no longer measure the duration directly. Instead, users are expected to construct a synthetic event which computes the interval between "start locking" and "acquire returned". - The new helper for checking if tracepoints are enabled in a header is used to avoid un-inlining any of the lock wrappers. This yields ~zero overhead if the tracepoints aren't enabled, and therefore obviates the need for a Kconfig for this change. [1] https://lore.kernel.org/patchwork/patch/1316922/ [2] https://lore.kernel.org/patchwork/patch/1311996/ Axel Rasmussen (1): mmap_lock: add tracepoints around lock acquisition include/linux/mmap_lock.h | 94 +++++++++++++++- include/trace/events/mmap_lock.h | 107 ++++++++++++++++++ mm/Makefile | 2 +- mm/mmap_lock.c | 187 +++++++++++++++++++++++++++++++ 4 files changed, 384 insertions(+), 6 deletions(-) create mode 100644 include/trace/events/mmap_lock.h create mode 100644 mm/mmap_lock.c -- 2.29.1.341.ge80a0c044ae-goog