DAMON: Improve User Space Interface
Subsystems (3)
cover DAMON: Improve User Space Interface
From: SeongJae Park <[email protected]>
NOTE: This is only an RFC for future features of DAMON patchset[1], which is not merged in the mainline yet. The aim of this RFC is to show how DAMON would be evolved once it is merged in. So, if you have some interest in this RFC, please consider reviewing the DAMON patchset, either.
After posting DAMON patchset[1], we received a number of comments. Based on those, we listed and shared future works for DAMON in the kernel summit 2020[2] and had a poll for the priorities of the works. As a result, the user space interface improvement received a second highest priority[3]. For the reason, this patchset is came out.
The 1st patch puts more information in the monitoring thread name so that user space could charge the DAMON's CPU usage on them by themselves, in fine granularity. The 2nd patch makes multiple monitoring contexts available using the debugfs interface.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://linuxplumbersconf.org/event/7/contributions/659/
[3] https://lore.kernel.org/linux-mm/[email protected]/
Baseline and Complete Git Trees
===============================
The patches are based on the v5.8 plus DAMON v20 patchset[1], RFC v14 of DAMOS patchset, RFC v8 of physical address space support patchset, and some more trivial fixes (s/snprintf/scnprintf). You can also clone the complete git tree:
$ git clone git://github.com/sjp38/linux -b damon-usi/rfc/v1
The web is also available:
https://github.com/sjp38/linux/releases/tag/damon-usi/rfc/v1
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
[3] https://lore.kernel.org/linux-mm/[email protected]/
SeongJae Park (2):
mm/damon: Put more information in kdamond thread name mm/damon/debugfs: Support multiple contexts
include/linux/damon.h | 2 + mm/damon-test.h | 34 ++-- mm/damon.c | 361 +++++++++++++++++++++++++++++++++--------- 3 files changed, 308 insertions(+), 89 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH 1/2 mm/damon: Put more information in kdamond thread name
From: SeongJae Park <[email protected]>
While multiple kdamond threads can run, it is hard to distinguish each thread as all kdamond threads has same name, 'kdamond'. This commit puts more information including if it is spawned from the user context (via the debugfs interface) and for what context it is running. The format of the name is:
kdamond.<current pid>.<# of context>
If it is not spawned from the user context, <current pid> becomes 0. Using this information, for example, the user space could easily account CPU usage of DAMON that they requested in fine granularity.
--- mm/damon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/damon.c +4 -1
@@ -1552,6 +1552,8 @@ static bool damon_kdamond_running(struct damon_ctx *ctx)* __damon_start() - Starts monitoring with given context. * @ctx: monitoring context * +* This function should be called while damon_lock is hold. +* * Return: 0 on success, negative error code otherwise. */ static int __damon_start (struct damon_ctx *ctx)
@@ -1562,7 +1564,8 @@ static int __damon_start(struct damon_ctx *ctx)if (!ctx->kdamond) { err =0 ; ctx->kdamond_stop = false; - ctx->kdamond =kthread_create (kdamond_fn, ctx,"kdamond" ); + ctx->kdamond =kthread_create (kdamond_fn, ctx,"kdamond.%d.%d" , + current ? current->pid :0 , nr_running_ctxs);if (IS_ERR (ctx->kdamond)) err =PTR_ERR (ctx->kdamond);else
Signature · 1 line
2.17.1
cover DAMON: Improve User Space Interface
From: SeongJae Park <[email protected]>
Seems lore.kernel.org missed original posting of this mail. Resending.
NOTE: This is only an RFC for future features of DAMON patchset[1], which is not merged in the mainline yet. The aim of this RFC is to show how DAMON would be evolved once it is merged in. So, if you have some interest in this RFC, please consider reviewing the DAMON patchset, either.
After posting DAMON patchset[1], we received a number of comments. Based on those, we listed and shared future works for DAMON in the kernel summit 2020[2] and had a poll for the priorities of the works. As a result, the user space interface improvement received a second highest priority[3]. For the reason, this patchset is came out.
The 1st patch puts more information in the monitoring thread name so that user space could charge the DAMON's CPU usage on them by themselves, in fine granularity. The 2nd patch makes multiple monitoring contexts available using the debugfs interface.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://linuxplumbersconf.org/event/7/contributions/659/
[3] https://lore.kernel.org/linux-mm/[email protected]/
Baseline and Complete Git Trees
===============================
The patches are based on the v5.8 plus DAMON v20 patchset[1], RFC v14 of DAMOS patchset, RFC v8 of physical address space support patchset, and some more trivial fixes (s/snprintf/scnprintf). You can also clone the complete git tree:
$ git clone git://github.com/sjp38/linux -b damon-usi/rfc/v1
The web is also available:
https://github.com/sjp38/linux/releases/tag/damon-usi/rfc/v1
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
[3] https://lore.kernel.org/linux-mm/[email protected]/
SeongJae Park (2):
mm/damon: Put more information in kdamond thread name mm/damon/debugfs: Support multiple contexts
include/linux/damon.h | 2 + mm/damon-test.h | 34 ++-- mm/damon.c | 361 +++++++++++++++++++++++++++++++++--------- 3 files changed, 308 insertions(+), 89 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH 2/2 mm/damon/debugfs: Support multiple contexts
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
DAMON allows the programming interface users to run monitoring with multiple contexts. This could be useful in some cases. For example, if someone want to do highly accurate monitoring and lots of CPUs are available, splitting the monitoring target regions into multiple small regions and allocating context (monitoring thread) to each small region could be helpful. Or, someone could need to monitor different types of address spaces simultaneously.
However, it's impossible from the user space because the DAMON debugfs interface supports only single context. This commit makes it available by implementing 'nr_contexts' debugfs file.
Users can pass the number (N) of contexts they want to use to the file. Then, N folders having name of 'ctx<1-(N-1)>' are created in the DAMON debugfs dir. Each of the directory is associated with the contexts and contains the the files for context setting (attrs, init_regions, record, schemes, and target_ids). The first context related files are still in the DAMON debugfs root directory, though.
--- include/linux/damon.h | 2 + mm/damon-test.h | 34 ++-- mm/damon.c | 356 +++++++++++++++++++++++++++++++++--------- 3 files changed, 304 insertions(+), 88 deletions(-)
include/linux/damon.h +2 -0
@@ -259,5 +259,7 @@ int damon_set_recording(struct damon_ctx *ctx, unsigned int rbuf_len, char *rfile_path);int damon_start (struct damon_ctx *ctxs,int nr_ctxs);int damon_stop (struct damon_ctx *ctxs,int nr_ctxs); +int damon_start_ctx_ptrs (struct damon_ctx **ctxs,int nr_ctxs); +int damon_stop_ctx_ptrs (struct damon_ctx **ctxs,int nr_ctxs);#endif
mm/damon-test.h +17 -17
@@ -102,14 +102,14 @@ static void damon_test_regions(struct kunit *test)static void damon_test_target (struct kunit *test) { -struct damon_ctx *c = &damon_user_ctx; +struct damon_ctx *c = debugfs_ctxs[0 ];struct damon_target *t; t =damon_new_target (42 );KUNIT_EXPECT_EQ (test,42ul , t->id);KUNIT_EXPECT_EQ (test,0u ,nr_damon_targets (c)); -damon_add_target (&damon_user_ctx, t); +damon_add_target (c, t);KUNIT_EXPECT_EQ (test,1u ,nr_damon_targets (c));damon_destroy_target (t);
@@ -118,7 +118,7 @@ static void damon_test_target(struct kunit *test)static void damon_test_set_targets (struct kunit *test) { -struct damon_ctx *ctx = &damon_user_ctx; +struct damon_ctx *ctx = debugfs_ctxs[0 ];unsigned long ids[] = {1 ,2 ,3 };char buf[64 ];
@@ -148,7 +148,7 @@ static void damon_test_set_targets(struct kunit *test)static void damon_test_set_recording (struct kunit *test) { -struct damon_ctx *ctx = &damon_user_ctx; +struct damon_ctx *ctx = debugfs_ctxs[0 ];int err; err =damon_set_recording (ctx,42 ,"foo" );
@@ -163,7 +163,7 @@ static void damon_test_set_recording(struct kunit *test)static void damon_test_set_init_regions (struct kunit *test) { -struct damon_ctx *ctx = &damon_user_ctx; +struct damon_ctx *ctx = debugfs_ctxs[0 ];unsigned long ids[] = {1 ,2 ,3 };/* Each line represents one region in ``<target id> <start> <end>`` */ char *const valid_inputs[] = {"2 10 20\n 2 20 30\n2 35 45" ,
@@ -299,10 +299,10 @@ static void damon_cleanup_global_state(void) {struct damon_target *t, *next; -damon_for_each_target_safe (t, next, &damon_user_ctx) +damon_for_each_target_safe (t, next, debugfs_ctxs[0 ])damon_destroy_target (t); - damon_user_ctx.rbuf_offset =0 ; + debugfs_ctxs[0 ]->rbuf_offset =0 ; }/*
@@ -317,7 +317,7 @@ static void damon_cleanup_global_state(void)*/ static void damon_test_aggregate (struct kunit *test) { -struct damon_ctx *ctx = &damon_user_ctx; +struct damon_ctx *ctx = debugfs_ctxs[0 ];unsigned long target_ids[] = {1 ,2 ,3 };unsigned long saddr[][3 ] = {{10 ,20 ,30 }, {5 ,42 ,49 }, {13 ,33 ,55 } };unsigned long eaddr[][3 ] = {{15 ,27 ,40 }, {31 ,45 ,55 }, {23 ,44 ,66 } };
@@ -367,10 +367,10 @@ static void damon_test_aggregate(struct kunit *test)static void damon_test_write_rbuf (struct kunit *test) { -struct damon_ctx *ctx = &damon_user_ctx; +struct damon_ctx *ctx = debugfs_ctxs[0 ];char *data; -damon_set_recording (&damon_user_ctx,4242 ,"damon.data" ); +damon_set_recording (debugfs_ctxs[0 ],4242 ,"damon.data" ); data ="hello" ;damon_write_rbuf (ctx, data,strnlen (data,256 ));
@@ -380,7 +380,7 @@ static void damon_test_write_rbuf(struct kunit *test)KUNIT_EXPECT_EQ (test, ctx->rbuf_offset,5u );KUNIT_EXPECT_STREQ (test, (char *)ctx->rbuf, data); -damon_set_recording (&damon_user_ctx,0 ,"damon.data" ); +damon_set_recording (debugfs_ctxs[0 ],0 ,"damon.data" ); }static struct damon_region *__nth_region_of (struct damon_target *t,int idx)
@@ -432,9 +432,9 @@ static void damon_do_test_apply_three_regions(struct kunit *test, r =damon_new_region (regions[i *2 ], regions[i *2 +1 ]);damon_add_region (r, t); } -damon_add_target (&damon_user_ctx, t); +damon_add_target (debugfs_ctxs[0 ], t); -damon_apply_three_regions (&damon_user_ctx, t, three_regions); +damon_apply_three_regions (debugfs_ctxs[0 ], t, three_regions);for (i =0 ; i < nr_expected /2 ; i++) { r =__nth_region_of (t, i);
@@ -541,7 +541,7 @@ static void damon_test_apply_three_regions4(struct kunit *test)static void damon_test_split_evenly (struct kunit *test) { -struct damon_ctx *c = &damon_user_ctx; +struct damon_ctx *c = debugfs_ctxs[0 ];struct damon_target *t;struct damon_region *r;unsigned long i;
@@ -601,7 +601,7 @@ static void damon_test_split_at(struct kunit *test) t =damon_new_target (42 ); r =damon_new_region (0 ,100 );damon_add_region (r, t); -damon_split_region_at (&damon_user_ctx, r,25 ); +damon_split_region_at (debugfs_ctxs[0 ], r,25 );KUNIT_EXPECT_EQ (test, r->ar.start,0ul );KUNIT_EXPECT_EQ (test, r->ar.end,25ul );
@@ -679,14 +679,14 @@ static void damon_test_split_regions_of(struct kunit *test) t =damon_new_target (42 ); r =damon_new_region (0 ,22 );damon_add_region (r, t); -damon_split_regions_of (&damon_user_ctx, t,2 ); +damon_split_regions_of (debugfs_ctxs[0 ], t,2 );KUNIT_EXPECT_EQ (test,nr_damon_regions (t),2u );damon_free_target (t); t =damon_new_target (42 ); r =damon_new_region (0 ,220 );damon_add_region (r, t); -damon_split_regions_of (&damon_user_ctx, t,4 ); +damon_split_regions_of (debugfs_ctxs[0 ], t,4 );KUNIT_EXPECT_EQ (test,nr_damon_regions (t),4u );damon_free_target (t); }
mm/damon.c +285 -71
534 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH 2/2] mm/damon/debugfs: Support multiple contexts
Quoted 11 lines · SeongJae Park
From: SeongJae Park <[email protected]>
DAMON allows the programming interface users to run monitoring with multiple contexts. This could be useful in some cases. For example, if someone want to do highly accurate monitoring and lots of CPUs are available, splitting the monitoring target regions into multiple small regions and allocating context (monitoring thread) to each small region could be helpful. Or, someone could need to monitor different types of address spaces simultaneously.
Quoted 5 lines
However, it's impossible from the user space because the DAMON debugfs interface supports only single context. This commit makes it available by implementing '
nr_contexts' debugfs file.Users can pass the number (N) of contexts they want to use to the file.
Why not just mkdir which will create a new context?
Quoted 4 lines
Then, N folders having name of 'ctx<1-(N-1)>' are created in the DAMON debugfs dir. Each of the directory is associated with the contexts and contains the the files for context setting (attrs,
init_regions, record, schemes, andtarget_ids).
Also instead of naming the kthread with context number why not give the kthread pids through attrs (or new interface) and the admin can move those kthreads to the cgroup they want to charge against?
Quoted 5 lines
The first context related files are still in
the DAMON debugfs root directory, though.Signed-off-by SeongJae Park <[email protected]>---
Re: [RFC PATCH 2/2] mm/damon/debugfs: Support multiple contexts
Quoted 12 lines · On Wed, 16 Sep 2020 09:11:18 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 11 lines · SeongJae Park
From: SeongJae Park <[email protected]>
DAMON allows the programming interface users to run monitoring with multiple contexts. This could be useful in some cases. For example, if someone want to do highly accurate monitoring and lots of CPUs are available, splitting the monitoring target regions into multiple small regions and allocating context (monitoring thread) to each small region could be helpful. Or, someone could need to monitor different types of address spaces simultaneously.
Quoted 7 lines
Quoted 5 lines
However, it's impossible from the user space because the DAMON debugfs interface supports only single context. This commit makes it available by implementing '
nr_contexts' debugfs file.Users can pass the number (N) of contexts they want to use to the file.
Why not just mkdir which will create a new context?
Because I referenced the naming rule of zram and because I just wanted to make this as simple as possible. I find no special functional difference between current way and you suggested way.
That said, I also think you suggested way is much more flexible. I will try to make this in that way.
Quoted 9 lines
Quoted 5 lines
Then, N folders having name of 'ctx<1-(N-1)>' are created in the DAMON debugfs dir. Each of the directory is associated with the contexts and contains the the files for context setting (attrs,
init_regions, record, schemes, andtarget_ids).Also instead of naming the kthread with context number why not give the kthread pids through attrs (or new interface) and the admin can move those kthreads to the cgroup they want to charge against?
Again, I just wanted to make this as simple as possible, and I also referenced blkback thread naming. And I find no special functional difference here, either.
And yes, I think you suggested way is much more flexible and easy to be used. I will make this in that way.
---
Just a note (not for only Shakeel, but anyone who interested in DAMON). The DAMON debugfs interface is not highly coupled with DAMON. Rather than that, it is implemented as an application using DAMON as a framework via the DAMON's kernel space interface. This means that anyone who want different user space interface can implement their own on top of the framework. I will try to make the changes as soon as possible, but if you cannot wait until then, you could implement your own.
Similarly, DAMON lacks many functionality such as support of special address spaces. I already have a TODO list. And I will implement those one by one. So, please give me the requests. However, I believe the kernel space interface is already almost complete. Thus, almost every such future features could be implemented on top of current DAMON interface. Therefore, if you cannot wait until I finish the work, you can implement your own on DAMON's kernel space interface.
Of course, if you send the patches for your own implementations, that will make not only I, but the community happier.
And this is the reason why the patchset containing only the framework part and minimal applications / addons is titled as official 'PATCH', while the patchsets for the future features are titled 'RFC'. So, I am asking you to consider giving more attention to the framework part (the first 4 patches of the patchset[1]), as all future features will depend on it.
[1] https://lore.kernel.org/linux-mm/[email protected]/
Thanks,
SeongJae Park