From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C58D734DCE3; Wed, 13 May 2026 04:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778645288; cv=none; b=nRgvoOJAKCIrlUcgCnKKQa6JN/D5MolJ9B3NAEU3GrjRzz0gt3N6JQ3w3Zdgy7uOb2vHCKuWbEKO8SEZ1waeJNIVuwKfVA/vfQg+E9fCjQvpDa+c0oIpXG/rgE6FQ1vIhbFQXsNitDpTMsNZ/rA6ClwLtrJD7L8N6EV9uCLdtnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778645288; c=relaxed/simple; bh=pskt4SQo2C/PgtW2BSSxb7f/T696oOXHRieAM0PAiUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NKONFiVLyZ0cNL6pY7jOF3LXJ4wuOOqYgYsF7tPBXW8Luwmf5EA2RWTbUHDMu2Hd9gT+qGcCgOh61Zsx6W0IT9eBYaBD9+1K5B6TUYaJEhqmxZZxzdt97fzGpA6yFRDJFDtj5Y5tQemyVOAJrHihzrr90F2/bf+WdbIAMSqhdH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TzLAlEcE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TzLAlEcE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C618C2BCC7; Wed, 13 May 2026 04:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778645288; bh=pskt4SQo2C/PgtW2BSSxb7f/T696oOXHRieAM0PAiUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TzLAlEcEkJbbyb7oLDpACVpQttKnmbbkpV7y21eZ74qlfLUQC+osvM0b+LyzXtgNM pv2bHjLtvrMqfFXOq8+S9LiISIuvM9jJUBYyV7CNHPXgDDkvo03tfBcAtRwQ+AUfDN QpI/aQZWrI8QR+EHRux/4KXtw3hiy4mGezcMOMi58mzRVuf8c+TqBMFBC3NIisqb6X JCHfUgYbHfI17HsuP0Y0Qw/lqoDWpf6HwjsQ1PINKZa/K2I6ERadaHO7PYnfESPnKA iAhZPIFAtODdkQePDbasl8ZkUJbtPa4FiuFL09NAjvvKbY02XdLClyJyek6pP21eOY pxZ+n1MJE/VLA== From: SeongJae Park To: stable@vger.kernel.org Cc: SeongJae Park , damon@lists.linux.dev, Andrew Morton Subject: [PATCH 6.12.y 1/2] mm/damon/core: implement damon_kdamond_pid() Date: Tue, 12 May 2026 21:07:31 -0700 Message-ID: <20260513040734.144259-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <2026051241-thievish-uncurious-73fe@gregkh> References: <2026051241-thievish-uncurious-73fe@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Andrew Morton (cherry picked from commit 4262c53236977de3ceaa3bf2aefdf772c9b874dd) Signed-off-by: SeongJae Park --- The second patch depends on this commit, so porting this together. include/linux/damon.h | 1 + mm/damon/core.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index a67f2c4940e94..77f8f05cf26fb 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -778,6 +778,7 @@ static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); +int damon_kdamond_pid(struct damon_ctx *ctx); int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index d817484608614..75d391b4ad72f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1163,6 +1163,23 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs) return err; } +/** + * damon_kdamond_pid() - Return pid of a given DAMON context's worker thread. + * @ctx: The DAMON context of the question. + * + * Return: pid if @ctx is running, negative error code otherwise. + */ +int damon_kdamond_pid(struct damon_ctx *ctx) +{ + int pid = -EINVAL; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) + pid = ctx->kdamond->pid; + mutex_unlock(&ctx->kdamond_lock); + return pid; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ -- 2.47.3