Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3204163pxk; Mon, 5 Oct 2020 04:04:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFo6+b33v0eST41iJc5MwlI5uIg4BY+LhQIne0bMGNfB6/+QNHcoFZO0OtwMyTq0qw8dDx X-Received: by 2002:a17:907:33d2:: with SMTP id zk18mr14395512ejb.145.1601895868172; Mon, 05 Oct 2020 04:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601895868; cv=none; d=google.com; s=arc-20160816; b=n7H9SNheIARAROr6O3Nv3LeSGsD0oTytYMxrqthWMwzRXzIUdSBIiDLBHNA5ragqB5 3aM6Yqt4PM5JkcL8Cf7mWeuOtj75Z/EwU6F3wMCjuW75MOy0qq8g59+ZrCBphufdDux7 KWW5SP5b+Mqxiec+W7jN3Zu2sCx6fOv2fs6zYNN9hkOPDpOfsfzrowZ/f9a26FXkC8Ue HkK2XcVHy11yVVdS/4Oso7kKH9izUjYONvMDNzclPTdJJ5P2gnIe2vJXmLvsAAcv24vk m0pxA/8L8otYmASrI6SP7VcepwcVvxiNDK2Wf5+ApCvrgqVbBpTJlmBIKxKG4wY71vMI o0ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2VNaUV42pskn5Np0OXFc3mY+gwZx6Wil6QyQsNtyJ/o=; b=ERBIKwt5v+nudo9Ij//J4qq4G+yU6Zs1XIQ76LM5/Pigik9tSNSWkedGovrvuaWKXq dO16iTP2S4tVsD1eUMDYT0f6fQdcNhZla90IASKm8p/yNgSytLmKpk+NNYoaQjPcMKiD QtZJ6Q8e3RZwgJz5/z85XL9NNoct7ml9CBzer6y9BnRPKflEdZhpDZeXBoLjKsosiU+G 85MhWLfaguH5bRAwsNGqL3xsdqqt0qVYHnwC5ta1vcR60Sf6W1uh3AsYnnFuaqRIe4EN 4TYqY2Or8ExYporC6JQ6412o4tN1P8MdgpfvTwAOejDDKnbcUMnuNIIUbpkd+A+vj8WK ZErg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=GdNock3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w26si6990994edq.89.2020.10.05.04.04.04; Mon, 05 Oct 2020 04:04:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=GdNock3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726053AbgJEK7z (ORCPT + 99 others); Mon, 5 Oct 2020 06:59:55 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:19410 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725974AbgJEK7z (ORCPT ); Mon, 5 Oct 2020 06:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601895595; x=1633431595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=2VNaUV42pskn5Np0OXFc3mY+gwZx6Wil6QyQsNtyJ/o=; b=GdNock3iwPZUSoivnsNmZ68OH8T2y485/GdGDBXj8MOF/eoOMa/s+MIk 6CsHmKGVcQPQrzx3jp64Z3FkWbu2MlVkpxmsHmKW6T0vP/GmDQveO9+7i QSerYwfimO8T0W0wA4UsP94HiiewJFUNvY3bOoX+Ue6x9WSYrbSElcHOj E=; X-IronPort-AV: E=Sophos;i="5.77,338,1596499200"; d="scan'208";a="80358271" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-a70de69e.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 05 Oct 2020 10:59:50 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1e-a70de69e.us-east-1.amazon.com (Postfix) with ESMTPS id F1C3AA1890; Mon, 5 Oct 2020 10:59:37 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.146) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 5 Oct 2020 10:59:20 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v21 12/18] mm/damon/dbgfs: Export kdamond pid to the user space Date: Mon, 5 Oct 2020 12:55:16 +0200 Message-ID: <20201005105522.23841-13-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201005105522.23841-1-sjpark@amazon.com> References: <20201005105522.23841-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.146] X-ClientProxiedBy: EX13d09UWC002.ant.amazon.com (10.43.162.102) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 c4401762fc16..a0956618ec2d 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -369,6 +369,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; @@ -397,11 +423,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