From nobody Sat Feb 7 21:08:14 2026 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 70B4E3ACA4E; Thu, 15 Jan 2026 15:20:53 +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=1768490453; cv=none; b=Y+zDh5ngCoBJN9MmPuevf8MuZ2yq5LzvNITZAxGBVfvB2DymtxsbSxttV6QzF127LnR7UpBKfXHHp2zliLyHnMxnoG4h6hguTdULwRIkGvMmoOogOCF06j4yGzQzrJfn0HMFU4DYrDvPYlfqTh8caZE8MA1lXeahB7MaSURn1y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490453; c=relaxed/simple; bh=1IPEhfIuLNwm0i05nT9ETMSk54stCMKIEwoga36jhG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fAOTGrwwdgL7BpjCMCsh7BbYneGqrK53+8tz1BFM8e/AowjTwpX8sMejoQWnIKtN9uXlroo4QMY7oC+d9m8hjVsKLa4TcN++DeTR0gvxIcHhcV2MUJ1Qt4Qf8t7gzhaW6dPFtBJ7dMZWmgs7oSmCaZnNwlEqPFIxo5R8+t4KI0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mmUrtir3; 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="mmUrtir3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4916C19423; Thu, 15 Jan 2026 15:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768490453; bh=1IPEhfIuLNwm0i05nT9ETMSk54stCMKIEwoga36jhG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmUrtir3+hVR4Mbud547emvQzHs+RYh7LX8xdBcT2SrKDVGqkZTAuU1EFqltZIXKl 9uAk6zpfvcfInlVcqJcJru8oasDn4gdYgO4G4oPAl8eBozA+j/SPwWxbLNygI7Vf/h zuxaqG75HrkZXQg9ffN1bfOenK3Me7Ds6xfAfDYfDg0h9A1gPs8jO/wx8c678ninhQ 9ig1Q/z/IElFee9dHwqy7wiczstggxeEOTgHwW6sdT/Bl5LdW1U7KRiLIF8B4o1XVQ YVR7JVEQxpfpQOa1jDdvFkb7l1bOePJgdXjwxStmmHabVHVz0HoCITr8ano4xV/vuv MRLxIRCfMeqTQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/5] mm/damon/core: implement damon_kdamond_pid() Date: Thu, 15 Jan 2026 07:20:41 -0800 Message-ID: <20260115152047.68415-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260115152047.68415-1-sj@kernel.org> References: <20260115152047.68415-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" '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. Signed-off-by: SeongJae Park --- 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 26fb8e90dff6..5b7ea7082134 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -972,6 +972,7 @@ bool damon_initialized(void); int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); bool damon_is_running(struct damon_ctx *ctx); +int damon_kdamond_pid(struct damon_ctx *ctx); =20 int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); diff --git a/mm/damon/core.c b/mm/damon/core.c index 729a5f7fac94..81b998d32074 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1442,6 +1442,23 @@ bool damon_is_running(struct damon_ctx *ctx) return running; } =20 +/** + * damon_kdamond_pid() - Return pid of a given DAMON context's worker thre= ad. + * @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 =3D -EINVAL; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) + pid =3D ctx->kdamond->pid; + mutex_unlock(&ctx->kdamond_lock); + return pid; +} + /* * damon_call_handle_inactive_ctx() - handle DAMON call request that added= to * an inactive context. --=20 2.47.3 From nobody Sat Feb 7 21:08:14 2026 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 9C9813B8BB9; Thu, 15 Jan 2026 15:20:54 +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=1768490454; cv=none; b=RO7VgDdHXWtmzJ/8PFgFSDtyvc6OJSk96eNg5bgoIuie36uhj8qgksl3220jR0hotppADXnhecak9N3eQ10P3KJfc5+xqVQWCMw1BbAfJ3aBsldauUAxQ3DYLPM17adjNtuBwXW2HKhSpwUVi8qjuTdNy+znzu9WDYPYDKIw6Ho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490454; c=relaxed/simple; bh=DxQCMUOdwfVtYBKudfkzYSOHXwwjcEpLd/GD9gGY3VI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hohVHAIGpUS17M2J+xqdo/9dRVjZQ8xtkfVRkehn9sWNQRyopeIN5lOh3VehiCCx2CqxhQzZAaPPjkaUA/NoqzQ9REwQnlrtC04qV37ExTzDq2nw1ctUzLwT/tDyJTwsUnZFaHwJnXqiMToOnnr5HudvlWWZ9ePbGENQAue5i28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tl7/Br9r; 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="Tl7/Br9r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B109C19422; Thu, 15 Jan 2026 15:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768490453; bh=DxQCMUOdwfVtYBKudfkzYSOHXwwjcEpLd/GD9gGY3VI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tl7/Br9r01iHEBaBIVHmGqZfuDwsnmz2afTYicmtxxNa6k0nRAINIxKRTLmbWaM5y 9EqRpg1QaEuJ3LknjWRWIDGuBnb9s25158SuDmf0xp9UMsYXVnkdVTnilrFX04FrcE sUQYP0cjKX/eKWotlEEoUN+waZuyjJAVdVW/h6OWPtrA3VCGtisK57ioKaSj46kDvF Y8hxeR4ciM6fHhCQhU3TpBPiiSY0cbPoo7fP5OauL48vG2q/hv8ydG4gemfK526eSA BhgV7kKdlnonPzxIVsYFu2kNWfnIjZcq4SHPDLzP5YLJs9daMS5eVmbpez6QkYgj7p xZankSgOwoVmQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/5] mm/damon/sysfs: use damon_kdamond_pid() Date: Thu, 15 Jan 2026 07:20:42 -0800 Message-ID: <20260115152047.68415-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260115152047.68415-1-sj@kernel.org> References: <20260115152047.68415-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface directly uses damon_ctx->kdamond field with manual synchronization using damon_ctx->kdamond_lock, to get the pid of the kdamond. Use a new dedicated function for the purpose, namely damon_kdamond_pid(), since that doesn't require manual and error-prone synchronization. Avoid use of kdamond_lock outside of the core. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 95fd9375a7d8..4de25708b05a 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1819,10 +1819,9 @@ static ssize_t pid_show(struct kobject *kobj, if (!ctx) goto out; =20 - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) - pid =3D ctx->kdamond->pid; - mutex_unlock(&ctx->kdamond_lock); + pid =3D damon_kdamond_pid(ctx); + if (pid < 0) + pid =3D -1; out: mutex_unlock(&damon_sysfs_lock); return sysfs_emit(buf, "%d\n", pid); --=20 2.47.3 From nobody Sat Feb 7 21:08:14 2026 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 9C6B33B5311; Thu, 15 Jan 2026 15:20:54 +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=1768490454; cv=none; b=PAadz+3C/nO/LTDn63wOfHtwesMpSTbDI6b/wRNeYGa14GkV22ros7YF3MOON/aYbn1nzAMEwKM5JjI+JJJfdeKQf3MBDZ3MzCQl+4S4hjLTTme+FCB5KT41zNkLn/RIA8EsNzn3vOt7CCKDahaDwULe+XTKlDwnBnjfE5URQGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490454; c=relaxed/simple; bh=liYSv1rqSeh/1ly0K+dN0fc398iVzhoj5D1pp/K03Sg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IGaNEhmcj/MuCitACwLsQURMU1NOSmMI9e80SGxgw4Ek60di27He76YXZkxmugWJqGTF1+lYfMaSrcj1HuDxM/9/TDPdHP8apJ9pZs6MhY8QFGEbvCsXHWUAK3EUDsyn1KMcMSDdR54ubIS14fLphHIoZECie6t7GPLnmbU6fYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qioR1czQ; 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="qioR1czQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F168C19424; Thu, 15 Jan 2026 15:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768490453; bh=liYSv1rqSeh/1ly0K+dN0fc398iVzhoj5D1pp/K03Sg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qioR1czQGcX9c+h+SaZCzzuecJqpv1iUe+Wy1oY/3VxML1KS5V64I7t1eBLplWkjS u4BJU5jaHEnsSTAZEW8SnOxVc/e6opmGtxW1UHgLGVRc56yRbftnVNia8L/YWBY5nA 6HNrsUTAIXr6QamBRrt6lItmuXz5pwMUGPvNW7ZFnKGv+B2QZS/B5ZFJWMjPsPjvhw LZkMecpkIRQSrQkpqztZo3CKInSFGkq0DqihmnRf4CtnNjwWewvlKQJxpNPPPNouGc UyyA8w4JvdPwIeDO2H86MjVcP96JzKSLIKv+f3SzwPndD6pKItG0I0Y3dwwOpjaO1o N9D2L714mndNg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/5] mm/damon/lru_sort: use damon_kdamond_pid() Date: Thu, 15 Jan 2026 07:20:43 -0800 Message-ID: <20260115152047.68415-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260115152047.68415-1-sj@kernel.org> References: <20260115152047.68415-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON_LRU_SORT directly uses damon_ctx->kdamond field with manual synchronization using damon_ctx->kdamond_lock, to get the pid of the kdamond. Use a new dedicated function for the purpose, namely damon_kdamond_pid(), since that doesn't require manual and error-prone synchronization. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 8296f984b428..bedb9134d286 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -405,7 +405,9 @@ static int damon_lru_sort_turn(bool on) err =3D damon_start(&ctx, 1, true); if (err) return err; - kdamond_pid =3D ctx->kdamond->pid; + kdamond_pid =3D damon_kdamond_pid(ctx); + if (kdamond_pid < 0) + return kdamond_pid; return damon_call(ctx, &call_control); } =20 --=20 2.47.3 From nobody Sat Feb 7 21:08:14 2026 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 9C7A73B8BB7; Thu, 15 Jan 2026 15:20:54 +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=1768490454; cv=none; b=Eib33wYwbMeUiFQMvaYgisk5ZfYuk3MD3SktGpkGfJJPbpB13HBJbcAfsx/SdKFypJ+92lEnLlzVyuc08Fl0Wt+Pk+VtGW8fp2wDMs9UNzg8GpC9eRT3DibuzRDBI7MUNItPQ0x7OJPv48Hx+SphxfIsrwV3kDktq5piRikKRN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490454; c=relaxed/simple; bh=Ta8voQ7PwaIwWi/tca9PDpVSIdwL9VUNWSGlUVLCyN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NACNy2n0oIs9NsvIFdSZ5QNUWA9r1ge4vurzwALPK5urdf4TthoWUcu2jvRwIK0w+vjahv9QwyPV5AZXvHRO/z7z0RO3gddRXMS9HNhVjLHap3A7tEhMZnesNiCSDELBQSbdGhfCgBtZddYX23nO3ivkZta95+V2yVUNwNjNwik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=auUbi4LZ; 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="auUbi4LZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92DBCC16AAE; Thu, 15 Jan 2026 15:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768490453; bh=Ta8voQ7PwaIwWi/tca9PDpVSIdwL9VUNWSGlUVLCyN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=auUbi4LZbcZY3XoZTmiuEBz9GFhg0i5IAadPhW3u5NPpvll+nU3nybYQhPjICRqrz vIEAcLAnh+2xP+WIYwOc9F9r9eWVTY0Q6hZiR7MCIk9KyFf0AAX5/BmP4OihheV/Ge JOWuHkr0tr8+AFb0hZYuKrBdyRiaSeR8HCrC9QJZQDDu7kK97Xe2cFgDe/bLc9AllJ eqsZvxCYVxF8yaeHoF9eWXr6JotDIzOVgpoZSJOZq1gQdX5SmSVgWBFgHAGYDTbGoB ksMlUXisqACVLlpzTEjbBMoZtFZIiTus8BEpVaCuBCeX1Qq6zyMkAkt+aJTovh2tXj vVywYGXmuu72w== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/5] mm/damon/reclaim: use damon_kdamond_pid() Date: Thu, 15 Jan 2026 07:20:44 -0800 Message-ID: <20260115152047.68415-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260115152047.68415-1-sj@kernel.org> References: <20260115152047.68415-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON_RECLAIM directly uses damon_ctx->kdamond field with manual synchronization using damon_ctx->kdamond_lock, to get the pid of the kdamond. Use a new dedicated function for the purpose, namely damon_kdamond_pid(), since that doesn't require manual and error-prone synchronization. Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 8463a5a5032f..55df43e241c5 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -307,7 +307,9 @@ static int damon_reclaim_turn(bool on) err =3D damon_start(&ctx, 1, true); if (err) return err; - kdamond_pid =3D ctx->kdamond->pid; + kdamond_pid =3D damon_kdamond_pid(ctx); + if (kdamond_pid < 0) + return kdamond_pid; return damon_call(ctx, &call_control); } =20 --=20 2.47.3 From nobody Sat Feb 7 21:08:14 2026 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 9C8A43B8BB8; Thu, 15 Jan 2026 15:20:54 +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=1768490454; cv=none; b=GacP3k2aJ+tRVWfyEHem4LCxQl/HSxBRa+RRWkEvPYcLUV/lnOJolhTx2iSEKyOUurR2XUElonaoUMS3zKkKJNyMk9f/DtOKoF1FC3pWfR+eFkQRgFtCXtbLrktx2AZQGBPMMM7qootKOpnbUAckUhPJMeDtBULeU6hxS3MXfyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490454; c=relaxed/simple; bh=4axDbWJSGHLGv1FOAfVefI2HSvmv3TegEZMiJ4E32WY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=maVYgdlV0+Fy7hkBxfdAg0b+lhsio6FCzQluiXFBhrnsN3IRnROokZI/LsRoBNtaH4Wd54MuWqlFYn3wV1xwTQantLTdQ99i6bpuxZQkc0K3wgtauc1/Vc4K4g2AB3iufQenT1YpnyE2zD9hT4i8+bdx3z+uSXxuUPTQy4V0pfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YKy7uMmA; 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="YKy7uMmA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C79B6C2BC86; Thu, 15 Jan 2026 15:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768490453; bh=4axDbWJSGHLGv1FOAfVefI2HSvmv3TegEZMiJ4E32WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YKy7uMmA3zHE6AvGwvQKg+fZQLbN6YxmONtC5clgQYvmX+YpYURjV9YJ8yn70Qsvn C4U0oIRN6bH8Z5E5ELBDm0Wf1MMUhLvBY4sY57+trSwAG4XA+qEiG3t6sbfG2aN8zf eHAtB0p6oQI85gkRxcpaN5d0oUdnHkKTWEdrb1UqpD2nvVs82IKjGgHY5mZIDsjbnR rZCnn95qL2y7SgKiTfOKKQby67WdDFYTAZyd0JneyajyQuIG5/sOFsm60x5Eap9Ope kpA/cYVudWbfWJx/WNNi/SEL9WoXAVH1kh5iDH0NebE3DRs+zB19yJF3mkPgNw0Lgv SoJDgbdF3GTaA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/5] mm/damon: hide kdamond and kdamond_lock of damon_ctx Date: Thu, 15 Jan 2026 07:20:45 -0800 Message-ID: <20260115152047.68415-6-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260115152047.68415-1-sj@kernel.org> References: <20260115152047.68415-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no DAMON API caller that directly access 'kdamond' and 'kdamond_lock' fields of 'struct damon_ctx'. Keeping those exposed could only encourage creative but error-prone usages. Hide them from DAMON API callers by marking those as private fields. Signed-off-by: SeongJae Park --- include/linux/damon.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 5b7ea7082134..e6930d8574d3 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -759,23 +759,20 @@ struct damon_attrs { * of the monitoring. * * @attrs: Monitoring attributes for accuracy/overhead control. - * @kdamond: Kernel thread who does the monitoring. - * @kdamond_lock: Mutex for the synchronizations with @kdamond. * - * For each monitoring context, one kernel thread for the monitoring is - * created. The pointer to the thread is stored in @kdamond. + * For each monitoring context, one kernel thread for the monitoring, name= ly + * kdamond, is created. The pid of kdamond can be retrieved using + * damon_kdamond_pid(). * - * Once started, the monitoring thread runs until explicitly required to be - * terminated or every monitoring target is invalid. The validity of the - * targets is checked via the &damon_operations.target_valid of @ops. The - * termination can also be explicitly requested by calling damon_stop(). - * The thread sets @kdamond to NULL when it terminates. Therefore, users c= an - * know whether the monitoring is ongoing or terminated by reading @kdamon= d. - * Reads and writes to @kdamond from outside of the monitoring thread must - * be protected by @kdamond_lock. + * Once started, kdamond runs until explicitly required to be terminated or + * every monitoring target is invalid. The validity of the targets is che= cked + * via the &damon_operations.target_valid of @ops. The termination can al= so be + * explicitly requested by calling damon_stop(). To know if a kdamond is + * running, damon_is_running() can be used. * - * Note that the monitoring thread protects only @kdamond via @kdamond_loc= k. - * Accesses to other fields must be protected by themselves. + * While the kdamond is running, all accesses to &struct damon_ctx from a + * thread other than the kdamond should be made using safe DAMON APIs, + * including damon_call() and damos_walk(). * * @ops: Set of monitoring operations for given use cases. * @addr_unit: Scale factor for core to ops address conversion. @@ -816,10 +813,12 @@ struct damon_ctx { struct damos_walk_control *walk_control; struct mutex walk_control_lock; =20 -/* public: */ + /* Working thread of the given DAMON context */ struct task_struct *kdamond; + /* Protects @kdamond field access */ struct mutex kdamond_lock; =20 +/* public: */ struct damon_operations ops; unsigned long addr_unit; unsigned long min_sz_region; --=20 2.47.3