Skip to content

Commit 429538e

Browse files
sj-awstorvalds
authored andcommitted
mm/damon/dbgfs: export kdamond pid to the user space
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]>
1 parent 4bc0595 commit 429538e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

mm/damon/dbgfs.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,32 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
239239
return ret;
240240
}
241241

242+
static ssize_t dbgfs_kdamond_pid_read(struct file *file,
243+
char __user *buf, size_t count, loff_t *ppos)
244+
{
245+
struct damon_ctx *ctx = file->private_data;
246+
char *kbuf;
247+
ssize_t len;
248+
249+
kbuf = kmalloc(count, GFP_KERNEL);
250+
if (!kbuf)
251+
return -ENOMEM;
252+
253+
mutex_lock(&ctx->kdamond_lock);
254+
if (ctx->kdamond)
255+
len = scnprintf(kbuf, count, "%d\n", ctx->kdamond->pid);
256+
else
257+
len = scnprintf(kbuf, count, "none\n");
258+
mutex_unlock(&ctx->kdamond_lock);
259+
if (!len)
260+
goto out;
261+
len = simple_read_from_buffer(buf, count, ppos, kbuf, len);
262+
263+
out:
264+
kfree(kbuf);
265+
return len;
266+
}
267+
242268
static int damon_dbgfs_open(struct inode *inode, struct file *file)
243269
{
244270
file->private_data = inode->i_private;
@@ -258,10 +284,17 @@ static const struct file_operations target_ids_fops = {
258284
.write = dbgfs_target_ids_write,
259285
};
260286

287+
static const struct file_operations kdamond_pid_fops = {
288+
.open = damon_dbgfs_open,
289+
.read = dbgfs_kdamond_pid_read,
290+
};
291+
261292
static void dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx)
262293
{
263-
const char * const file_names[] = {"attrs", "target_ids"};
264-
const struct file_operations *fops[] = {&attrs_fops, &target_ids_fops};
294+
const char * const file_names[] = {"attrs", "target_ids",
295+
"kdamond_pid"};
296+
const struct file_operations *fops[] = {&attrs_fops, &target_ids_fops,
297+
&kdamond_pid_fops};
265298
int i;
266299

267300
for (i = 0; i < ARRAY_SIZE(file_names); i++)

0 commit comments

Comments
 (0)