From patchwork Mon Jun 21 08:31:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12334113 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 90239C48BE5 for ; Mon, 21 Jun 2021 08:31:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 45F8A60FF4 for ; Mon, 21 Jun 2021 08:31:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45F8A60FF4 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 DBDBB6B008A; Mon, 21 Jun 2021 04:31:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5B016B008C; Mon, 21 Jun 2021 04:31:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD54F6B0092; Mon, 21 Jun 2021 04:31:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 8D4426B008A for ; Mon, 21 Jun 2021 04:31:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2ECB98249980 for ; Mon, 21 Jun 2021 08:31:46 +0000 (UTC) X-FDA: 78277062612.13.B6F5B20 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf18.hostedemail.com (Postfix) with ESMTP id E46C120015CB for ; Mon, 21 Jun 2021 08:31:45 +0000 (UTC) Received: by mail-qk1-f174.google.com with SMTP id g142so28313133qke.4 for ; Mon, 21 Jun 2021 01:31:45 -0700 (PDT) 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; bh=27fs4ayWfwDx66gepojtp7zAr2zH3uKkjECbTbsrrQM=; b=W5cSoZPWgKoDTsIoHK7Z2ydoJXNZNDaY8ysBq3Ght6vISwdF4nVdZ82SaPeM7Tw/CO TObpiwn7OdxAVdixVn47w7wabaEfor/rD7fejPfUSpGa9oLHN5VV5KJtNKZ+TBwGoEJO cCos1IwctUqvREkRh3LLoK9/Xlb39RQSJVA8UfJut3nfLoUst1P4cLVqC7+BKQzXuVsx jjHfXdNYEghy9Pg1Lk2S7MMOFkxedbEdzYp9EdRPOyanmc3eIIi5bf3YNFfkbOQ6qxp7 83coXN50H8tK2xKwmu0dQkrFb8vTE8JFEYC2dkI349Dj0QZ0KkTguaKlG+hOXxL+YDcE yHMA== 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; bh=27fs4ayWfwDx66gepojtp7zAr2zH3uKkjECbTbsrrQM=; b=Ypw9bERKWnEW00On5kEmUKQGJLZufsd19MhhAxsD4fTPJTWm1R9+PEaJjzaQxAsPqi sj4HQ4hotQICs4Gc78kX1PbT4kSm1xppuhJ+/qqzgjOvI6zvBptudW7glNNS353o86iJ FrSzOJyS8kKTH4E9i3BxQrUF1afg9v+dwfrTI9LTYtZGIHdN7ZL0nrbr9ugnW/a00JTd 8qfN0zclXk+z3NG4HQU+VvVn2F3iWsEQzNNF0vZqtrV954AdvSKut1NCl2sjDSe8Ige8 VFBJ1SMPOcqdwhOQSaqbUpVJnq6sPNYVXwzYJojy8wDkpe8U9rCLiJ6vAwhwSV895UWr fQ9Q== X-Gm-Message-State: AOAM532xFie5WCYjo/SDW3QCePcXHpEIMSQsuz9PFvBzSFTl59+OQ1mv bAh4qlGqYAnZXGRlGZAQXZk= X-Google-Smtp-Source: ABdhPJxfpfFM8Nu58EU59s2qXHapzK9iuOSF5DgEk5v33gbk4tr/z6XCCU6zFRs1bjTXJE+jEKDoZg== X-Received: by 2002:a37:7d83:: with SMTP id y125mr22320768qkc.7.1624264305350; Mon, 21 Jun 2021 01:31:45 -0700 (PDT) Received: from localhost.localdomain (ec2-35-169-212-159.compute-1.amazonaws.com. [35.169.212.159]) by smtp.gmail.com with ESMTPSA id l23sm9852581qtp.28.2021.06.21.01.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 01:31:44 -0700 (PDT) From: SeongJae Park To: akpm@linux-foundation.org Cc: SeongJae Park , Jonathan.Cameron@Huawei.com, acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, brendanhiggins@google.com, corbet@lwn.net, david@redhat.com, dwmw@amazon.com, elver@google.com, fan.du@intel.com, foersleo@amazon.de, greg@kroah.com, gthelen@google.com, guoju.fgj@alibaba-inc.com, jgowans@amazon.com, mgorman@suse.de, mheyne@amazon.de, minchan@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, riel@surriel.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, shakeelb@google.com, shuah@kernel.org, sieberf@amazon.com, sj38.park@gmail.com, snu@zelle79.org, vbabka@suse.cz, vdavydov.dev@gmail.com, zgf574564920@gmail.com, linux-damon@amazon.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v31 08/13] mm/damon/dbgfs: Export kdamond pid to the user space Date: Mon, 21 Jun 2021 08:31:03 +0000 Message-Id: <20210621083108.17589-9-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210621083108.17589-1-sj38.park@gmail.com> References: <20210621083108.17589-1-sj38.park@gmail.com> Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=W5cSoZPW; spf=pass (imf18.hostedemail.com: domain of sj38park@gmail.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=sj38park@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: pj3xmqq9pweb9xji95x6qfodesxqs44n X-Rspamd-Queue-Id: E46C120015CB X-Rspamd-Server: rspam06 X-HE-Tag: 1624264305-102206 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: SeongJae Park For CPU usage accounting, knowing pid of the monitoring thread could be helpful. For example, users could use cpuaccount cgroups with the pid. This commit therefore exports the pid of currently running monitoring thread to the user space via 'kdamond_pid' file in the debugfs directory. Signed-off-by: SeongJae Park Reviewed-by: Fernand Sieber --- mm/damon/dbgfs.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index c4a4a6f1dc79..524362f8c628 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -237,6 +237,32 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return ret; } +static ssize_t dbgfs_kdamond_pid_read(struct file *file, + char __user *buf, size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t len; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) + len = scnprintf(kbuf, count, "%d\n", ctx->kdamond->pid); + else + len = scnprintf(kbuf, count, "none\n"); + mutex_unlock(&ctx->kdamond_lock); + if (!len) + goto out; + len = simple_read_from_buffer(buf, count, ppos, kbuf, len); + +out: + kfree(kbuf); + return len; +} + static int damon_dbgfs_open(struct inode *inode, struct file *file) { file->private_data = inode->i_private; @@ -258,10 +284,18 @@ static const struct file_operations target_ids_fops = { .write = dbgfs_target_ids_write, }; +static const struct file_operations kdamond_pid_fops = { + .owner = THIS_MODULE, + .open = damon_dbgfs_open, + .read = dbgfs_kdamond_pid_read, +}; + static void dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) { - const char * const file_names[] = {"attrs", "target_ids"}; - const struct file_operations *fops[] = {&attrs_fops, &target_ids_fops}; + const char * const file_names[] = {"attrs", "target_ids", + "kdamond_pid"}; + const struct file_operations *fops[] = {&attrs_fops, &target_ids_fops, + &kdamond_pid_fops}; int i; for (i = 0; i < ARRAY_SIZE(file_names); i++)