2023-09-20 01:58:49

by Huan Yang

[permalink] [raw]
Subject: [PATCH v3] mm/damon/core: remove unnecessary si_meminfo invoke.

si_meminfo() will read and assign more info not just free/ram pages.
For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages
is ok to save cpu.

Signed-off-by: Huan Yang <[email protected]>
---
Change from v1:
v1 fold free mem rate logic into __damos_get_wmark_free_mem_rate and not
invoke si_meminfo, just get free/ram_pages in global.
v2 cancel this __damos_get_wmark_free_mem_rate and just calculate rate
in damos_wmark_metric_value to keep it simple.
v3 fix changelog format, fix code style.


mm/damon/core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index bcd2bd9d6c10..6ceb52298904 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1280,12 +1280,10 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)

static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
{
- struct sysinfo i;
-
switch (metric) {
case DAMOS_WMARK_FREE_MEM_RATE:
- si_meminfo(&i);
- return i.freeram * 1000 / i.totalram;
+ return global_zone_page_state(NR_FREE_PAGES) * 1000 /
+ totalram_pages();
default:
break;
}
--
2.34.1


2023-09-20 07:21:16

by SeongJae Park

[permalink] [raw]
Subject: Re: [PATCH v3] mm/damon/core: remove unnecessary si_meminfo invoke.

Hi Huan,

On Wed, 20 Sep 2023 09:57:27 +0800 Huan Yang <[email protected]> wrote:

> si_meminfo() will read and assign more info not just free/ram pages.
> For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages
> is ok to save cpu.
>
> Signed-off-by: Huan Yang <[email protected]>

Reviewed-by: SeongJae Park <[email protected]>


Thanks,
SJ

> ---
> Change from v1:
> v1 fold free mem rate logic into __damos_get_wmark_free_mem_rate and not
> invoke si_meminfo, just get free/ram_pages in global.
> v2 cancel this __damos_get_wmark_free_mem_rate and just calculate rate
> in damos_wmark_metric_value to keep it simple.
> v3 fix changelog format, fix code style.
>
>
> mm/damon/core.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index bcd2bd9d6c10..6ceb52298904 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1280,12 +1280,10 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
>
> static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
> {
> - struct sysinfo i;
> -
> switch (metric) {
> case DAMOS_WMARK_FREE_MEM_RATE:
> - si_meminfo(&i);
> - return i.freeram * 1000 / i.totalram;
> + return global_zone_page_state(NR_FREE_PAGES) * 1000 /
> + totalram_pages();
> default:
> break;
> }
> --
> 2.34.1