From patchwork Tue Oct 12 05:49:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12551541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A6C6C433EF for ; Tue, 12 Oct 2021 05:50:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DBE1F60E52 for ; Tue, 12 Oct 2021 05:50:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DBE1F60E52 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 26B716B006C; Tue, 12 Oct 2021 01:50:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21B566B0071; Tue, 12 Oct 2021 01:50:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10AF2900002; Tue, 12 Oct 2021 01:50:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id 010186B006C for ; Tue, 12 Oct 2021 01:49:59 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AC8752A021 for ; Tue, 12 Oct 2021 05:49:59 +0000 (UTC) X-FDA: 78686709318.05.0C41423 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 41F971003978 for ; Tue, 12 Oct 2021 05:49:57 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UrY4FKf_1634017792; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UrY4FKf_1634017792) by smtp.aliyun-inc.com(127.0.0.1); Tue, 12 Oct 2021 13:49:53 +0800 From: Xin Hao To: sjpark@amazon.de Cc: xhao@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/dbgfs: add region_stat interface Date: Tue, 12 Oct 2021 13:49:48 +0800 Message-Id: <20211012054948.90381-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf12.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 41F971003978 X-Stat-Signature: 3ke35h7mitjx1udud8wu6mzj1rxbborf X-HE-Tag: 1634017797-362372 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: Using damon-dbgfs has brought great convenience to user-mode operation damon, but sometimes if i want to be able to view the division of task regions, nr_access values etc,but i found that it is impossible to view directly through the dbgfs interface, so there i add a interface "region_stat", it displays like this. # cat region_stat last_aggregation=120.87s target_id=5148 nr_regions=10 400000-258c000(34352 KiB): 1 258c000-4719000(34356 KiB): 0 4719000-abbf000(103064 KiB): 0 abbf000-c4d4000(25684 KiB): 11 c4d4000-ff5c000(59936 KiB): 15 ff5c000-152f9000(85620 KiB): 20 152f9000-1599e000(6804 KiB): 10 1599e000-19573000(61268 KiB): 0 19573000-1f92c000(102116 KiB): 0 1f92c000-22a4c000(50304 KiB): 0 Signed-off-by: Xin Hao Reported-by: kernel test robot --- mm/damon/dbgfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index faee070977d8..269a336e92f0 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -266,6 +266,57 @@ static ssize_t dbgfs_kdamond_pid_read(struct file *file, return len; } +static ssize_t dbgfs_region_stat_read(struct file *file, + char __user *buf, size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + struct damon_target *t; + char *kbuf; + ssize_t len; + int id, rc, written = 0; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + damon_for_each_target(t, ctx) { + struct damon_region *r; + + if (targetid_is_pid(ctx)) + id = (int)pid_vnr((struct pid *)t->id); + + rc = scnprintf(&kbuf[written], count - written, + "last_aggregation=%lld.%lds\ntarget_id=%d\nnr_regions=%u\n", + ctx->last_aggregation.tv_sec, + ctx->last_aggregation.tv_nsec / 1000000, + id, t->nr_regions); + if (!rc) + goto out; + + written += rc; + + damon_for_each_region(r, t) { + rc = scnprintf(&kbuf[written], count - written, + "%lx-%lx(%lu KiB): %u\n", + r->ar.start, r->ar.end, + (r->ar.end - r->ar.start) >> 10, + r->nr_accesses); + if (!rc) + goto out; + + written += rc; + } + + len += simple_read_from_buffer(buf, count, ppos, kbuf, written); + } + +out: + mutex_unlock(&ctx->kdamond_lock); + kfree(kbuf); + return len; +} + static int damon_dbgfs_open(struct inode *inode, struct file *file) { file->private_data = inode->i_private; @@ -290,12 +341,17 @@ static const struct file_operations kdamond_pid_fops = { .read = dbgfs_kdamond_pid_read, }; +static const struct file_operations region_stat_fops = { + .open = damon_dbgfs_open, + .read = dbgfs_region_stat_read, +}; + static void dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) { const char * const file_names[] = {"attrs", "target_ids", - "kdamond_pid"}; + "kdamond_pid", "region_stat"}; const struct file_operations *fops[] = {&attrs_fops, &target_ids_fops, - &kdamond_pid_fops}; + &kdamond_pid_fops, ®ion_stat_fops}; int i; for (i = 0; i < ARRAY_SIZE(file_names); i++)