]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/damon/core: introduce damon_call_control->dealloc_on_cancel
authorSeongJae Park <sj@kernel.org>
Mon, 8 Sep 2025 20:15:12 +0000 (13:15 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:23:39 +0000 (17:23 -0700)
When damon_call_control->repeat is set, damon_call() is executed
asynchronously, and eventually be canceled when kdamond finishes.  If the
damon_call_control object is dynamically allocated, hence, finding the
place to deallocate the object is difficult.  Introduce a new
damon_call_control field, namely dealloc_on_cancel, to ask the kdamond
deallocates those dynamically allocated objects when those are canceled.

Link: https://lkml.kernel.org/r/20250908201513.60802-2-sj@kernel.org
Fixes: d809a7c64ba8 ("mm/damon/sysfs: implement refresh_ms file internal work")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Yunjeong Mun <yunjeong.mun@sk.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/damon.h
mm/damon/core.c

index f13664c62ddda5b74ab2b4a961ae61d0c510b315..9e62b2a85538da7d60c50e623ebe1fec250d3a4a 100644 (file)
@@ -636,6 +636,7 @@ struct damon_operations {
  * @data:              Data that will be passed to @fn.
  * @repeat:            Repeat invocations.
  * @return_code:       Return code from @fn invocation.
+ * @dealloc_on_cancel: De-allocate when canceled.
  *
  * Control damon_call(), which requests specific kdamond to invoke a given
  * function.  Refer to damon_call() for more details.
@@ -645,6 +646,7 @@ struct damon_call_control {
        void *data;
        bool repeat;
        int return_code;
+       bool dealloc_on_cancel;
 /* private: internal use only */
        /* informs if the kdamond finished handling of the request */
        struct completion completion;
index c2e0b469fd43271afd4fe2bc412e80b63d93b565..08065b3639722474362a33f5997a390d7cc64cc6 100644 (file)
@@ -2479,10 +2479,14 @@ static void kdamond_call(struct damon_ctx *ctx, bool cancel)
                mutex_lock(&ctx->call_controls_lock);
                list_del(&control->list);
                mutex_unlock(&ctx->call_controls_lock);
-               if (!control->repeat)
+               if (!control->repeat) {
                        complete(&control->completion);
-               else
+               } else if (control->canceled && control->dealloc_on_cancel) {
+                       kfree(control);
+                       continue;
+               } else {
                        list_add(&control->list, &repeat_controls);
+               }
        }
        control = list_first_entry_or_null(&repeat_controls,
                        struct damon_call_control, list);