linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Quanmin Yan <yanquanmin1@huawei.com>
To: <sj@kernel.org>
Cc: <akpm@linux-foundation.org>, <damon@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<yanquanmin1@huawei.com>, <wangkefeng.wang@huawei.com>,
	<zuoze1@huawei.com>
Subject: [PATCH 02/11] mm/damon/paddr: support addr_unit for access monitoring
Date: Thu, 21 Aug 2025 18:51:50 +0800	[thread overview]
Message-ID: <20250821105159.2503894-3-yanquanmin1@huawei.com> (raw)
In-Reply-To: <20250821105159.2503894-1-yanquanmin1@huawei.com>

From: SeongJae Park <sj@kernel.org>

Add support of addr_unit paramer for access monitoing operations of
paddr.

Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/paddr.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 0b67d9321460..d497373c2bd2 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -18,7 +18,13 @@
 #include "../internal.h"
 #include "ops-common.h"
 
-static void damon_pa_mkold(unsigned long paddr)
+static phys_addr_t damon_pa_phys_addr(
+		unsigned long addr, unsigned long addr_unit)
+{
+	return (phys_addr_t)addr * addr_unit;
+}
+
+static void damon_pa_mkold(phys_addr_t paddr)
 {
 	struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
 
@@ -29,11 +35,12 @@ static void damon_pa_mkold(unsigned long paddr)
 	folio_put(folio);
 }
 
-static void __damon_pa_prepare_access_check(struct damon_region *r)
+static void __damon_pa_prepare_access_check(struct damon_region *r,
+		unsigned long addr_unit)
 {
 	r->sampling_addr = damon_rand(r->ar.start, r->ar.end);
 
-	damon_pa_mkold(r->sampling_addr);
+	damon_pa_mkold(damon_pa_phys_addr(r->sampling_addr, addr_unit));
 }
 
 static void damon_pa_prepare_access_checks(struct damon_ctx *ctx)
@@ -43,11 +50,11 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx)
 
 	damon_for_each_target(t, ctx) {
 		damon_for_each_region(r, t)
-			__damon_pa_prepare_access_check(r);
+			__damon_pa_prepare_access_check(r, ctx->addr_unit);
 	}
 }
 
-static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
+static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz)
 {
 	struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
 	bool accessed;
@@ -62,23 +69,25 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
 }
 
 static void __damon_pa_check_access(struct damon_region *r,
-		struct damon_attrs *attrs)
+		struct damon_attrs *attrs, unsigned long addr_unit)
 {
-	static unsigned long last_addr;
+	static phys_addr_t last_addr;
 	static unsigned long last_folio_sz = PAGE_SIZE;
 	static bool last_accessed;
+	phys_addr_t sampling_addr = damon_pa_phys_addr(
+			r->sampling_addr, addr_unit);
 
 	/* If the region is in the last checked page, reuse the result */
 	if (ALIGN_DOWN(last_addr, last_folio_sz) ==
-				ALIGN_DOWN(r->sampling_addr, last_folio_sz)) {
+				ALIGN_DOWN(sampling_addr, last_folio_sz)) {
 		damon_update_region_access_rate(r, last_accessed, attrs);
 		return;
 	}
 
-	last_accessed = damon_pa_young(r->sampling_addr, &last_folio_sz);
+	last_accessed = damon_pa_young(sampling_addr, &last_folio_sz);
 	damon_update_region_access_rate(r, last_accessed, attrs);
 
-	last_addr = r->sampling_addr;
+	last_addr = sampling_addr;
 }
 
 static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
@@ -89,7 +98,8 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
 
 	damon_for_each_target(t, ctx) {
 		damon_for_each_region(r, t) {
-			__damon_pa_check_access(r, &ctx->attrs);
+			__damon_pa_check_access(
+					r, &ctx->attrs, ctx->addr_unit);
 			max_nr_accesses = max(r->nr_accesses, max_nr_accesses);
 		}
 	}
-- 
2.43.0



  parent reply	other threads:[~2025-08-21 11:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 10:51 [PATCH 00/11] mm/damon: support ARM32 with LPAE Quanmin Yan
2025-08-21 10:51 ` [PATCH 01/11] mm/damon/core: add damon_ctx->addr_unit Quanmin Yan
2025-08-21 17:10   ` SeongJae Park
2025-08-21 10:51 ` Quanmin Yan [this message]
2025-08-21 17:12   ` [PATCH 02/11] mm/damon/paddr: support addr_unit for access monitoring SeongJae Park
2025-08-21 10:51 ` [PATCH 03/11] mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT Quanmin Yan
2025-08-21 17:14   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 04/11] mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO Quanmin Yan
2025-08-21 17:16   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 05/11] mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD} Quanmin Yan
2025-08-21 17:18   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 06/11] mm/damon/paddr: support addr_unit for DAMOS_STAT Quanmin Yan
2025-08-21 17:19   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 07/11] mm/damon/sysfs: implement addr_unit file under context dir Quanmin Yan
2025-08-21 17:21   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 08/11] Docs/mm/damon/design: document 'address unit' parameter Quanmin Yan
2025-08-21 17:22   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 09/11] Docs/admin-guide/mm/damon/usage: document addr_unit file Quanmin Yan
2025-08-21 17:23   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 10/11] Docs/ABI/damon: " Quanmin Yan
2025-08-21 17:24   ` SeongJae Park
2025-08-21 10:51 ` [PATCH 11/11] mm/damon: add damon_ctx->min_region Quanmin Yan
2025-08-21 17:33   ` SeongJae Park
2025-08-22  1:29     ` Quanmin Yan
2025-08-22 18:03       ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250821105159.2503894-3-yanquanmin1@huawei.com \
    --to=yanquanmin1@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=zuoze1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox