From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95E5EC388F2 for ; Tue, 20 Oct 2020 18:18:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D72C72098B for ; Tue, 20 Oct 2020 18:18:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qfBhdJLP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D72C72098B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 148B96B0068; Tue, 20 Oct 2020 14:18:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F9866B006C; Tue, 20 Oct 2020 14:18:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 035DE6B006E; Tue, 20 Oct 2020 14:18:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id CBA026B0068 for ; Tue, 20 Oct 2020 14:18:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 50D15362B for ; Tue, 20 Oct 2020 18:18:23 +0000 (UTC) X-FDA: 77393113686.28.vest95_2b1665927241 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 160CF6C04 for ; Tue, 20 Oct 2020 18:18:23 +0000 (UTC) X-HE-Tag: vest95_2b1665927241 X-Filterd-Recvd-Size: 9567 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 20 Oct 2020 18:18:22 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id t22so1444191plr.9 for ; Tue, 20 Oct 2020 11:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6HboVrD2Vhe2nA65C8FtX+ikgZJapeA+m1MOIgVXqLM=; b=qfBhdJLPl68eKtjAnzEHdPgp81waz/xyoPwQtYvCqoaARPSV27J60EPxzhx81Ln7/Y a6WohdVv0c/hvNq3wCkV7Xu62kY3/rAsTYLKk0rcQYhBK/F5OFrSEr5Lh+L3dW98esQ8 suSj8M1WnGx2U7YFrTzqdG/aZ/9MnVfQjnqJ0ZrLcv3gC6SGDd7THfxjqWpk59kKUQlX rZWN3AXWxUxkLuZisb4mjotgm9sxs2Vg8FmucvseGWx/82XGzfSc2sY9MkK7Mz9afO5O IjCqYedaoV4CG2DYJoOkkAsNIUb4oHrUCz62TfQZ5ZdcDP72WdyGo5xHejaKaRRjvQJ8 LQhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6HboVrD2Vhe2nA65C8FtX+ikgZJapeA+m1MOIgVXqLM=; b=SIUsewZwcsjskl+pA0QkYVAC3B5xwTmRcM2KQdKG0+PXINpu/7m/mwcScLyu6Id52n V555slLiNmBKz/emrx/kxrPvxsaPi0FVup6mYPQhc2VXC0rO+QufloeuM6eVXvW+5fTO 8H37CLZQEPsaFHnKyTdN+2aQNUE/ZpunRuRwmx2c2qKWs5fjLZwIIIH5CFMTMCLpe3G2 8iiLc5G06q07hQnj4nJ3TqLjR8K/+2pLSZQfuc7xtonVwCc4B24XlqaA+mR4RkkYu/PG rP2mGlz/i184GHDdlL+TkCHKind/wMy22UMzE/ETwt8tag6eqWCZCC5WPe3D9I84oL+v UIyg== X-Gm-Message-State: AOAM530a0m9KGBjPBpAswPAwlI8hDHBym3dgh2QaAuBVPXKY2TlEMLbE zZ/JtIXkr5JnbqubUynqV0mG19bF08Pbu/p/Z4Xhmg== X-Google-Smtp-Source: ABdhPJzq033GBPir40Pqpk+7HfChTLVmIrS875guc+TqYdohTwPKDUmCtyX7Ml9VQp/Es/Jzoz9tg2+UCDSLnldW7pI= X-Received: by 2002:a17:90a:ed87:: with SMTP id k7mr3870502pjy.127.1603217901251; Tue, 20 Oct 2020 11:18:21 -0700 (PDT) MIME-Version: 1.0 References: <20201009220524.485102-1-axelrasmussen@google.com> <20201009220524.485102-3-axelrasmussen@google.com> <1b9238b7-17f2-6c1e-b37e-cf65424f504b@suse.cz> In-Reply-To: <1b9238b7-17f2-6c1e-b37e-cf65424f504b@suse.cz> From: Axel Rasmussen Date: Tue, 20 Oct 2020 11:17:44 -0700 Message-ID: Subject: Re: [PATCH v3 2/2] mmap_lock: add tracepoints around lock acquisition To: Vlastimil Babka Cc: Steven Rostedt , Ingo Molnar , Andrew Morton , Michel Lespinasse , Daniel Jordan , Laurent Dufour , Jann Horn , Chinwen Chang , Yafang Shao , LKML , Linux MM Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Oct 20, 2020 at 7:50 AM Vlastimil Babka wrote: > > On 10/10/20 12:05 AM, Axel Rasmussen wrote: > > The goal of these tracepoints is to be able to debug lock contention > > issues. This lock is acquired on most (all?) mmap / munmap / page fault > > operations, so a multi-threaded process which does a lot of these can > > experience significant contention. > > > > We trace just before we start acquisition, when the acquisition returns > > (whether it succeeded or not), and when the lock is released (or > > downgraded). The events are broken out by lock type (read / write). > > > > The events are also broken out by memcg path. For container-based > > workloads, users often think of several processes in a memcg as a single > > logical "task", so collecting statistics at this level is useful. > > > > The end goal is to get latency information. This isn't directly included > > in the trace events. Instead, users are expected to compute the time > > between "start locking" and "acquire returned", using e.g. synthetic > > events or BPF. The benefit we get from this is simpler code. > > > > Because we use tracepoint_enabled() to decide whether or not to trace, > > this patch has effectively no overhead unless tracepoints are enabled at > > runtime. If tracepoints are enabled, there is a performance impact, but > > how much depends on exactly what e.g. the BPF program does. > > > > Signed-off-by: Axel Rasmussen > > Yeah I agree with this approach that follows the page ref one. > > ... > > > diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c > > new file mode 100644 > > index 000000000000..b849287bd12a > > --- /dev/null > > +++ b/mm/mmap_lock.c > > @@ -0,0 +1,87 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#define CREATE_TRACE_POINTS > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* > > + * We have to export these, as drivers use mmap_lock, and our inline functions > > + * in the header check if the tracepoint is enabled. They can't be GPL, as e.g. > > + * the nvidia driver is an existing caller of this code. > > I don't think this argument works in the kernel community. I would just remove > this comment. > > > + */ > > +EXPORT_SYMBOL(__tracepoint_mmap_lock_start_locking); > > +EXPORT_SYMBOL(__tracepoint_mmap_lock_acquire_returned); > > +EXPORT_SYMBOL(__tracepoint_mmap_lock_released); > > You can use EXPORT_TRACEPOINT_SYMBOL() here. This is simpler, thanks for the pointer! Agree the comment isn't needed in this case. I added it mainly since checkpatch.pl doesn't like the EXPORT_SYMBOL-ing things not defined just above, but EXPORT_TRACEPOINT_SYMBOL won't raise the same concerns. > > > +#ifdef CONFIG_MEMCG > > + > > +DEFINE_PER_CPU(char[MAX_FILTER_STR_VAL], trace_memcg_path); > > + > > +/* > > + * Write the given mm_struct's memcg path to a percpu buffer, and return a > > + * pointer to it. If the path cannot be determined, the buffer will contain the > > + * empty string. > > + * > > + * Note: buffers are allocated per-cpu to avoid locking, so preemption must be > > + * disabled by the caller before calling us, and re-enabled only after the > > + * caller is done with the pointer. > > + */ > > +static const char *get_mm_memcg_path(struct mm_struct *mm) > > +{ > > + struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm); > > + > > + if (memcg != NULL && likely(memcg->css.cgroup != NULL)) { > > + char *buf = this_cpu_ptr(trace_memcg_path); > > + > > + cgroup_path(memcg->css.cgroup, buf, MAX_FILTER_STR_VAL); > > + return buf; > > + } > > + return ""; > > +} > > + > > +#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \ > > + do { \ > > + if (trace_mmap_lock_##type##_enabled()) { \ > > Is this check really needed? We only got called from the functions inlined in > the .h file because tracepoint_enabled() was true in the first place, so this > seems redundant. Right, now that we've moved the check into the header, this isn't needed. > > > + get_cpu(); \ > > + trace_mmap_lock_##type(mm, get_mm_memcg_path(mm), \ > > + ##__VA_ARGS__); \ > > + put_cpu(); \ > > + } \ > > + } while (0) > > + > > +#else /* !CONFIG_MEMCG */ > > + > > +#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \ > > + trace_mmap_lock_##type(mm, "", ##__VA_ARGS__) > > + > > +#endif /* CONFIG_MEMCG */ > > + > > +/* > > + * Trace calls must be in a separate file, as otherwise there's a circular > > + * dependency between linux/mmap_lock.h and trace/events/mmap_lock.h. > > + */ > > + > > +void __mmap_lock_do_trace_start_locking(struct mm_struct *mm, bool write) > > +{ > > + TRACE_MMAP_LOCK_EVENT(start_locking, mm, write, true); > > Seems wasteful to have an always-true success field here. Yeah, not reusing the > same event class for all three tracepoints means more code, but for tracing > efficiency it's worth it, IMHO. Right, originally I was worried about code size. But, I switched to not re-using an event class, and I only measure an increase of 524 bytes in .text, which seems trivial. I'll send a v4 with all of the above changes. > > > +} > > +EXPORT_SYMBOL(__mmap_lock_do_trace_start_locking); > > + > > +void __mmap_lock_do_trace_acquire_returned(struct mm_struct *mm, bool write, > > + bool success) > > +{ > > + TRACE_MMAP_LOCK_EVENT(acquire_returned, mm, write, success); > > +} > > +EXPORT_SYMBOL(__mmap_lock_do_trace_acquire_returned); > > + > > +void __mmap_lock_do_trace_released(struct mm_struct *mm, bool write) > > +{ > > + TRACE_MMAP_LOCK_EVENT(released, mm, write, true); > > Ditto. > > > +} > > +EXPORT_SYMBOL(__mmap_lock_do_trace_released); > > >