Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1018541pxu; Thu, 8 Oct 2020 00:41:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywQ6t4Rm1ep+J8Y0oUsWu6AREdAj4S8KeEd04vtRXiklrFjr7yUYvv2sICb5ADdJhLOAnZ X-Received: by 2002:a17:906:3b02:: with SMTP id g2mr2502222ejf.512.1602142916928; Thu, 08 Oct 2020 00:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602142916; cv=none; d=google.com; s=arc-20160816; b=knq0Y5zVx3FiCMLLw2cm7woG+fsHLLSW4UMdvYNLfQbSF6KoTQCysVL9zW9Z8f5h8J 5ii441qTiwJ5OYLHY+v7UJXTsLSzdDopc4LBJTEcQIOlxeqi0sxezGYb8n2JVZAJW0ps dlopxKHDmocjjSRvtuauXquC0nOl0v4LE3CK2DBz6/lQPFY0MnhqqVIqI8E6ixGyPTOE 0GBTRcyrIiECOx6y16/5FF6n9SYi71XaBgVDeOf7sTWHSQM2jrJnD0vJHMJ5gfC8afEd rHOv55IbM54WpId6vHl4rg2X1rqhZfp6tGmUHyUH08wwVs55xWxJZurccCK99Em17Amz 0ilQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7Rp3My2L/roRnIDEi9kisQtYgeX2FwvYUO7ZV7SrOvU=; b=DztpMol2sg6rWqASbDEjf6eBqwwiIOQhaty/A6pWzmeUFkZbmRc8LEHC9i4eHq7fmJ N6+SipmNaUjbp/t6XXMGx7EofSGh+96TcVqVtk3MsFhqB8UgtyD7qGZzTDZfdzSZmeWG ORTNgn0a9Q7Qu+XTea1+8RzWpDHEjlACw63nuLZvMaIxDJZmWhtpRgMQ41xL4Ae20Viz yxtRbPOzcdsvVQ8XQXc95k1Vmvup+GaTcXujhq4Bx32oiKI/4Ioj5tA9VJ/OOQoYitxI fzlu6JeeZroXLzsbpEqgjubD5DXDETeHeLKT2/zIX73lIfCbDO3lELw/4nO97tV6fjtL LlYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q5USTEPG; 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 kq6si3371649ejb.658.2020.10.08.00.41.33; Thu, 08 Oct 2020 00:41:56 -0700 (PDT) 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=q5USTEPG; 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 S1727873AbgJHHkU (ORCPT + 99 others); Thu, 8 Oct 2020 03:40:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727224AbgJHHkT (ORCPT ); Thu, 8 Oct 2020 03:40:19 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E59AC061755 for ; Thu, 8 Oct 2020 00:40:19 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id h9so3843507ybm.4 for ; Thu, 08 Oct 2020 00:40:19 -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=7Rp3My2L/roRnIDEi9kisQtYgeX2FwvYUO7ZV7SrOvU=; b=q5USTEPGaKtcH62zrMADCGgthfmfGu4Q0LxLhnuNjym9+D4SMw3X36j3KU7PUzr5Dl O3SJ/s06qAC48u4lXvaYATZ9of9OC8WEoI/ZlA3aPa7c1M/57tckvnl0uaHIHe5Xr2xi otnnoT8jMz+Jcjwqv/oBEMWHDvMowmhOOh+e12Fg2AUsu0gYGfWyU0zIy7TLanaRGLqM 7D8tix2Bp8rO+xDRzZ3Jy541nYCFqdZsX3CNKZR+CkLyWwIHhRAiAE7w9HIlGJTvQEfT FNPcT1nKGBB2ie1x2KIjwAWWw9jrptHbuJOeQaGqo/n0tT+9ScOR7Zx3WNGnS5qhSeRT srBQ== 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=7Rp3My2L/roRnIDEi9kisQtYgeX2FwvYUO7ZV7SrOvU=; b=T0jFh4eUQnnLY1csuwvQz7D2Tcly6Te0lXZXr1fkixCHGloIRaQKrrwQXm/SAkNI5H 1ti3QkWd9mTYcJVpFmIIvzfsnCTrUpiKbdk/DedPHIPDOpXvcJrjLoMXpmyH2hhvpiJw XOutaaB7xK3XpSqg3ZtR5/98kWnvNCYj0O2ei1CAhjKGFI9Mlub/i9PTGU0bXfhtzcql Z/cQYeAkeKlRAPiF8xgGRcLXkRE3Pma6pUY2Tyg3l+6VoWdWwjJRMmxjKYTq3AwcRQhi 6c8gRDckzzQMUzQHWnaEk5oCwxRqalxqv+OLTbDVahAOQOPyBF5PXpZp9sf1kGFBLoGJ +x4g== X-Gm-Message-State: AOAM533NCVMmLsKJEgp39GwLuAv7DHSq6H8Ukslau7VTQNe9L9gO9X9x GjiBXEaImfGOBeGQ29NpU8ZCqJ8vu2/vyOUy4vIGkQ== X-Received: by 2002:a25:840d:: with SMTP id u13mr9231276ybk.7.1602142818150; Thu, 08 Oct 2020 00:40:18 -0700 (PDT) MIME-Version: 1.0 References: <20201007184403.1902111-1-axelrasmussen@google.com> <20201007184403.1902111-3-axelrasmussen@google.com> In-Reply-To: <20201007184403.1902111-3-axelrasmussen@google.com> From: Michel Lespinasse Date: Thu, 8 Oct 2020 00:40:05 -0700 Message-ID: Subject: Re: [PATCH v2 2/2] mmap_lock: add tracepoints around lock acquisition To: Axel Rasmussen Cc: Steven Rostedt , Ingo Molnar , Andrew Morton , Vlastimil Babka , Daniel Jordan , Laurent Dufour , Jann Horn , Chinwen Chang , Yafang Shao , LKML , linux-mm Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 7, 2020 at 11:44 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 Thanks for working on this. I like that there is no overhead unless CONFIG_TRACING is set. However, I think the __mmap_lock_traced_lock and similar functions are the wrong level of abstraction, especially considering that we are considering to switch away from using rwsem as the underlying lock implementation. Would you consider something along the following lines instead for include/linux/mmap_lock.h ? #ifdef CONFIG_TRACING DECLARE_TRACEPOINT(...); void __mmap_lock_do_trace_start_locking(struct mm_struct *mm, bool write); static inline void mmap_lock_trace_start_locking(struct mm_struct *mm, bool write) { if (tracepoint_enabled(mmap_lock_start_locking)) __mmap_lock_do_trace_start_locking(mm, write); } #else static inline void mmap_lock_trace_start_locking(struct mm_struct *mm, bool write) {} #endif static inline void mmap_write_lock(struct mm_struct *mm) { mmap_lock_trace_start_locking(mm, true); down_write(&mm->mmap_lock); mmap_lock_trace_acquire_returned(mm, true, true); } I think this is more straightforward, and also the mmap_lock_trace_start_locking and similar functions don't depend on the underlying lock implementation. The changes to the other files look fine to me. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.