From patchwork Mon Dec 7 11:31:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yulei zhang X-Patchwork-Id: 11955417 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 85781C433FE for ; Mon, 7 Dec 2020 11:33:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 08CB123340 for ; Mon, 7 Dec 2020 11:33:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08CB123340 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9D3318D000A; Mon, 7 Dec 2020 06:33:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 986518D0001; Mon, 7 Dec 2020 06:33:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84A1F8D000A; Mon, 7 Dec 2020 06:33:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 6E1B68D0001 for ; Mon, 7 Dec 2020 06:33:51 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3511D33CD for ; Mon, 7 Dec 2020 11:33:51 +0000 (UTC) X-FDA: 77566276662.16.house95_2d0bdec273de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 0B085100E6903 for ; Mon, 7 Dec 2020 11:33:51 +0000 (UTC) X-HE-Tag: house95_2d0bdec273de X-Filterd-Recvd-Size: 9550 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 7 Dec 2020 11:33:50 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id i3so6025980pfd.6 for ; Mon, 07 Dec 2020 03:33:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QMkfGfUr8fj2hO5B5jLMQa5h9UySfQVQPVhyn3NCxd4=; b=lqKRhFOEdKV0wC0Ujvy8bkoj7sCr3aw0Z4/HDK77hQNPjJPNnVzFT7Y48IfRoK5fje 8Z3ax4VrbD+Dn0BhRTbgr8ogTL0zkSdpIuruZQ3+yy6Zr2XBsPy5eyrUcW0mVCr0/3bn qx+pBlAKJUjm/UklANHSReU2TCJRzqIA73fT6ogzAbRptOgSwK1+51QW8zzSqVkyvnwA lDTHfoho00Iof1lZ3QDDZkSwQBzQVJSl1+9+lTUfJcA7vzOvWze/xtSffZ8kB0THXJWq CodT0//aOcvnyDJGfu7Gte5EhdswKxOh89d3sLKX4/56IVsr8+P70YCf92dYnF/ATCXH EKEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMkfGfUr8fj2hO5B5jLMQa5h9UySfQVQPVhyn3NCxd4=; b=owN7rcLUwMYn3SEVhHj6HOCmPsd7yU3x5laDIWWXI8YYXK4mcJVsZKHCZwMUiI+YRP 3TspBZ6iX6Xm/KOX0ZgbJ2kSD5HkthYCsJmemH0V1hUNyTxydzdk4H4f6i5o1uRVTaLH mLlX0y/uw37elzr7/o7m6NSZQjpEb6LVSuZx6J7g+drLJzHjdbka5abj/FFnCuJBqaKj Ciazy/rBiCBJzQcOBjblXT57G7JFIcCg0A1flZISERjcmLgT+V3n5TdEz/Bt8n/cF7S5 VfkGGH1o69Y27XNoed6yuyoB6diLm9xDXiBdDHdhR+FadQ4FJDN089LW8UOTAcD/LHBy BMfg== X-Gm-Message-State: AOAM53213fViET3XPj4/brkuM+2DmPN/eqp3N5Q0e6lsx0TrVo2cQrkZ 68GGTx4FsueexxGAUFGO1cnOHQG6C98= X-Google-Smtp-Source: ABdhPJwqvcI3wGyVmABSaYBJRnwrF2eTs+saCLZYg+lluLMzqvEOWJNH8GFu5PCjSHRlesroiuhjqA== X-Received: by 2002:a65:558a:: with SMTP id j10mr17960023pgs.370.1607340829629; Mon, 07 Dec 2020 03:33:49 -0800 (PST) Received: from localhost.localdomain ([203.205.141.39]) by smtp.gmail.com with ESMTPSA id d4sm14219822pfo.127.2020.12.07.03.33.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 03:33:49 -0800 (PST) From: yulei.kernel@gmail.com X-Google-Original-From: yuleixzhang@tencent.com To: linux-mm@kvack.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, naoya.horiguchi@nec.com, viro@zeniv.linux.org.uk, pbonzini@redhat.com Cc: joao.m.martins@oracle.com, rdunlap@infradead.org, sean.j.christopherson@intel.com, xiaoguangrong.eric@gmail.com, kernellwp@gmail.com, lihaiwei.kernel@gmail.com, Yulei Zhang , Xiao Guangrong Subject: [RFC V2 07/37] dmem: trace core functions Date: Mon, 7 Dec 2020 19:31:00 +0800 Message-Id: <4ee2b130c35367a6a3e7b631c872b824a1f59d23.1607332046.git.yuleixzhang@tencent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 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: From: Yulei Zhang Add tracepoints for dmem alloc_init, alloc and free functions, that helps us to figure out what is happening inside dmem allocator Signed-off-by: Xiao Guangrong Signed-off-by: Yulei Zhang --- fs/dmemfs/Makefile | 1 + fs/dmemfs/inode.c | 5 ++++ fs/dmemfs/trace.h | 54 +++++++++++++++++++++++++++++++++++ include/trace/events/dmem.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ mm/dmem.c | 6 ++++ 5 files changed, 134 insertions(+) create mode 100644 fs/dmemfs/trace.h create mode 100644 include/trace/events/dmem.h diff --git a/fs/dmemfs/Makefile b/fs/dmemfs/Makefile index 73bdc9c..0b36d03 100644 --- a/fs/dmemfs/Makefile +++ b/fs/dmemfs/Makefile @@ -2,6 +2,7 @@ # # Makefile for the linux dmem-filesystem routines. # +ccflags-y += -I $(srctree)/$(src) # needed for trace events obj-$(CONFIG_DMEM_FS) += dmemfs.o dmemfs-y += inode.o diff --git a/fs/dmemfs/inode.c b/fs/dmemfs/inode.c index 9ec62dc..7723b58 100644 --- a/fs/dmemfs/inode.c +++ b/fs/dmemfs/inode.c @@ -31,6 +31,9 @@ MODULE_AUTHOR("Tencent Corporation"); MODULE_LICENSE("GPL v2"); +#define CREATE_TRACE_POINTS +#include "trace.h" + struct dmemfs_mount_opts { unsigned long dpage_size; }; @@ -336,6 +339,7 @@ static void *find_radix_entry_or_next(struct address_space *mapping, offset += inode->i_sb->s_blocksize; dpages--; mapping->nrexceptional++; + trace_dmemfs_radix_tree_insert(index, entry); index++; } @@ -532,6 +536,7 @@ static void inode_drop_dpages(struct inode *inode, loff_t start, loff_t end) break; xa_erase(&mapping->i_pages, istart); + trace_dmemfs_radix_tree_delete(istart, pvec.pages[i]); mapping->nrexceptional--; addr = dmem_entry_to_addr(inode, pvec.pages[i]); diff --git a/fs/dmemfs/trace.h b/fs/dmemfs/trace.h new file mode 100644 index 00000000..cc11653 --- /dev/null +++ b/fs/dmemfs/trace.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/** + * trace.h - DesignWare Support + * + * Copyright (C) + * + * Author: Xiao Guangrong + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM dmemfs + +#if !defined(_TRACE_DMEMFS_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_DMEMFS_H + +#include + +DECLARE_EVENT_CLASS(dmemfs_radix_tree_class, + TP_PROTO(unsigned long index, void *rentry), + TP_ARGS(index, rentry), + + TP_STRUCT__entry( + __field(unsigned long, index) + __field(void *, rentry) + ), + + TP_fast_assign( + __entry->index = index; + __entry->rentry = rentry; + ), + + TP_printk("index %lu entry %#lx", __entry->index, + (unsigned long)__entry->rentry) +); + +DEFINE_EVENT(dmemfs_radix_tree_class, dmemfs_radix_tree_insert, + TP_PROTO(unsigned long index, void *rentry), + TP_ARGS(index, rentry) +); + +DEFINE_EVENT(dmemfs_radix_tree_class, dmemfs_radix_tree_delete, + TP_PROTO(unsigned long index, void *rentry), + TP_ARGS(index, rentry) +); +#endif + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +/* This part must be outside protection */ +#include diff --git a/include/trace/events/dmem.h b/include/trace/events/dmem.h new file mode 100644 index 00000000..10d1b90 --- /dev/null +++ b/include/trace/events/dmem.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM dmem + +#if !defined(_TRACE_DMEM_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_DMEM_H + +#include + +TRACE_EVENT(dmem_alloc_init, + TP_PROTO(unsigned long dpage_shift), + TP_ARGS(dpage_shift), + + TP_STRUCT__entry( + __field(unsigned long, dpage_shift) + ), + + TP_fast_assign( + __entry->dpage_shift = dpage_shift; + ), + + TP_printk("dpage_shift %lu", __entry->dpage_shift) +); + +TRACE_EVENT(dmem_alloc_pages_node, + TP_PROTO(phys_addr_t addr, int node, int try_max, int result_nr), + TP_ARGS(addr, node, try_max, result_nr), + + TP_STRUCT__entry( + __field(phys_addr_t, addr) + __field(int, node) + __field(int, try_max) + __field(int, result_nr) + ), + + TP_fast_assign( + __entry->addr = addr; + __entry->node = node; + __entry->try_max = try_max; + __entry->result_nr = result_nr; + ), + + TP_printk("addr %#lx node %d try_max %d result_nr %d", + (unsigned long)__entry->addr, __entry->node, + __entry->try_max, __entry->result_nr) +); + +TRACE_EVENT(dmem_free_pages, + TP_PROTO(phys_addr_t addr, int dpages_nr), + TP_ARGS(addr, dpages_nr), + + TP_STRUCT__entry( + __field(phys_addr_t, addr) + __field(int, dpages_nr) + ), + + TP_fast_assign( + __entry->addr = addr; + __entry->dpages_nr = dpages_nr; + ), + + TP_printk("addr %#lx dpages_nr %d", (unsigned long)__entry->addr, + __entry->dpages_nr) +); +#endif + +/* This part must be outside protection */ +#include diff --git a/mm/dmem.c b/mm/dmem.c index a77a064..aa34bf2 100644 --- a/mm/dmem.c +++ b/mm/dmem.c @@ -18,6 +18,8 @@ #include #include +#define CREATE_TRACE_POINTS +#include /* * There are two kinds of page in dmem management: * - nature page, it's the CPU's page size, i.e, 4K on x86 @@ -559,6 +561,8 @@ int dmem_alloc_init(unsigned long dpage_shift) mutex_lock(&dmem_pool.lock); + trace_dmem_alloc_init(dpage_shift); + if (dmem_pool.dpage_shift) { /* * double init on the same page size is okay @@ -686,6 +690,7 @@ int dmem_alloc_init(unsigned long dpage_shift) } } + trace_dmem_alloc_pages_node(addr, node, try_max, *result_nr); mutex_unlock(&dmem_pool.lock); } return addr; @@ -791,6 +796,7 @@ void dmem_free_pages(phys_addr_t addr, unsigned int dpages_nr) mutex_lock(&dmem_pool.lock); + trace_dmem_free_pages(addr, dpages_nr); WARN_ON(!dmem_pool.dpage_shift); dregion = find_dmem_region(addr, &pdnode);