Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2855541pxb; Tue, 13 Apr 2021 11:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5UnWMXNLFjy3J1wUJ6iYS/81X1Jxjx0iIt3RIuQEWlwxhZD9tiDyrwbeghQH00uYNO7E/ X-Received: by 2002:a63:3ecb:: with SMTP id l194mr33694564pga.146.1618339862245; Tue, 13 Apr 2021 11:51:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618339862; cv=none; d=google.com; s=arc-20160816; b=uMA8tZcM65IniCLQxb9RPvFQyyBpf+gNeCyq6W9fEHItOS8KCcSQc9HoxrWC22PuQM Y3Hj0TaOQht7Nu/Kx7gYpqMq5pCp47HXmApZgMwHTyY5DaFO08GC94FgLPyZObg9mqKj EuEpdBzd74A+HvNxMU+hBNgXBjlyFT/U9P5ULX4ip/Es53zszB43asyRcHih0+yCGHcR cfMwJAEwo2OeJVPmQ8ZYtzMmPkvC+WeLRmzQ/tW/DBEY99GcuWcc1gvkc+WZdTIYu6id VQ8ndj1Tt9sRK8020Dcd1/EEXwUstaWFgMr+O3BJnWmtfwsZ5lUPrvbfEdkYT+MDRhH7 VdLQ== 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=eYTdxL2E49yq4b0Ub99eMeKNygqCtQlWSQ8UNjQ6vgA=; b=Ct3UC651ISsHzlQzE8muWiM43XXupsCCmvbtmqxHl4vrCz+FJIMjgatHxxC1SO+myI abRYzbmS7AvxD49AiDCDE5+LF2tYSob4/bBgBi8lk5LvwWcVK71lnWPHUBEtUFEQjaRZ wBPD+u6/fKrfp6Igm820hY48OtK2EjsOfNlklLvsd66IBKhoPPBvSI6WsBzcZSfiD6x1 ez9hxpSnn+SZ3ZTo6iHJEKiJthQZK9qo3S28/qpsXNJq8tVzMyJ59sNImIPZAbm02rGZ wBTRS5ZEhC8TN29Es3Zt++ocL+Ar8TRY6rVpZBrQEANpPE1Acv48+TWjIkHxr6haNqdj Tr5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Wz8kRlNr; 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 j64si2478994pfd.161.2021.04.13.11.50.48; Tue, 13 Apr 2021 11:51:02 -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=Wz8kRlNr; 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 S239201AbhDMOar (ORCPT + 99 others); Tue, 13 Apr 2021 10:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238505AbhDMO34 (ORCPT ); Tue, 13 Apr 2021 10:29:56 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DC08C06138C; Tue, 13 Apr 2021 07:29:35 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id 18so1147730qkl.3; Tue, 13 Apr 2021 07:29:35 -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=eYTdxL2E49yq4b0Ub99eMeKNygqCtQlWSQ8UNjQ6vgA=; b=Wz8kRlNr4zj9Wxg3LJJXUtaqyTxuCR5hEZ//Hpw6L2z+VO641agxv0ky6VroYNJXM3 hFEn3rtK8m8eMGPclor2d8elOgrV9O+kZfn6XAR8SHqDrvcaDBU/YpnvAQYBbEOCdH3J x4nsQyZegO/jBr4MTsVt/6Sz2Py+qIQhOmiQsHLwFBWW2kGpaVSpOKO5AHJ78ihX0KG2 NrsUySVuck0nlJN25eInOl3+RbV2YsQ21dF/e7atfNcWiOZK64jaKFeHeE0L8yi8ZZ9V qgYtxadBmATKZOHJXAEXPMmo2YFi11D/nuiAnUafPoyUGTIzjRoUcQK3Aid7+icpMcme G9Zw== 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=eYTdxL2E49yq4b0Ub99eMeKNygqCtQlWSQ8UNjQ6vgA=; b=JQ6xhS/WDKxzCH7Ef2PxHET9gOTa/Zj45N8PjJVLcDtuIkDlalfaL3M2PgWr9bsva2 2z/8vWYJ5cU0HZbbxqUKqFqEzyzNt4PR7swYVQ99pVtjZGj1Qz1LEhVIcvIX7WU3K86D uHVIox4kS0x71kMFnzivPXfh+tGWYeqrjGwuhUr4OvmS1h6k/K2/ydm7KjQ4+p6TdY8+ nM6+lLiJjJRYdCYIe/npBbEjjN/fsr2tIP4pUT17i27JVCGGWUBH6Vt54WsreHcMlK3o 5Efs/5BDGE0jIlCeyE4wdGA3j/dtsKyFfaIRJGn71DlMBDxOx4nZCHA6SKXtxeV7Kyg+ 1Bzg== X-Gm-Message-State: AOAM533TZGiCmpa74mEnPtOg2wgx3ytpaBRfl31YusoaW7lbnckmEdr5 g7Y3zhb0brAsZCH4DJ3q4mE= X-Received: by 2002:a37:64c3:: with SMTP id y186mr25700000qkb.244.1618324174723; Tue, 13 Apr 2021 07:29:34 -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 2sm6160911qko.134.2021.04.13.07.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 07:29:34 -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, 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 v28 08/13] mm/damon/dbgfs: Export kdamond pid to the user space Date: Tue, 13 Apr 2021 14:28:59 +0000 Message-Id: <20210413142904.556-9-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210413142904.556-1-sj38.park@gmail.com> References: <20210413142904.556-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 --- 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 17c7878cfcb8..67b273472c0b 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