From mboxrd@z Thu Jan 1 00:00:00 1970 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 5B98EC4361B for ; Tue, 15 Dec 2020 12:00:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DE810222B6 for ; Tue, 15 Dec 2020 12:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE810222B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 364DC6B006C; Tue, 15 Dec 2020 07:00:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 313F76B006E; Tue, 15 Dec 2020 07:00:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DBCE6B0070; Tue, 15 Dec 2020 07:00:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 064DF6B006C for ; Tue, 15 Dec 2020 07:00:13 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B8148181AEF30 for ; Tue, 15 Dec 2020 12:00:12 +0000 (UTC) X-FDA: 77595373464.22.toe74_2b1849727423 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id E468318038E98 for ; Tue, 15 Dec 2020 12:00:06 +0000 (UTC) X-HE-Tag: toe74_2b1849727423 X-Filterd-Recvd-Size: 5313 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Dec 2020 12:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608033607; x=1639569607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=tYuImZATeZ5BU9vyZ/5gMK7OI/H0skCjpeJLNRGvwog=; b=ST1VnXblxMHi82GMMFTv8diLK0dTByYa2Fti5Cdoi+x7piYd0JGkiLNp RgNyHTB0E3BOi8czGqazsEfOD5BdbCZ/f0jxEdN8tqanduV6rnknHVLSQ FvgKNMUCWJrLlqXvi8Fauj9MgyJQ8o6nhmRJBYotAZ0Qnnvpo69FCVmBs E=; X-IronPort-AV: E=Sophos;i="5.78,420,1599523200"; d="scan'208";a="72726859" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-16425a8d.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 15 Dec 2020 12:00:06 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1d-16425a8d.us-east-1.amazon.com (Postfix) with ESMTPS id 79167101104; Tue, 15 Dec 2020 11:59:53 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.252) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 15 Dec 2020 11:59:36 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v23 09/15] mm/damon/dbgfs: Export kdamond pid to the user space Date: Tue, 15 Dec 2020 12:54:42 +0100 Message-ID: <20201215115448.25633-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215115448.25633-1-sjpark@amazon.com> References: <20201215115448.25633-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D33UWC002.ant.amazon.com (10.43.162.11) To EX13D31EUA001.ant.amazon.com (10.43.165.15) 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 | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 733d2f3e646e..a1512d3e5afe 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -337,6 +337,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; @@ -365,11 +391,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", "record", "target_ids"}; + const char * const file_names[] = {"attrs", "record", "target_ids", + "kdamond_pid"}; const struct file_operations *fops[] = {&attrs_fops, &record_fops, - &target_ids_fops}; + &target_ids_fops, &kdamond_pid_fops}; int i; for (i = 0; i < ARRAY_SIZE(file_names); i++) { -- 2.17.1