From nobody Fri Dec 19 20:53:42 2025 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 80145192D8E; Thu, 9 Jan 2025 17:51:38 +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=1736445098; cv=none; b=oSnYTNBw/o34y0q3B3GZ3uvehc6tuO1AN3ZZJNyiNjiZKkVkdrmLFWpk7DTKxy5ZNkodjk+8K66VMKSZ+TG2bTbPG/pBOPXFtUfXX9DFQYC8gwLT9P8LOReNB0FoxsZCoAoDlOGhS6edtjbAF1mnZo6aMRuENrQMD/9/hJiqlNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445098; c=relaxed/simple; bh=97I76lDfvaM6L2LOAAduyShBBxqQhcZ1zQRaRPWTvuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lvw7MmPPN1/jAtaYEW1uBwzREDECVPdfSlD9kyEnJaSXqE2ePgns+HClfK0TohVKPSWigRxBmA3PocHNIQr3QhMFbTtkgd72UmYpqs1k3lyT3wF33hAdznqdIDF0K8obaw2vT3q6BWw6Q/FvDbwyUDRMA4946nvqeOdBKgGpZVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GtXAjCKQ; 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="GtXAjCKQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA5C4C4CED2; Thu, 9 Jan 2025 17:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445098; bh=97I76lDfvaM6L2LOAAduyShBBxqQhcZ1zQRaRPWTvuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtXAjCKQhCXp6XoAzncBThz0kaOtImaAYZIh+2dMqtJca447B2ZLB0/KZW9C6EKwS tYgd4e8PzXMPQGuimjfE7awNMh+Ue58ZeG57xpCMyQgj9Kh6gXR0BDVBNTM+LDjBFS OJ35/YSQ2AYXSlV3kWJR6NeKTsjBABupqrMIQsf/CwT6x18zy1VHzoGdBwsgROPym0 2R9PoraJyf6PAvJ/fNbTJZWwcPTNCvN5Fjwgjd9xtJqZEuWf+ZvW+2KraUaTUJ64Jq 9gPoaPMLqUjH8wQRWwXOkbxtVjv2PVIlw/VdcOMaAiAePHI8bcvYQANhWKCjBlHa20 xnlIkeVQIiekg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 01/10] mm/damon: fixup damos_filter kernel-doc Date: Thu, 9 Jan 2025 09:51:17 -0800 Message-Id: <20250109175126.57878-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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" The comment is slightly wrong. DAMOS filters are not only for pages, but general bytes of memory. Also the description of 'matching' is bit confusing, since DAMOS filters do only filtering out. Update the comments to be less confusing. Signed-off-by: SeongJae Park --- include/linux/damon.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 298b1a831e62..72afba74ac6d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -347,8 +347,8 @@ enum damos_filter_type { =20 /** * struct damos_filter - DAMOS action target memory filter. - * @type: Type of the page. - * @matching: If the matching page should filtered out or in. + * @type: Type of the target memory. + * @matching: If the @type-matching memory should be filtered out. * @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG. * @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR. * @target_idx: Index of the &struct damon_target of @@ -357,9 +357,10 @@ enum damos_filter_type { * @list: List head for siblings. * * Before applying the &damos->action to a memory region, DAMOS checks if = each - * page of the region matches to this and avoid applying the action if so. - * Support of each filter type depends on the running &struct damon_operat= ions - * and the type. Refer to &enum damos_filter_type for more detai. + * byte of the region matches to this given condition and avoid applying t= he + * action if so. Support of each filter type depends on the running &stru= ct + * damon_operations and the type. Refer to &enum damos_filter_type for mo= re + * details. */ struct damos_filter { enum damos_filter_type type; --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 A9AE7199949; Thu, 9 Jan 2025 17:51:39 +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=1736445099; cv=none; b=a0ag43TRJnyfjGk3FwNSM6Z2zTa6FlvS1i7st1bBfqgmbpHq49By0X2Sp5li7nO9nMig+aWGHSpZuHCJ3QdvYrnSE20jZlrBd1GvdhsHkhwhdPtBD0v7Cfl8n0We4/it/XRWE7HXFfcKBPMb4gJ9D3O9Jn6W0n1Bjcr/KtAl7A0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445099; c=relaxed/simple; bh=b5/TGNrGU2BJ6e8ROpk/K/qKcaZatsIxBg3oBg+1uiM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ALutS0jCOocToA3z6Qcm9g57YXt4CN0nWE0T9Dv5jKolQpY7Mfv7ycxBH6KGnpbqCpBgHnmubUXDhy9IclZb2+yOfsJXi+CVwx76tcZJfWkEevt/RckGb/tdGOxZcKjuYT+V9JM/09If9Pk5A3kL/xrKMvNDXa3/kH87mgcjRXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgDCg4aO; 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="XgDCg4aO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CACFC4CEDF; Thu, 9 Jan 2025 17:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445099; bh=b5/TGNrGU2BJ6e8ROpk/K/qKcaZatsIxBg3oBg+1uiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgDCg4aOnSyKMLbHEiFCUeQulqorcmktJn7pvdk+KyGJPAAKYP3hw5WnF080ziHBY Cux41jLyFii6G1U+3tgU+voGlXx4KWqRYLpSEYExW+CVkQ5SSj6y4Gtr1m7oetsPxb AVNfrzOLWnPEEr9//e9rt1WVoUECGgS1L8P+J/xt47QJXSWgPcrvFeJI8DfJfH2hmR 6OlI1rFGwVWfYml11NanvbR6xZPOyAN/n2KEUDZ2YDkVbokqLZ/Fq/jNdbxNXtbfja dawTjerZ+LQVrDupRPjQRich0DOoWSQpmaea/jAlBS+ZKRUfGvgAX1JVimbYIXerqU I1Ol6vWUob6Fw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 02/10] mm/damon/core: add damos_filter->allow field Date: Thu, 9 Jan 2025 09:51:18 -0800 Message-Id: <20250109175126.57878-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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 filters work as only exclusive (reject) filters. This makes it easy to be confused, and restrictive at combining multiple filters for covering various types of memory. Add a field named 'allow' to damos_filter. The field will be used to indicate whether the filter should work for inclusion or exclusion. To keep the old behavior, set it as 'false' (work as exclusive filter) by default, from damos_new_filter(). Following two commits will make the core and operations set layers, which handles damos_filter objects, respect the field, respectively. Signed-off-by: SeongJae Park --- include/linux/damon.h | 4 +++- mm/damon/core.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 72afba74ac6d..8a2d104df5a3 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -348,7 +348,8 @@ enum damos_filter_type { /** * struct damos_filter - DAMOS action target memory filter. * @type: Type of the target memory. - * @matching: If the @type-matching memory should be filtered out. + * @matching: Whether this is for @type-matching memory. + * @allow: Whether to include or exclude the @matching memory. * @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG. * @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR. * @target_idx: Index of the &struct damon_target of @@ -365,6 +366,7 @@ enum damos_filter_type { struct damos_filter { enum damos_filter_type type; bool matching; + bool allow; union { unsigned short memcg_id; struct damon_addr_range addr_range; diff --git a/mm/damon/core.c b/mm/damon/core.c index 52e50f183ffe..bdde532ebbc8 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -275,6 +275,7 @@ struct damos_filter *damos_new_filter(enum damos_filter= _type type, return NULL; filter->type =3D type; filter->matching =3D matching; + filter->allow =3D false; INIT_LIST_HEAD(&filter->list); return filter; } --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 C9C2019D880; Thu, 9 Jan 2025 17:51:40 +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=1736445100; cv=none; b=buLOnrCYYyntYQtAKFvovSmtztDDBYjqK2clZRHTQ5wPGOVv2yWAbQV1715VwtNTzJo8NhVp/IP6LmcYEAc8vWo2bfG3LkolYvLwWvATyQ5j96/RiNUnxk18ztCMDAHzS9E7BlgHZse8jY6ldBKp1cJeHFRrTwDz/ZD1jg271o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445100; c=relaxed/simple; bh=/TwzvHzsYhMLVRMAly61w18SuFtGS0e8DIve8swoAg8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K/S7m2Hd22b+ansYdLLPQNWZbP+m4PnEWVOCkKN/kjFbeaRCVO6ej4e7t+xlwwD17QUn4iECCFo7hUKD7yAAWdf6+EZ3VQSPZezgKUOE9uBBDSFDHny8mTIE2rde1XXyjyPf9ddnnk1QRLqehBTFbtKEM9/7AZUi/Uv6CctZBW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iOiV8xN+; 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="iOiV8xN+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36EFEC4CEE1; Thu, 9 Jan 2025 17:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445100; bh=/TwzvHzsYhMLVRMAly61w18SuFtGS0e8DIve8swoAg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iOiV8xN+tOzd6OhWGwRDcbApXOwx2OoSQwcl1ajO5uMihuqIeFetDPj9kO1jvRZI3 DCaVH7i0rTdMfXF9gctFxlGeo8ihHqNWZs0nADBR6YSrMd36r0n6p36YB1MuIFuRj1 /BMQS++22T1gOsjeEneFIB8/06l2tUcaCx5/BajT7ICW4t09cZsy+uQeu0Qyvjz7dx f8LNV/bZ+JLSt8fXU5hvrmJCT+A44RSIA0A4g8SuUGaxAAUCZaDwk07W+nPkt1v+gB qK+y9hp3bWU2vsD48OucJ/zTxW2Lmn30O1QwshQ0saR9Kd3SnNh47BIjxCa+9Mev5e F095E2SrYdR5A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 03/10] mm/damon/core: support damos_filter->allow Date: Thu, 9 Jan 2025 09:51:19 -0800 Message-Id: <20250109175126.57878-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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 filters supports allowing behavior, but the core layer's DAMOS filters handling logic still assumes only rejecting (filtering-out) behavior. Update the logic to aware of and respect the behavioral decision by reading damos_filter->allow when making the decision to exclude a region or not. Signed-off-by: SeongJae Park --- mm/damon/core.c | 6 +++--- mm/damon/tests/core-kunit.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index bdde532ebbc8..76707b0635d6 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1374,7 +1374,7 @@ static void damos_update_stat(struct damos *s, s->stat.sz_ops_filter_passed +=3D sz_ops_filter_passed; } =20 -static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target = *t, +static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target = *t, struct damon_region *r, struct damos_filter *filter) { bool matched =3D false; @@ -1428,8 +1428,8 @@ static bool damos_filter_out(struct damon_ctx *ctx, s= truct damon_target *t, struct damos_filter *filter; =20 damos_for_each_filter(filter, s) { - if (__damos_filter_out(ctx, t, r, filter)) - return true; + if (damos_filter_match(ctx, t, r, filter)) + return !filter->allow; } return false; } diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index cf22e09a3507..8f58d3424c21 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -434,25 +434,25 @@ static void damos_test_filter_out(struct kunit *test) damon_add_region(r, t); =20 /* region in the range */ - KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, damos_filter_match(NULL, t, r, f)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region before the range */ r->ar.start =3D DAMON_MIN_REGION * 1; r->ar.end =3D DAMON_MIN_REGION * 2; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region after the range */ r->ar.start =3D DAMON_MIN_REGION * 6; r->ar.end =3D DAMON_MIN_REGION * 8; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region started before the range */ r->ar.start =3D DAMON_MIN_REGION * 1; r->ar.end =3D DAMON_MIN_REGION * 4; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2); @@ -465,7 +465,7 @@ static void damos_test_filter_out(struct kunit *test) /* region started in the range */ r->ar.start =3D DAMON_MIN_REGION * 2; r->ar.end =3D DAMON_MIN_REGION * 8; - KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, damos_filter_match(NULL, t, r, f)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6); --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 E0A391A2C0B; Thu, 9 Jan 2025 17:51:41 +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=1736445102; cv=none; b=RCA/90+wc+1AzPvNBeGfdFCNQLgOAWKr+fKRy3G6zNwSTA8lYkyHfcKR4tBBtmqdILVEdqns4GRh9mJAdt2m/41JIF3sknmfMNdPKMe/FP9f1btZPNcomVWFAr5X6A/QJniQBjJYz5CvlgVR8B+0OYYJ3GDm1yLPqBlFz7KcC1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445102; c=relaxed/simple; bh=xBH0b3NhxWYTGElmoBJalgG8ZkJmFacZfKWdD6zTD8o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Sf1K7Xq0onfOwIDrt5BUutnfMfA4zrU6lrAFUbiHEswpp/NiIyNUsXFFPELyZuOH57ra2/w8XvStyR05kRFkB+2JvsIrg3n3D36J62QxCQwFXdjp6z+cL2M4SpgDQ7cX0XLXcxuvgVcvcfIa08CB3TgS9S55G3XGF3/Gx8aDB34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h2nx70CS; 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="h2nx70CS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 474E2C4CEE8; Thu, 9 Jan 2025 17:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445101; bh=xBH0b3NhxWYTGElmoBJalgG8ZkJmFacZfKWdD6zTD8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2nx70CSAa1D7NJ1Q+cniSmR/Cs12oa2tSDvv2hG1MrjskAGMUls70M8xr21kMENF 4q4oBrSWzKZkaACyQRBmq70GxYNaZdA47qMw1vGxo9rt4Ku8cfzxiOPHsEeIv59ZDc qXLs7xqDVw10ku1W8NLXWOJFEuLyF8FurvEfdJQ2kqTKgcoAmTBMQu22kmd3nO+zGe YbRgznO0p4Z79IkRv+Kyf8TKpyp1Sk4G9VItMY+3WB36l/+AelHeX8q2MaiNKkSGZj WjQfKQVn8KHfHrpm2FrFCHte+if9KtE0kky8UjLhkiXN9kqr13ZOl5S4S4XU9jvfFa p889H/fWOEIlQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 04/10] mm/damon/paddr: support damos_filter->allow Date: Thu, 9 Jan 2025 09:51:20 -0800 Message-Id: <20250109175126.57878-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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" Respect damos_filter->allow from 'paddr', which is a DAMON operations set implementation for the physical address space and supports a few types of region-internal DAMOS filters (anon, memcg and young). The change is similar to that of the previous commit for core layer update. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b0c283808ba6..817acfd4f8a2 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -198,7 +198,7 @@ static unsigned int damon_pa_check_accesses(struct damo= n_ctx *ctx) return max_nr_accesses; } =20 -static bool __damos_pa_filter_out(struct damos_filter *filter, +static bool damos_pa_filter_match(struct damos_filter *filter, struct folio *folio) { bool matched =3D false; @@ -237,8 +237,8 @@ static bool damos_pa_filter_out(struct damos *scheme, s= truct folio *folio) struct damos_filter *filter; =20 damos_for_each_filter(filter, scheme) { - if (__damos_pa_filter_out(filter, folio)) - return true; + if (damos_pa_filter_match(filter, folio)) + return !filter->allow; } return false; } --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 082561ACEB2; Thu, 9 Jan 2025 17:51:42 +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=1736445103; cv=none; b=hZD6UmKBUYKJrLX+iUz0NztI+ry1COfW/amPntuk4LovjhfbqBNv9zLPgOoyYMuDcJ6eNj5ejJz2WrZUhmNimJ4usFlGzHfULIO0OQqQ6SVUb5EIdvDhqgtg/0aX1WuRsYDYWiTgmGFDmXbJltXcm1h3xvec8Z6Em37/4HzKZPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445103; c=relaxed/simple; bh=VTPumCjyOZzpcnH5UkJNLIwC7RykeAkPieOWziLnSjk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CuimbcuASEUSLfpc/GSdKf94c2aCUVXk/5tWP9DSKObZE4nDdJCYM8wmwmEV7Y+1MKhVfoWm/cp7QlaedoOEwC64EECRH6Yyaf39kI81kk6wmtRuwiKBvtrqZe2pDIlbyc8iLnSmSl4GB/ZOiR4/mcn771WmyF8C6CnEqzurDX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qSj+cWsJ; 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="qSj+cWsJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54C31C4CEEA; Thu, 9 Jan 2025 17:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445102; bh=VTPumCjyOZzpcnH5UkJNLIwC7RykeAkPieOWziLnSjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qSj+cWsJLxLYLKIerVnKmUOKM4kdgjseSjeI8f9V7mRbskhrL5TAk4RFZRQXcZfiQ LN7g8yMoqdqifi4p5cyyYwifg3EcoiwCQ7ioHusB1wN9VcsNGfEZjR+1VDJyz5fW3W Qa5MY/JaiSPH6D6RLU5XRpYMdcFSj1V+v6AdVJzMty5/7avSWb+daBp14+J9eW7AH7 PD7YAiQyJjWADMlon0yZqvdeclzCnkeqADaRVeBg4/kI6jjz1Ukkt3eky9CdWfaeN3 RIEcmXy4BTz3la+Yp4OpJfMxwusNmakZsMIQk/jOqsLW7w+p/WPXS6ynYT4qjmWMNa iu+qLWHg6eleQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 05/10] mm/damon: add 'allow' argument to damos_new_filter() Date: Thu, 9 Jan 2025 09:51:21 -0800 Message-Id: <20250109175126.57878-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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 API users should set damos_filter->allow manually to use a DAMOS allow-filter, since damos_new_filter() unsets the field always. It is cumbersome and easy to mistake. Add an arugment for setting the field to damos_new_filter(). Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 +- mm/damon/core.c | 7 ++++--- mm/damon/paddr.c | 3 ++- mm/damon/reclaim.c | 2 +- mm/damon/sysfs-schemes.c | 2 +- mm/damon/tests/core-kunit.h | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 8a2d104df5a3..0834d7ffcb84 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -801,7 +801,7 @@ void damon_update_region_access_rate(struct damon_regio= n *r, bool accessed, struct damon_attrs *attrs); =20 struct damos_filter *damos_new_filter(enum damos_filter_type type, - bool matching); + bool matching, bool allow); void damos_add_filter(struct damos *s, struct damos_filter *f); void damos_destroy_filter(struct damos_filter *f); =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 76707b0635d6..55a435bdd89d 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -266,7 +266,7 @@ int damon_set_regions(struct damon_target *t, struct da= mon_addr_range *ranges, } =20 struct damos_filter *damos_new_filter(enum damos_filter_type type, - bool matching) + bool matching, bool allow) { struct damos_filter *filter; =20 @@ -275,7 +275,7 @@ struct damos_filter *damos_new_filter(enum damos_filter= _type type, return NULL; filter->type =3D type; filter->matching =3D matching; - filter->allow =3D false; + filter->allow =3D allow; INIT_LIST_HEAD(&filter->list); return filter; } @@ -806,7 +806,8 @@ static int damos_commit_filters(struct damos *dst, stru= ct damos *src) continue; =20 new_filter =3D damos_new_filter( - src_filter->type, src_filter->matching); + src_filter->type, src_filter->matching, + src_filter->allow); if (!new_filter) return -ENOMEM; damos_commit_filter_arg(new_filter, src_filter); diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 817acfd4f8a2..6b4397de4199 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -259,7 +259,8 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s, } } if (install_young_filter) { - filter =3D damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true); + filter =3D damos_new_filter( + DAMOS_FILTER_TYPE_YOUNG, true, false); if (!filter) return 0; damos_add_filter(s, filter); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 9e0077a9404e..a675150965e0 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -221,7 +221,7 @@ static int damon_reclaim_apply_parameters(void) } =20 if (skip_anon) { - filter =3D damos_new_filter(DAMOS_FILTER_TYPE_ANON, true); + filter =3D damos_new_filter(DAMOS_FILTER_TYPE_ANON, true, false); if (!filter) goto out; damos_add_filter(scheme, filter); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index deeaf23c1fcf..9a883e8aea1c 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1901,7 +1901,7 @@ static int damon_sysfs_add_scheme_filters(struct damo= s *scheme, sysfs_filters->filters_arr[i]; struct damos_filter *filter =3D damos_new_filter(sysfs_filter->type, - sysfs_filter->matching); + sysfs_filter->matching, false); int err; =20 if (!filter) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 8f58d3424c21..532c6a6f21f9 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -411,7 +411,7 @@ static void damos_test_new_filter(struct kunit *test) { struct damos_filter *filter; =20 - filter =3D damos_new_filter(DAMOS_FILTER_TYPE_ANON, true); + filter =3D damos_new_filter(DAMOS_FILTER_TYPE_ANON, true, false); KUNIT_EXPECT_EQ(test, filter->type, DAMOS_FILTER_TYPE_ANON); KUNIT_EXPECT_EQ(test, filter->matching, true); KUNIT_EXPECT_PTR_EQ(test, filter->list.prev, &filter->list); @@ -425,7 +425,7 @@ static void damos_test_filter_out(struct kunit *test) struct damon_region *r, *r2; struct damos_filter *f; =20 - f =3D damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true); + f =3D damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true, false); f->addr_range =3D (struct damon_addr_range){ .start =3D DAMON_MIN_REGION * 2, .end =3D DAMON_MIN_REGION * 6}; =20 --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 0D1F81B0413; Thu, 9 Jan 2025 17:51: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=1736445104; cv=none; b=XSqheAnQ9E61s/4mdkh00nH8wXvY0p4Z+3rcMBaP848mT+VSYc/chbSphxdTQ43L2it/NKaaO+iSm4vZbmxqJhHlSUXWBskNMU2sIE+pnfUF75fDGKj2cg0w/aRE5dk9wzEfacl+pFWaySanlv4zOmQS4Op9Z7DmSXqC5ZltKI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445104; c=relaxed/simple; bh=qmaIUnx59dUjwJkr4G+Ggfwt4z+WkdllmHRXE6wuoJA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AXWujfUR2PpVWE0ropx9hDc9/GnZwWDWmwIkE2SOiUciAjKbSuKWATWz2UyaTUYiF2ZpPeBbfWmKOFBIPZuhiRGlraLa1JWBLvo9+xhX6Quwj8CsGqE4GAPr4oRXBBWeupIJbUNNrHMscBCnMBjA0toa1oq59tG0WWrM0Aoan6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P8NlydKr; 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="P8NlydKr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E877C4CEE2; Thu, 9 Jan 2025 17:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445103; bh=qmaIUnx59dUjwJkr4G+Ggfwt4z+WkdllmHRXE6wuoJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8NlydKrZFuP8R5wAjf7JbfscwIPB64jz+BGzzEkjRkiQZqySwJ97bJzTajtYLk+F 0xXmae4ZRT78XzzUs1KT7FmLdBlxWrn0RMcxKFtG7TO2kA6sR8YMDUTmrws2e3ycFG 2ttU3NmCipytEE+qOvbm25XhIsMPT6hQUQ2YCu6FSo4LXdibz9bnQ1QqJ9wYOE4Cjs rstP5YUKEr+Ekx6gMov2qd3AWBoffGg9Rd/b3dZUMjRaTLR+SPsAaATPfHLCno6uNc jQhulsnR2GHmgyX6YJVmV+IWHp8k6De+eqP+SueNmgk84xgIVzB/CHwqp6WhUiAnLT U7/MjPM6Y6uSw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 06/10] mm/damon/sysfs-schemes: add a file for setting damos_filter->allow Date: Thu, 9 Jan 2025 09:51:22 -0800 Message-Id: <20250109175126.57878-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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" Only kernel-space DAMON API users can use inclusive DAMOS filters. Add a sysfs file named 'allow' under DAMOS filter directory of DAMON sysfs interface, to let the user-space users use inclusive DAMOS filters. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 9a883e8aea1c..98f93ae9f59e 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -313,6 +313,7 @@ struct damon_sysfs_scheme_filter { struct kobject kobj; enum damos_filter_type type; bool matching; + bool allow; char *memcg_path; struct damon_addr_range addr_range; int target_idx; @@ -385,6 +386,30 @@ static ssize_t matching_store(struct kobject *kobj, return count; } =20 +static ssize_t allow_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_filter *filter =3D container_of(kobj, + struct damon_sysfs_scheme_filter, kobj); + + return sysfs_emit(buf, "%c\n", filter->allow ? 'Y' : 'N'); +} + +static ssize_t allow_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_scheme_filter *filter =3D container_of(kobj, + struct damon_sysfs_scheme_filter, kobj); + bool allow; + int err =3D kstrtobool(buf, &allow); + + if (err) + return err; + + filter->allow =3D allow; + return count; +} + static ssize_t memcg_path_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -482,6 +507,9 @@ static struct kobj_attribute damon_sysfs_scheme_filter_= type_attr =3D static struct kobj_attribute damon_sysfs_scheme_filter_matching_attr =3D __ATTR_RW_MODE(matching, 0600); =20 +static struct kobj_attribute damon_sysfs_scheme_filter_allow_attr =3D + __ATTR_RW_MODE(allow, 0600); + static struct kobj_attribute damon_sysfs_scheme_filter_memcg_path_attr =3D __ATTR_RW_MODE(memcg_path, 0600); =20 @@ -497,6 +525,7 @@ static struct kobj_attribute damon_sysfs_scheme_filter_= damon_target_idx_attr =3D static struct attribute *damon_sysfs_scheme_filter_attrs[] =3D { &damon_sysfs_scheme_filter_type_attr.attr, &damon_sysfs_scheme_filter_matching_attr.attr, + &damon_sysfs_scheme_filter_allow_attr.attr, &damon_sysfs_scheme_filter_memcg_path_attr.attr, &damon_sysfs_scheme_filter_addr_start_attr.attr, &damon_sysfs_scheme_filter_addr_end_attr.attr, @@ -1901,7 +1930,8 @@ static int damon_sysfs_add_scheme_filters(struct damo= s *scheme, sysfs_filters->filters_arr[i]; struct damos_filter *filter =3D damos_new_filter(sysfs_filter->type, - sysfs_filter->matching, false); + sysfs_filter->matching, + sysfs_filter->allow); int err; =20 if (!filter) --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 ED7031F12FB; Thu, 9 Jan 2025 17:51: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=1736445105; cv=none; b=Fd4HF2CJyt2de9LFGrzQQtTaoCENp8zfHh2Xsnz8QJNsFyjitDDbCgK0a1h0xeukIobxVOxHQD1cycO1TtoaGXmpWbQhiJJajSuoC5OtWQs3TvDJ3pqvF8YJs8y6cLq5cLNENLCuSdpZGAp8+CNS7h3kvaZSoZl8h6TlPwTtEwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445105; c=relaxed/simple; bh=D5K8J1LD/PiUXT0vcupBmI3FxsSeWohef6Oiv0g+Rfo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PyxWD8zcP3iMO4y/W1wUpaH/rokJyXRFt5/Qs5ocVx7MyyrrvAIrlilCoTbygyiIkxGA7rgFSXMZzBPTjr2chPvGIrjOpivu+DXUJmFX/37ooDJOFPoy3ryd0H0yCg2WgwRzP1cO+ixBrldIKxGlwJPiATI2MKTGny3YfCvxE9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IMh+T2KB; 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="IMh+T2KB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AC9CC4CEE5; Thu, 9 Jan 2025 17:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445104; bh=D5K8J1LD/PiUXT0vcupBmI3FxsSeWohef6Oiv0g+Rfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMh+T2KBV7HCpVmbGHyYNBHIs5nafW8flfKwJ8siqr6+f87zJ2q+W0QPIMWaUAbF4 YUX11l/s0wpwVZZCj35/WeG8fRW5kuu0xGMp/W+raK3N66kk15nIZV4GG1q95qEa6x 0Aap+9qtd1SV8m5hKzSkFVSb6aAvOITaRlZtGEPmP5ZpwJdt3FauH1BzvrhlfeHOs2 kqAfpB5VAQS/KTqHBt8Opp/kKhqMxjogmWkBQK94vpWZ4UtxtHhv+4uXpDlLwcyGM2 YNkAZZ6SV/v1KJ1Lt0AxMiQgUSzp8CjKKFqN6Ahe7DaKsayGVTcHBdSEA6ZtB9w4bC WSVHI8j/7bvSQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 07/10] Docs/mm/damon/design: document allow/reject DAMOS filter behaviors Date: Thu, 9 Jan 2025 09:51:23 -0800 Message-Id: <20250109175126.57878-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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" Update DAMOS filters design document to describe the allow/reject behavior of filters. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 449eb33688c2..667775bab86c 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -504,9 +504,34 @@ have a list of latency-critical processes. =20 To let users optimize DAMOS schemes with such special knowledge, DAMOS pro= vides a feature called DAMOS filters. The feature allows users to set an arbitr= ary -number of filters for each scheme. Each filter specifies the type of targ= et -memory, and whether it should exclude the memory of the type (filter-out),= or -all except the memory of the type (filter-in). +number of filters for each scheme. Each filter specifies + +- a type of memory (``type``), +- whether it is for the memory of the type or all except the type + (``matching``), and +- whether it is to allow (include) or reject (exclude) applying + the scheme's action to the memory (``allow``). + +When multiple filters are installed, each filter is evaluated in the insta= lled +order. If a part of memory is matched to one of the filter, next filters = are +ignored. If the memory passes through the filters evaluation stage becaus= e it +is not matched to any of the filters, applying the scheme's action to it is +allowed, same to the behavior when no filter exists. + +For example, let's assume 1) a filter for allowing anonymous pages and 2) +another filter for rejecting young pages are installed in the order. If a= page +of a region that eligible to apply the scheme's action is an anonymous pag= e, +the scheme's action will be applied to the page regardless of whether it is +young or not, since it matches with the first allow-filter. If the page is +not anonymous but young, the scheme's action will not be applied, since the +second reject-filter blocks it. If the page is neither anonymous nor youn= g, +the page will pass through the filters evaluation stage since there is no +matching filter, and the action will be applied to the page. + +Note that the action can equally be applied to memory that either explicit= ly +filter-allowed or filters evaluation stage passed. It means that installi= ng +allow-filters at the end of the list makes no practical change but only +filters-checking overhead. =20 For efficient handling of filters, some types of filters are handled by the core layer, while others are handled by operations set. In the latter cas= e, @@ -516,7 +541,7 @@ filter are not counted as the scheme has tried to the r= egion. In contrast, if a memory regions is filtered by an operations set layer-handled filter, it= is counted as the scheme has tried. This difference affects the statistics. =20 -Below types of filters are currently supported. +Below ``type`` of filters are currently supported. =20 - anonymous page - Applied to pages that containing data that not stored in files. --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 362DD1FCCF3; Thu, 9 Jan 2025 17:51: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=1736445106; cv=none; b=VSJ0jKW3eUO4KBZT4Z47biZkPOzFWYdKzAHM8W79Ln8AMuJ7/jNQRk1fbqU2aHZpCVV0uhNyWV4CwtRj5/pyW1NLwBEO/7Uyr7VKssbaCj4ctirZT8WmT0pnV1vMgWWnEbhet3fH9vrYFOE9GPxdsy+2C1STuTTnXImkuyDHo3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445106; c=relaxed/simple; bh=gKQlLARsVrrph5NrbcUYgL9T8fplC1mlIWF/4YxuHGg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mHK3spckl5zMNVXc/tHCn47KXyViG3CUjGDypPBG5hjkeopsJWPVMdb0tHmhBo6pRvEmpeqoUJ3LAAsmgDUJuzpydsl9MteQ0X6zF43TCxL5vFA97Jb1WabMSiAJo43Rti8/bvIeITecUBXEqbh6f3PJWQ9YqzG9sGsjcVW3axw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=REsmlWwh; 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="REsmlWwh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96E17C4CEDF; Thu, 9 Jan 2025 17:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445105; bh=gKQlLARsVrrph5NrbcUYgL9T8fplC1mlIWF/4YxuHGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REsmlWwhB0dudPGHboz+PDVelqGDAeP6LkzFmqYWSqf1lAqHKMJxvJZa6W0K+z687 0Tzm84jAynQdcg7cHsGQNJNoBsNT85GuJrSqH6a9FbQ+tIdkuW5Kd7YYRf7fec7btw 4+S9cbMoAT1ZIt3cOGSyUyZIlREp1jbEdBarzaHzGx4uKzgehkl/K10y29is4Jy9N5 t/TP56RX5xrZFvovNwENPFm5ceSUyXhrcYqkTTkgP5+9FAB27r1xqRzLABV190knSq ou/hNqpn2JjORBElpBaNQIdAe5iIAlWbH9s39eUTXTRtcLbSWdExCMRa7Uk387r05b Uq6JDI1p6oikg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 08/10] Docs/ABI/damon: document DAMOS filter allow sysfs file Date: Thu, 9 Jan 2025 09:51:24 -0800 Message-Id: <20250109175126.57878-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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" Update DAMON ABI document for added DAMOS filter 'allow' file. Signed-off-by: SeongJae Park --- Documentation/ABI/testing/sysfs-kernel-mm-damon | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 8c0acb31638b..b057eddefbfc 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -355,10 +355,15 @@ Description: If 'target' is written to the 'type' fil= e, writing to or What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//fi= lters//matching Date: Dec 2022 Contact: SeongJae Park -Description: Writing 'Y' or 'N' to this file sets whether to filter out - pages that do or do not match to the 'type' and 'memcg_path', - respectively. Filter out means the action of the scheme will - not be applied to. +Description: Writing 'Y' or 'N' to this file sets whether the filter is for + the memory of the 'type', or all except the 'type'. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//fi= lters//allow +Date: Jan 2025 +Contact: SeongJae Park +Description: Writing 'Y' or 'N' to this file sets whether to allow or reje= ct + applying the scheme's action to the memory that satisfies the + 'type' and the 'matching' of the directory. =20 What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//st= ats/nr_tried Date: Mar 2022 --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 5AE401FECA5; Thu, 9 Jan 2025 17:51:46 +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=1736445107; cv=none; b=iM+siftMjCNcT5N+ruGP5+eYfKXjz3tHrzLptsg/gV1EfyHe1KDzQd/7zdy4yIMyFw5qXnNeFFwHjZ+a9safKJOjeWLPzn0V1+ax2aYHRIRZbCZIIcxa+17bPO9q6YWik157NiquvNwyTuCboAqgNUSnG2h4NhEpnbW79Mmy07E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445107; c=relaxed/simple; bh=jufb0sHL1L5krYu5xZ9uPN7YQ+OC0Evk60XYWVCJy7g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y9GPqnTf2Ye/VPr54jrVQwcVvZAVZtzWCQF5k7IKi2Rh5vVy5529DTop3Nb0K6Hsidta44+y5kluNY4LsDU0ZDADO27diDbuHZKSLoM+2sx9mCXNXyo8gsLghiLf40Px03s+uPqaSVXQlTqk6rXfNMdi6IWSSCZaFDXr7GEOJqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rKs0gZ2C; 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="rKs0gZ2C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE997C4CEE2; Thu, 9 Jan 2025 17:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445106; bh=jufb0sHL1L5krYu5xZ9uPN7YQ+OC0Evk60XYWVCJy7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rKs0gZ2C2Zr7ye0+OdvYEFCw7MIAwCeZdC2N8tWy4GVn4gqpSrTU7VrYj3WjuFhqO 5ce6wlNJZQyAnYW+nf/hOeQ12qJSEqq4eQQ3TxdqiC0BPTSk9lmpbUp8mYYZSaCHya 79gYNA9ADpr5cESKx22cDAD26PJlLwu+4wXbFrCEcXojhxA6X3v4iYwjFb9phohury /nY9pAi0O/WhTiCg/NljqXn1nn0h/QqpvhQg8+hAkklGxF6sz2kUpNxBSWCRBarehj gkKw4cmmJNz3NIXzTIpQkZxgX+5QfAf8wPXiPC5YlZ+hPAeq+5QySqn587rIl5lnwY NaMsiIiHl+eQA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 09/10] Docs/admin-guide/mm/damon/usage: omit DAMOS filter details in favor of design doc Date: Thu, 9 Jan 2025 09:51:25 -0800 Message-Id: <20250109175126.57878-10-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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 usage document is describing some details about DAMOS filters, which are also documented on the design doc. Deduplicate the details in favor of the design doc. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 29 ++++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index 71cf29ae8502..8df3357dcfa3 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -411,13 +411,17 @@ Each filter directory contains six files, namely ``ty= pe``, ``matcing``, file, you can write one of five special keywords: ``anon`` for anonymous p= ages, ``memcg`` for specific memory cgroup, ``young`` for young pages, ``addr`` = for specific address range (an open-ended interval), or ``target`` for specific -DAMON monitoring target filtering. In case of the memory cgroup filtering= , you -can specify the memory cgroup of the interest by writing the path of the m= emory -cgroup from the cgroups mount point to ``memcg_path`` file. In case of the -address range filtering, you can specify the start and end address of the = range -to ``addr_start`` and ``addr_end`` files, respectively. For the DAMON -monitoring target filtering, you can specify the index of the target betwe= en -the list of the DAMON context's monitoring targets list to ``target_idx`` = file. +DAMON monitoring target filtering. Meaning of the types are same to the +description on the :ref:`design doc `. + +In case of the memory cgroup filtering, you can specify the memory cgroup = of +the interest by writing the path of the memory cgroup from the cgroups mou= nt +point to ``memcg_path`` file. In case of the address range filtering, you= can +specify the start and end address of the range to ``addr_start`` and +``addr_end`` files, respectively. For the DAMON monitoring target filteri= ng, +you can specify the index of the target between the list of the DAMON cont= ext's +monitoring targets list to ``target_idx`` file. + You can write ``Y`` or ``N`` to ``matching`` file to filter out pages that= does or does not match to the type, respectively. Then, the scheme's action wi= ll not be applied to the pages that specified to be filtered out. @@ -434,14 +438,9 @@ pages of all memory cgroups except ``/having_care_alre= ady``.:: echo /having_care_already > 1/memcg_path echo Y > 1/matching =20 -Note that ``anon`` and ``memcg`` filters are currently supported only when -``paddr`` :ref:`implementation ` is being used. - -Also, memory regions that are filtered out by ``addr`` or ``target`` filte= rs -are not counted as the scheme has tried to those, while regions that filte= red -out by other type filters are counted as the scheme has tried to. The -difference is applied to :ref:`stats ` and -:ref:`tried regions `. +Refer to the :ref:`DAMOS filters design documentation +` for more details including when each of the +filters are supported and differences on stats. =20 .. _sysfs_schemes_stats: =20 --=20 2.39.5 From nobody Fri Dec 19 20:53:42 2025 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 24FB7200B95; Thu, 9 Jan 2025 17:51:48 +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=1736445108; cv=none; b=taDw5wrgPdpF0ihjNY3p1jFLML5BtR0MczBUz1+8qZvgg6WnTXYEpT6uUIMwisjtVluMtmn14J5oov/Av/7IthGEt61rtn8zT7DoxKoZf0BzX/ILA54Z8w2vKrqHYPFJUE/t2kxCq5VPQUKbKL1LqYkb1cZhgVIVuji+QET16Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736445108; c=relaxed/simple; bh=IPoCvtuIbYdm4duAoYfcI65fUkKJC3T/ANKcwt19fcA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=BKclcyqkYLbt9gSCrynEhNmmyqfbqVr6uS4sCTtAv0pZUtaDO8BZlvBTnhKMkQRSayo0WXWZZu8OwhGvd82qiGakpSbLdSa837WiTWILgpFqWQmDt67xGlOd3/7Xg7ofzSKGfcX2QOTMb0JPUaFSqFD/WRsS6zt/bXYL24lprmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LYYfWteP; 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="LYYfWteP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE000C4CED2; Thu, 9 Jan 2025 17:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736445108; bh=IPoCvtuIbYdm4duAoYfcI65fUkKJC3T/ANKcwt19fcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LYYfWtePMZTuxd4s2GRIBuHgMcxlCm6/g/nwHTX+qzJ7Q6oLzDb2N+B1qx/ANy6JG L1b4uwDm3AKkYPa/sfWJjSAL66RbSTW3nLyZWT9jTaASpJ4cEXQ74jjvoyilcVQY1d PP7mKtMt24H07N0YUyegP4mhDWuLcRUT9CUFr2gTBJQRpEUpGiCB83EIe8lfy2Xhzu oTP6cwo+p9jhLLfM95fIY6vLvK5qkcacQKOoIytnlhKZccWnrLkiW12ZH6my+gSpAs EQd6ed51aVz/lHT/cjkYTLpliY6WIn34vQifkLkZ5cCzCG4V6mPAg0TeF79cD7jOhU yuOlq4RRSgFHw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 10/10] Docs/admin-guide/mm/damon/usage: document DAMOS filter 'allow' sysfs file Date: Thu, 9 Jan 2025 09:51:26 -0800 Message-Id: <20250109175126.57878-11-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250109175126.57878-1-sj@kernel.org> References: <20250109175126.57878-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Update DAMON usage document for the newly added 'allow' sysfs file for DAMOS filters. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 33 +++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index 8df3357dcfa3..f0d0c20711d6 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -83,7 +83,7 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 0/target_metric,target_value,current_value =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`watermarks `/metric,interval_us,high,mid,low =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`filters `/nr_filters - =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/type,matching,memcg_id + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/type,matching,memcg_id,allow =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`stats `/nr_tried,sz_tried,nr_applied,sz_applied,= sz_ops_filter_passed,qt_exceeds =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`tried_regions `/total_bytes =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/start,end,nr_accesses,age,sz_filter_passed @@ -406,13 +406,14 @@ number (``N``) to the file creates the number of chil= d directories named ``0`` to ``N-1``. Each directory represents each filter. The filters are evalu= ated in the numeric order. =20 -Each filter directory contains six files, namely ``type``, ``matcing``, -``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``ty= pe`` -file, you can write one of five special keywords: ``anon`` for anonymous p= ages, -``memcg`` for specific memory cgroup, ``young`` for young pages, ``addr`` = for -specific address range (an open-ended interval), or ``target`` for specific -DAMON monitoring target filtering. Meaning of the types are same to the -description on the :ref:`design doc `. +Each filter directory contains seven files, namely ``type``, ``matching``, +``allow``, ``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx`= `. +To ``type`` file, you can write one of five special keywords: ``anon`` for +anonymous pages, ``memcg`` for specific memory cgroup, ``young`` for young +pages, ``addr`` for specific address range (an open-ended interval), or +``target`` for specific DAMON monitoring target filtering. Meaning of the +types are same to the description on the :ref:`design doc +`. =20 In case of the memory cgroup filtering, you can specify the memory cgroup = of the interest by writing the path of the memory cgroup from the cgroups mou= nt @@ -422,25 +423,29 @@ specify the start and end address of the range to ``a= ddr_start`` and you can specify the index of the target between the list of the DAMON cont= ext's monitoring targets list to ``target_idx`` file. =20 -You can write ``Y`` or ``N`` to ``matching`` file to filter out pages that= does -or does not match to the type, respectively. Then, the scheme's action wi= ll -not be applied to the pages that specified to be filtered out. +You can write ``Y`` or ``N`` to ``matching`` file to specify whether the f= ilter +is for memory that matches the ``type``. You can write ``Y`` or ``N`` to +``allow`` file to specify if applying the action to the memory that satisf= ies +the ``type`` and ``matching`` should be allowed or not. =20 For example, below restricts a DAMOS action to be applied to only non-anon= ymous pages of all memory cgroups except ``/having_care_already``.:: =20 # echo 2 > nr_filters - # # filter out anonymous pages + # # disallow anonymous pages echo anon > 0/type echo Y > 0/matching + echo N > 0/allow # # further filter out all cgroups except one at '/having_care_already' echo memcg > 1/type echo /having_care_already > 1/memcg_path echo Y > 1/matching + echo N > 1/allow =20 Refer to the :ref:`DAMOS filters design documentation -` for more details including when each of the -filters are supported and differences on stats. +` for more details including how multiple filt= ers +of different ``allow`` works, when each of the filters are supported, and +differences on stats. =20 .. _sysfs_schemes_stats: =20 --=20 2.39.5