Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp467480pxf; Thu, 8 Apr 2021 06:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfhfC5nmDCILOFncvT3ROfvwxihuM7ZuaqN4vPmJ2lW9CRAt8klT18Wiu4iFk9b0i2gEUy X-Received: by 2002:a05:6402:26d3:: with SMTP id x19mr11607056edd.349.1617889892595; Thu, 08 Apr 2021 06:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617889892; cv=none; d=google.com; s=arc-20160816; b=sVDOP1ZTHSjqwP1GwgQWsqFoZu5Wf6of+DvRsZDiC1xOZNqx5exDrTU3vvw80ADYBl y55bYhxbjBGcCDjltN4UrW8afRJOd5nAlM+YX/Itr9PkhO6htazcqaq1Fz9vVrzuMiN3 G5U6b8cFQWRT/FavY/r7NLHfRmLqWFFW0fwTG5TeCnaHnpzlSwgu+oLVs9bIjrT9n+pc 0Kj/HfcXCMHXCMJVpOfFs3jtIJTN6JeC/5yau35Fr5kpInAmzAd+XQn7AlzuONx1+vlB CfZdPLR3Es+7iLotSt9g6wsoSKB58GyA98MnmXHatsr+H+qjG0zc4wGjUtkaDAe8raab Cwpg== 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=dsfUiNEtUfgASDGDNGVkgQgo9ssjMF6aUvvvoPabB6I=; b=0OVdcEXljE1KhImLz9pyfAfW0pUMG0kSuy0gkosx+ZKNW3HN/gkvX/tw1RB7NzVW/f HPJzIcQaF+INJoquietC/PYwJfHaj8K64lxUhoYPsQImW+ROJ+acsW6Zxk68eZA79bqI G4OGHGljMKasutub/6eiGrIskN2/ND+ZlixrThwOL1hvoTyRPDrOegSsswEfpBndEW/W 7yK6UUiTnBnIITvBdaXaZQCM9Yf3vr2xL6sDS7ePBF5eHNvNZdIMCP5r+db6MLsP/Z6Z 6LzhjnG1CCt2W3g+SodFWr9q+lKM+nhmShS+iqqEpFcramfiT74xDDxYb8ehPBgeQaR9 NK1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pNwd5y5l; 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 e6si12326170edv.376.2021.04.08.06.51.06; Thu, 08 Apr 2021 06:51:32 -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=pNwd5y5l; 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 S231852AbhDHNuD (ORCPT + 99 others); Thu, 8 Apr 2021 09:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231795AbhDHNti (ORCPT ); Thu, 8 Apr 2021 09:49:38 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2737C0613DA; Thu, 8 Apr 2021 06:49:25 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id c6so1422103qtc.1; Thu, 08 Apr 2021 06:49:25 -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=dsfUiNEtUfgASDGDNGVkgQgo9ssjMF6aUvvvoPabB6I=; b=pNwd5y5lu37bj5Be+5mulhAmZ1VSddSiMq2ZmCZbcb+XCLkSLM+h4FOQERy8Bl8auU uRF7V+W4wFtM5T8Pg7ciCa9MTW8kdgJubnoDofIEqJ2k2gF90VPgOXN8c5PvkH7rwHRc T7v/XT4Zi1zWcOL1R5w5/K3e+iwd7IY/1S3E/W4CuNuwfSFS1p1rLRHAdynBGIy6/nV6 YtvfZlHKUWlSAYLYNVZMDcZQ+xkrBOfVdWtwJMaBHkMK8PtangkrTSYABkj1Cd8cykDL sIH1R62/257PVGtSbx809oR7KCnrPq2WLnD0X9ZmDTaq66fGkbd66vMl+yQsqWmNqh/M jjSQ== 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=dsfUiNEtUfgASDGDNGVkgQgo9ssjMF6aUvvvoPabB6I=; b=gZzf5cTtkKsDjIknn/XXx4HVPpFzjH476Vb0Y3mbgOa/9x4TeqnzIDi31sxHKxfCBm qC7Si+hpriXeO9SgUMRZ/+V7A+hcx6MuGnKZlo41op9rnJiY3C6TTq0DjRSqP0ftHGFk zcd4B9hlhmvg6KgESZHxBeGXV/qJdJeMbcmlleGLRvhjWgGUtW2vGyOH66Y9bTNUO84U Odys0o9HUI5cbhmrPKuikcXcR9qOJ3lofeFlQTkpx0f2dFgByWRtfM/bOJdFvTDicysL 0PKi2EaLWE1IOecgTlnrQIdudt7SQ8BpyEklp1KYF8BcPwTgR6QxC+gqmkS3A2yDpRmy i4rA== X-Gm-Message-State: AOAM531f1hf8Sz86EktuhLE5sjUwdbhC8I/ZmHZpbW2PVi9ha55zXQ8P QOlnZpYXmKUL4/fuSsH2ooI= X-Received: by 2002:ac8:6f0b:: with SMTP id g11mr7540132qtv.12.1617889764938; Thu, 08 Apr 2021 06:49:24 -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 h16sm506094qkh.18.2021.04.08.06.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 06:49:24 -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 v27 08/13] mm/damon/dbgfs: Export kdamond pid to the user space Date: Thu, 8 Apr 2021 13:48:49 +0000 Message-Id: <20210408134854.31625-9-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210408134854.31625-1-sj38.park@gmail.com> References: <20210408134854.31625-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 9af844faffd4..b20c1e7742ce 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++) -- 2.17.1