Skip to content

Commit

Permalink
mm/damon/dbgfs: export kdamond pid to the user space
Browse files Browse the repository at this point in the history
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.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: SeongJae Park <[email protected]>
Reviewed-by: Fernand Sieber <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Amit Shah <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Brendan Higgins <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Fan Du <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Greg Thelen <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Leonard Foerster <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Markus Boehme <[email protected]>
Cc: Maximilian Heyne <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Steven Rostedt (VMware) <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
sj-aws authored and torvalds committed Sep 8, 2021
1 parent 4bc0595 commit 429538e
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions mm/damon/dbgfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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;
Expand All @@ -258,10 +284,17 @@ static const struct file_operations target_ids_fops = {
.write = dbgfs_target_ids_write,
};

static const struct file_operations kdamond_pid_fops = {
.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++)
Expand Down

0 comments on commit 429538e

Please sign in to comment.