From nobody Mon Feb 9 17:21:33 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 9FD9D2566ED; Mon, 10 Feb 2025 18:27:43 +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=1739212064; cv=none; b=BaAyKYYFrcwPBRv41Z7B8LNRcLdQto4bQczK2XgZPqcY8lCDQpM6PnFtQ3G4io6kC6k/DmB0XxLt/wZ/hmPOMsV53t8AZVLJ0gQPuJQzUZJOfRjgrw1aeszrUFe8+iMqmOHLD5AkiByjj0MgFu7ukYoiL+NPM8PLk0GwkMKSzsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212064; c=relaxed/simple; bh=LrSHEUWGR3qHfrIKo1moG6hK8HchQtQJ1sO0Uhs1DR4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fg4y9Pu0X1shIfSGCuacGX4CBvUdUTnWC3NX6Ml4R4a+n8abG6GFQmchxtQ0vmrcPFZW9DweQB0JsadB/owI0KBYLXZfLX3oTD/86G1AmenNS4Ei+6pv5UtCK4tcRrCefvsDbROUJ4NPExdEpST9JNBs/XNrX7Gq6DDgFJs+2h4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a/pNKGsE; 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="a/pNKGsE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4AC7C4CED1; Mon, 10 Feb 2025 18:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739212063; bh=LrSHEUWGR3qHfrIKo1moG6hK8HchQtQJ1sO0Uhs1DR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/pNKGsELlIKLxoPDcP0a9hKpMJ/C722aqX2HgUqkAWt53FMhmcwuPrY2xj/vFBVl cR4valunDe1rwOwFuuulPEJXvjb0uzAmTM4wF6e8cMALZgzqHE645s5srPVkbDD+4W dKlYod+/KhwfnZv86rh7nMfMsJx9KyZt2tn4UVZptMx/HxBFW98PYxP0XKuGIwaTag XRHB+4TN2QAq3Qa66rJMRPfWahjCedHXxaAaabVmu6OEi2HbCcRJUdCZX4DNu+qSVL gk84/jkYPjDAXbzZKUxITb7RG6BACQvVt8qbrP7lM233RYO0/alneV5cLG09WfpZS8 btNZtSn54q9Nw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] mm/damon/core: unset damos->walk_completed after confimed set Date: Mon, 10 Feb 2025 10:27:34 -0800 Message-Id: <20250210182737.134994-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250210182737.134994-1-sj@kernel.org> References: <20250210182737.134994-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" damos->walk_completed is only set, not unset. This can cause next damos_walk() finish earlier than expected. Unset it after all walk_completed is confirmed. Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()") Signed-off-by: SeongJae Park --- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 1a4dd644949b..1d9025d14d83 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1489,6 +1489,9 @@ static void damos_walk_complete(struct damon_ctx *ctx= , struct damos *s) if (!siter->walk_completed) return; } + damon_for_each_scheme(siter, ctx) + siter->walk_completed =3D false; + complete(&control->completion); mutex_lock(&ctx->walk_control_lock); ctx->walk_control =3D NULL; --=20 2.39.5 From nobody Mon Feb 9 17:21:33 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 9FE572566EE; Mon, 10 Feb 2025 18:27:44 +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=1739212064; cv=none; b=SJ+FxyFLRi2C4ljjfAxHITMTw/XVZ3p7RkJiowW8uPRaDBny40c6oli2VH5Im81su9JdMWo83aKVX92/KgASWkPFsy0wb2/oz6v+IRTn28NHALLgwTyuOcKupBhgC72X0ilIxGJe9zwaxnFvZWcSNV7+OS+jnfN2lwN1YimsgiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212064; c=relaxed/simple; bh=hYylxJ/t4NlvulYeuOeW/1CI3orFeM5MsoOWEdxNfxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z5xiHFozLtWPEci4g69GxXHGlfOs++xSE58n1jYitD/isF9vhyZLR1xND/KW5goEEWrPguQ+wsLvE2+sdFhRysBw6kMo0Tfuormvwdgyctgyu61ItaxhIINaYItHgAjU5BHxg5TO6XkSie77xDbCabx3Ushw98qzCbDcrwfAI5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uIgqxIxe; 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="uIgqxIxe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06060C4CEE6; Mon, 10 Feb 2025 18:27:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739212064; bh=hYylxJ/t4NlvulYeuOeW/1CI3orFeM5MsoOWEdxNfxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uIgqxIxe3bqwoy6asnuOYnlpRVTFpkFH1FOGwJCT42U50Uxe4FJYa81ENcSz0orfd qrVK2HdWWpKbdN+XcTgcvaOOyk8KVHX7tsrprCrpxqfi7kiRim5cOwKrQmUBOzBgcl GkgWyHr2PGOHwjcREDaEXNdSAl8jCNp0niySHC5/nrcUtsUcfeV3kNY9ZnX+G54wCD D4YNB4Hr3jT76xCjb0bpCRR4gYviefC4sCotPJj3n0QlUXmE0ESodqt/6PC+XYsEIC 84cbYyEqNKd16F4+e0TqwdX5ocfz3S8FZXyggY6T3XEyXII3uFNfiqQHf+vXE8Xkrk +GZK1ByHMIHTA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] mm/damon/core: do not call damos_walk_control->walk() if walk is completed Date: Mon, 10 Feb 2025 10:27:35 -0800 Message-Id: <20250210182737.134994-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250210182737.134994-1-sj@kernel.org> References: <20250210182737.134994-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" damos_walk() invokes callback functions of schemes until all schemes finishes at least one round of walks. If there are multiple DAMOS schemes having different apply_interval, the callback functions for longer apply interval scheme will be called for more than a round of the walk. The behavior is different from the document (see damos_walk() kernel-doc comment), and not useful. Make the behavior be same to the documented one, by stopping invoking the callback if the walk for the given scheme is completed. Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()") Signed-off-by: SeongJae Park --- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 1d9025d14d83..4b865b2558d9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1453,6 +1453,9 @@ static void damos_walk_call_walk(struct damon_ctx *ct= x, struct damon_target *t, { struct damos_walk_control *control; =20 + if (s->walk_completed) + return; + mutex_lock(&ctx->walk_control_lock); control =3D ctx->walk_control; mutex_unlock(&ctx->walk_control_lock); --=20 2.39.5 From nobody Mon Feb 9 17:21:33 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 DBC11257449; Mon, 10 Feb 2025 18:27:45 +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=1739212065; cv=none; b=YwBhTqiFxRvPVK3rx9NxlgiQUiSf49CbMwIrBdBZjtHuhKsVBv5WCJcvC1B5FsZW8KHeGsIrwYTz+nABJAkGbxiS4JB/kemsiQPFZ1VYy+ljDy+rHmeVrk8G0nn5uNshUXCBsnpprndeDXdmCMr85exr2gM0pgN5OzVp5Tqxgo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212065; c=relaxed/simple; bh=JOpbnQ6/GYsrBYDCbmgIB9gcRtACbXxjFLu2npIKqq4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kWj3QKjfaJuP9Ujn0VXbPGnmYd23dJTFEzWHWGa4b2xvbGpvKDrp4UDVj9fEYZYuHuCiH5Iw/7y+8fUz1E2EBcxoGtv9biglQtx5uwoLyk8HXCPx71M6ky+LUVCCaWswyYyN+6od5jAM3OaxpDfaW1wDmwpQM/eTenbw+jHfeco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pXPFF+hp; 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="pXPFF+hp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EA4EC4CED1; Mon, 10 Feb 2025 18:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739212065; bh=JOpbnQ6/GYsrBYDCbmgIB9gcRtACbXxjFLu2npIKqq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXPFF+hpXIwxEWBO4XNrD2qFwVsSZW7Zd4kKXxF+iazZPOwL66VttoSYIR5m+bhjj 2CB/dhyYSfNQhw3IG3oL+it13d8rYTeT6VeGziXbskumptRBow6qNtP6DOwJb0Dt/U iOuKJJ75fjj9pMAiGoEPVqYycysEGDxrsez42ETAJnDGpkVDlRyE6MQ7Y5TPm1v2p1 dWPo0zSJeLd5FZBKqOV40QVYjdFaC9Dcy6T1KBrHrLcd4bTxcXCbht4hoQ7JKwFI+u tam+aUz/BQ3weJi2T3LTnFTiiVstHMgDYkkcvzHrdaPC7GzElFcb215YtlExmcpQfd FjIs+3adj30QQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] mm/damon/core: do damos walking in entire regions granularity Date: Mon, 10 Feb 2025 10:27:36 -0800 Message-Id: <20250210182737.134994-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250210182737.134994-1-sj@kernel.org> References: <20250210182737.134994-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" damos_walk_control can be installed while DAMOS is walking the regions. This means the walk callback function invocations can be started from a region at the middle of the regions list. This makes it hard to be used reliably. Particularly, DAMOS tried regions update for collecting monitoring results gets problematic results. Increase the walk_control_lock critical section to do walking in entire regions granularity. Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()") Signed-off-by: SeongJae Park --- mm/damon/core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 4b865b2558d9..c3d9b96b786a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1456,11 +1456,10 @@ static void damos_walk_call_walk(struct damon_ctx *= ctx, struct damon_target *t, if (s->walk_completed) return; =20 - mutex_lock(&ctx->walk_control_lock); control =3D ctx->walk_control; - mutex_unlock(&ctx->walk_control_lock); if (!control) return; + control->walk_fn(control->data, ctx, t, r, s, sz_filter_passed); } =20 @@ -1480,9 +1479,7 @@ static void damos_walk_complete(struct damon_ctx *ctx= , struct damos *s) struct damos *siter; struct damos_walk_control *control; =20 - mutex_lock(&ctx->walk_control_lock); control =3D ctx->walk_control; - mutex_unlock(&ctx->walk_control_lock); if (!control) return; =20 @@ -1496,9 +1493,7 @@ static void damos_walk_complete(struct damon_ctx *ctx= , struct damos *s) siter->walk_completed =3D false; =20 complete(&control->completion); - mutex_lock(&ctx->walk_control_lock); ctx->walk_control =3D NULL; - mutex_unlock(&ctx->walk_control_lock); } =20 /* @@ -1845,6 +1840,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) if (!has_schemes_to_apply) return; =20 + mutex_lock(&c->walk_control_lock); damon_for_each_target(t, c) { damon_for_each_region_safe(r, next_r, t) damon_do_apply_schemes(c, t, r); @@ -1859,6 +1855,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) c->attrs.aggr_interval) / sample_interval; s->last_applied =3D NULL; } + mutex_unlock(&c->walk_control_lock); } =20 /* --=20 2.39.5