From patchwork Tue Mar 30 09:05:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12172099 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.8 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 71A03C433E0 for ; Tue, 30 Mar 2021 09:06:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06E8761929 for ; Tue, 30 Mar 2021 09:06:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06E8761929 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 D5A826B0095; Tue, 30 Mar 2021 05:06:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1F96B0096; Tue, 30 Mar 2021 05:06:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE7FA6B0098; Tue, 30 Mar 2021 05:06:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 8FF3C6B0095 for ; Tue, 30 Mar 2021 05:06:14 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4DE053631 for ; Tue, 30 Mar 2021 09:06:14 +0000 (UTC) X-FDA: 77975959068.16.5CECB09 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 6B565E0011DD for ; Tue, 30 Mar 2021 09:06:13 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id cx5so7765120qvb.10 for ; Tue, 30 Mar 2021 02:06:13 -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=W8+A/g3U4DodIE6llQ+hDjB/HFXop9Ja1bxfrVH/yAg=; b=LDQ5ryqtA8+D9rvRlvwrCBUAU0iQ3DGAgoZZqK1NpuLn97qOrBSIzELw0Lsk4PMh2J YPn3tbyXz1dWsFW41ERB1doJxXDTcAysZ0esZ0I3qoCfOpUiwCsTX5Z4tp/84rn3gU79 RlZO9tKkbm5VXJ12j0r2R/fKiMQsAa/yGzbwXdZOyrVXUynjeeHkQbZC7mF394hdcQzw INvk6RcEvBT4xIvknE4BhG6uXMRYYQ9vrUAMEsi3V3sEHZzu4sRIY9qfZJu5SQ7BeJ8n Mriq6Cz5bTN9w4gnkyA3HqDv747mIwXOMBPhPGIg7q1qAifafpDFT2drWLnccC8ERrT6 dpJA== 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=W8+A/g3U4DodIE6llQ+hDjB/HFXop9Ja1bxfrVH/yAg=; b=fZeOCZimCNyT6briOwllOo3XslXw7FJFeGW7s8x4pDCCxKCMhNCUwAgF5VrKTWGC1z ank9eiEViRAwpe7CJRhh4jN596PhJem1bNk2ohXxV+dvKj/33I4F5RYCpDRbSisqgK53 eFK7Cdl7IlSPGUsnr2O9VPjf/6B09rOMWs5rIuFtoF5hE20mIoU9EzSq4zNdOjiQRRIo 4Gncy5a95rRUKdXdP55iS4S6rSGCR+BuLOGLH+CIlvuJICCKCWNQU2TUgkVvwIzeiK0q 3L2UFfgZ2KHpQOx0lJvV99raYpT86ZW8yu2kgQlSTNaiF6oPowvECQM4D9FDoZeyw7Wt CYlA== X-Gm-Message-State: AOAM532r7rsQBipmwWvOWJ4lWFlJybUpzm6eoH1jEYCan5IX6ywHQ6PX PcsISnFZaeTL27QLFErGdsk= X-Google-Smtp-Source: ABdhPJyRjGTqSUKlNYgNG0XLD2eSfgVel59IOpaSZRQui14bQKl5x8NUFOtRE5FhU9EtAvVW+YI1+w== X-Received: by 2002:a05:6214:906:: with SMTP id dj6mr23121183qvb.38.1617095173219; Tue, 30 Mar 2021 02:06:13 -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 8sm14630011qkc.32.2021.03.30.02.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 02:06:12 -0700 (PDT) From: sj38.park@gmail.com 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, mgorman@suse.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, sj38.park@gmail.com, snu@amazon.de, 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 v26 08/13] mm/damon/dbgfs: Export kdamond pid to the user space Date: Tue, 30 Mar 2021 09:05:32 +0000 Message-Id: <20210330090537.12143-9-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210330090537.12143-1-sj38.park@gmail.com> References: <20210330090537.12143-1-sj38.park@gmail.com> X-Stat-Signature: wk5d6e456jaah11xoqsj37d8q3mrqt8u X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6B565E0011DD Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=mail-qv1-f51.google.com; client-ip=209.85.219.51 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617095173-434928 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 --- 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 02b27be9187a..aec2b7d81809 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 int 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++)