* [PATCH] mm/damon: improve damon_new_region strategy
@ 2022-09-12 14:39 Dawei Li
2022-09-12 19:26 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Dawei Li @ 2022-09-12 14:39 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Dawei Li
Kdamond is implemented as a periodical split-merge pattern, which will
create and destroy regions possibly on high frequency(hundreds or even
thousands of per sec), depending on number of regions and aggregation
period. In that case, kmalloc and kfree could bring considerable overhead
to system, which can be improved by private kmem cache.
Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
mm/damon/core.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 029ae384e6ff..0b1eb945c68a 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -29,6 +29,8 @@ static bool running_exclusive_ctxs;
static DEFINE_MUTEX(damon_ops_lock);
static struct damon_operations damon_registered_ops[NR_DAMON_OPS];
+static struct kmem_cache *damon_region_cache __ro_after_init;
+
/* Should be called under damon_ops_lock with id smaller than NR_DAMON_OPS */
static bool __damon_is_registered_ops(enum damon_ops_id id)
{
@@ -119,7 +121,7 @@ struct damon_region *damon_new_region(unsigned long start, unsigned long end)
{
struct damon_region *region;
- region = kmalloc(sizeof(*region), GFP_KERNEL);
+ region = kmem_cache_alloc(damon_region_cache, GFP_KERNEL);
if (!region)
return NULL;
@@ -148,7 +150,7 @@ static void damon_del_region(struct damon_region *r, struct damon_target *t)
static void damon_free_region(struct damon_region *r)
{
- kfree(r);
+ kmem_cache_free(damon_region_cache, r);
}
void damon_destroy_region(struct damon_region *r, struct damon_target *t)
@@ -1279,4 +1281,18 @@ bool damon_find_biggest_system_ram(unsigned long *start, unsigned long *end)
return true;
}
+static int __init damon_init(void)
+{
+ damon_region_cache = kmem_cache_create("damon_region_cache", sizeof(struct damon_region),
+ 0, 0, NULL);
+ if (unlikely(!damon_region_cache)) {
+ pr_err("creating damon_region_cache fails\n");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+subsys_initcall(damon_init);
+
#include "core-test.h"
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mm/damon: improve damon_new_region strategy
2022-09-12 14:39 [PATCH] mm/damon: improve damon_new_region strategy Dawei Li
@ 2022-09-12 19:26 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-09-12 19:26 UTC (permalink / raw)
To: Dawei Li; +Cc: sj, damon, linux-mm, linux-kernel
On Mon, 12 Sep 2022 22:39:03 +0800 Dawei Li <set_pte_at@outlook.com> wrote:
> Kdamond is implemented as a periodical split-merge pattern, which will
> create and destroy regions possibly on high frequency(hundreds or even
> thousands of per sec), depending on number of regions and aggregation
> period. In that case, kmalloc and kfree could bring considerable overhead
> to system, which can be improved by private kmem cache.
>
A dedicated slab cache should be faster and will also consume less
memory, due to better packing into the underlying pages. So I redid
the changelog thusly:
: Kdamond is implemented as a periodical split-merge pattern, which will
: create and destroy regions possibly at high frequency (hundreds or even
: thousands of per sec), depending on the number of regions and aggregation
: period. In that case, kmalloc and kfree could bring speed and space
: overheads, which can be improved by using a private kmem cache.
> +static int __init damon_init(void)
> +{
> + damon_region_cache = kmem_cache_create("damon_region_cache", sizeof(struct damon_region),
Should be able to use just
damon_region_cache = KMEM_CACHE(damon_region, 0);
here. Please test that and send along a fixup patch?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-12 19:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-12 14:39 [PATCH] mm/damon: improve damon_new_region strategy Dawei Li
2022-09-12 19:26 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).