Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3571127pxj; Mon, 21 Jun 2021 01:33:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxiuXpEuDi0YDstUKiZpPy6pABdzBdlsrLHR1GasgvcyIJys8GLPNPwAKeDrKdWGg8ixG+ X-Received: by 2002:a05:6e02:f03:: with SMTP id x3mr12324527ilj.190.1624264384171; Mon, 21 Jun 2021 01:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624264384; cv=none; d=google.com; s=arc-20160816; b=hrHaeKY9iuzPRqXC+rFrkJXSkDTIO/4to0wHfIUBkgTZJf7d6UQX1lZ3pRNC2crh3r 3cftqVb+N8KMyULXN3ioMPq+6Nxw2p/hOyW7M3ugznSTlR8dXhYgY2/Z9NE3/2AoXNn0 6dESyOYq90TVHD63RX9ajy2nM41Mayd2yVt0+40ffLUuJkPzmqcoHB6Au0ZmOQQEnpgY ptqKw00FWVE/DyWc/L9cdHYiYtBCHE6g0PDChqXh4Bnb5m74eUDcehEQwpx7UGPJneiq 95AU7e5R1g/tpngv70oK/mXZhhjnQINTSKsV+BnPhOg5KIfdKQDG0oR+jSxc6FXkKvWQ I0lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=27fs4ayWfwDx66gepojtp7zAr2zH3uKkjECbTbsrrQM=; b=VEDxLdj3ASBrw6LSjpzvtTe17UAxtcvsfCx9ecjvJhLOdIsOA4NEu5yGnYWZDpzSuq ogQcohhvcEWfcxFwBV+Qb6VpqMa/u26byAh/ndrylobVDW7CMvrT4ZWNrCPzhDCH2BfC 2Ettwn3Cz/iacf9u40HtYwEvypcIty8WSiHoiK4VpvpOa1FLEf+a12M1kHuN8c9t8kol Y+3UxrIRTe8jo2txpTe6WMB1R8OEcQNEvXQ6dFCANBsBsn8sDP7mk0muQ5tILiUoIapG meWcRqyIc3pUZV3ZN4reaWjTkiCKcctpgFDAMmR40eQN1TXFfksu/dHxMCV/AfU9KlYd ZtVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W5cSoZPW; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si21431321jav.115.2021.06.21.01.32.52; Mon, 21 Jun 2021 01:33:04 -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=@gmail.com header.s=20161025 header.b=W5cSoZPW; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230495AbhFUIeQ (ORCPT + 99 others); Mon, 21 Jun 2021 04:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbhFUIeA (ORCPT ); Mon, 21 Jun 2021 04:34:00 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2289FC061767; Mon, 21 Jun 2021 01:31:46 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id f70so28270562qke.13; Mon, 21 Jun 2021 01:31:46 -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=Tw9zlghNP2lMtvkjF+jXIw8cIb9CfadeHddyDj+bDlp8L1NR56Vu8Q1QXv/6RYZRnZ skAjWuFY3G7KJVz0bbQhoZRB/APyVzT4NLrhUXkyaY9S3kvICJV9GfE9G7w7AqFECAGd AUJdC6+nmLLmlcdFhDKpnVLwDl7RoT9LPxBzATX8tmg8DSBiO5r2YSV1fBXSbbIGFROA 5YIc2MsLz2PDY/jBkLYERKNBfTuon+dXhygu6BzfYfa0j41EQQ1dwBZmKMU3zZRTpCoP ogr2KyJSZdXQFtVgGNwTHRu/bSYHfcCYqI0xP2BRtKkNa6Jz498kfgEhiseBoTpiDiT6 0wlA== X-Gm-Message-State: AOAM531DUBFbQVhkm4fOPzeoC5Q7PKpGI/h7PlqN5+gmkXlvw5k9qkak /kFEBK/u9TSlNhWe8WQiWSA= 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> 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 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++) -- 2.17.1