Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: implement damon_kdamond_pid()

Patch series "mm/damon: hide kdamond and kdamond_lock from API callers".

'kdamond' and 'kdamond_lock' fields initially exposed to DAMON API callers
for flexible synchronization and use cases. As DAMON API became somewhat
complicated compared to the early days, Keeping those exposed could only
encourage the API callers to invent more creative but complicated and
difficult-to-debug use cases.

Fortunately DAMON API callers didn't invent that many creative use cases.
There exist only two use cases of 'kdamond' and 'kdamond_lock'. Finding
whether the kdamond is actively running, and getting the pid of the
kdamond. For the first use case, a dedicated API function, namely
'damon_is_running()' is provided, and all DAMON API callers are using the
function for the use case. Hence only the second use case is where the
fields are directly being used by DAMON API callers.

To prevent future invention of complicated and erroneous use cases of the
fields, hide the fields from the API callers. For that, provide new
dedicated DAMON API functions for the remaining use case, namely
damon_kdamond_pid(), migrate DAMON API callers to use the new function,
and mark the fields as private fields.


This patch (of 5):

'kdamond' and 'kdamond_lock' are directly being used by DAMON API callers
for getting the pid of the corresponding kdamond. To discourage invention
of creative but complicated and erroneous new usages of the fields that
require careful synchronization, implement a new API function that can
simply be used without the manual synchronizations.

Link: https://lkml.kernel.org/r/20260115152047.68415-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20260115152047.68415-2-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
4262c532 291487b7

+18
+1
include/linux/damon.h
··· 972 972 int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); 973 973 int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); 974 974 bool damon_is_running(struct damon_ctx *ctx); 975 + int damon_kdamond_pid(struct damon_ctx *ctx); 975 976 976 977 int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); 977 978 int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
+17
mm/damon/core.c
··· 1442 1442 return running; 1443 1443 } 1444 1444 1445 + /** 1446 + * damon_kdamond_pid() - Return pid of a given DAMON context's worker thread. 1447 + * @ctx: The DAMON context of the question. 1448 + * 1449 + * Return: pid if @ctx is running, negative error code otherwise. 1450 + */ 1451 + int damon_kdamond_pid(struct damon_ctx *ctx) 1452 + { 1453 + int pid = -EINVAL; 1454 + 1455 + mutex_lock(&ctx->kdamond_lock); 1456 + if (ctx->kdamond) 1457 + pid = ctx->kdamond->pid; 1458 + mutex_unlock(&ctx->kdamond_lock); 1459 + return pid; 1460 + } 1461 + 1445 1462 /* 1446 1463 * damon_call_handle_inactive_ctx() - handle DAMON call request that added to 1447 1464 * an inactive context.