[RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state

Quanmin Yan posted 16 patches 1 month, 3 weeks ago
There is a newer version of this series
[RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state
Posted by Quanmin Yan 1 month, 3 weeks ago
After introducing ctx->addr_unit, the unit of sz might not
be in bytes. However, sz_applied is returned in bytes after
processing by paddr. To maintain external consistency, sz
is converted to byte units when updating the state.

Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index b162aa1156fc..bc764f9dc5c5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1889,7 +1889,9 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 		r->age = 0;
 
 update_stat:
-	damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed);
+	damos_update_stat(s,
+			sz * (c->ops.id == DAMON_OPS_PADDR ? c->addr_unit : 1),
+			sz_applied, sz_ops_filter_passed);
 }
 
 static void damon_do_apply_schemes(struct damon_ctx *c,
-- 
2.34.1
Re: [RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state
Posted by SeongJae Park 1 month, 3 weeks ago
On Wed, 13 Aug 2025 13:07:04 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> After introducing ctx->addr_unit, the unit of sz might not
> be in bytes. However, sz_applied is returned in bytes after
> processing by paddr.

This is not an intended behavior, but a bug of my code.  Let's update patches
3-6 of this series to return sz_applied as core-layer address unit, instead of
bytes.

> To maintain external consistency, sz
> is converted to byte units when updating the state.

Users could keep the consistency by multiplying the addr_unit, which they set
themselves.

> 
> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
> ---
>  mm/damon/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index b162aa1156fc..bc764f9dc5c5 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1889,7 +1889,9 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
>  		r->age = 0;
>  
>  update_stat:
> -	damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed);
> +	damos_update_stat(s,
> +			sz * (c->ops.id == DAMON_OPS_PADDR ? c->addr_unit : 1),
> +			sz_applied, sz_ops_filter_passed);
>  }
>  
>  static void damon_do_apply_schemes(struct damon_ctx *c,
> -- 
> 2.34.1


Thanks,
SJ
Re: [RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state
Posted by Quanmin Yan 1 month, 2 weeks ago
Hi SJ,

在 2025/8/14 1:08, SeongJae Park 写道:
> On Wed, 13 Aug 2025 13:07:04 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:
>
>> After introducing ctx->addr_unit, the unit of sz might not
>> be in bytes. However, sz_applied is returned in bytes after
>> processing by paddr.
> This is not an intended behavior, but a bug of my code.  Let's update patches
> 3-6 of this series to return sz_applied as core-layer address unit, instead of
> bytes.
>
>> To maintain external consistency, sz
>> is converted to byte units when updating the state.
> Users could keep the consistency by multiplying the addr_unit, which they set
> themselves.

Thanks for the clarification! this patch has been dropped from the v2 series.

Thanks,
Quanmin Yan