Skip to contentSkip to conversation

mm/damon/core: remove unnecessary si_meminfo invoke.

PATCH Superseded Huan Yang 2 participants 6 messages Sep 18, 2023 – Sep 19, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Huan Yang

author
#0 lore raw

PATCH 1/1 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.

---
 mm/damon/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +6 -4
index bcd2bd9d6c10..1cddee9ae73b 100644
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
 	return true;
 }
 
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)
 {
-	struct sysinfo i;
+	return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
 	switch (metric) {
 	case DAMOS_WMARK_FREE_MEM_RATE:
-		si_meminfo(&i);
-		return i.freeram * 1000 / i.totalram;
+		return __damons_get_wmark_free_mem_rate();
 	default:
 		break;
 	}
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi Huan,

Quoted 1 line · On Mon, 18 Sep 2023 17:49:34 +0800 Huan Yang <[email protected]> wrote:

si_meminfo() will read and assign more info not just free/ram pages.

Nice catch :)

Quoted 13 lines

For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages is ok to save cpu.

---
 mm/damon/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index bcd2bd9d6c10..1cddee9ae73b 100644

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1281

Quoted 5 lines
mm/damon/core.c +1 -1
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
 	return true;
 }
 
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)

Nit. s/damons/damos/ would look more consistently, in my opinion?

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1290

Quoted 12 lines
mm/damon/core.c +5 -3
 {
-	struct sysinfo i;
+	return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
 	switch (metric) {
 	case DAMOS_WMARK_FREE_MEM_RATE:
-		si_meminfo(&i);
-		return i.freeram * 1000 / i.totalram;
+		return __damons_get_wmark_free_mem_rate();

Since __damons_get_wmark_free_mem_rate() is just one line function and damos_wmark_metric_value() is the only user of the code, I think we could just writ the code here?

Quoted 5 lines
mm/damon/core.c +0 -0
 	default:
 		break;
 	}
Signature · 1 line
2.34.1

Thanks,
SJ

author
#2 lore raw
Quoted 23 lines · SeongJae Park

Hi Huan,

Quoted 1 line · On Mon, 18 Sep 2023 17:49:34 +0800 Huan Yang <[email protected]> wrote:

si_meminfo() will read and assign more info not just free/ram pages.

Nice catch :)

Quoted 16 lines

For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages is ok to save cpu.

---
  mm/damon/core.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index bcd2bd9d6c10..1cddee9ae73b 100644
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
  	return true;
  }
 
Quoted 3 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1281

Quoted 2 lines
mm/damon/core.c +1 -1
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)

Nit. s/damons/damos/ would look more consistently, in my opinion?

HI, SJ, sorry, what's this mean?

Quoted 6 lines
Quoted 6 lines
mm/damon/core.c +2 -1
  {
-	struct sysinfo i;
+	return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
Quoted 10 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1290

Quoted 7 lines
mm/damon/core.c +3 -2
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
  	switch (metric) {
  	case DAMOS_WMARK_FREE_MEM_RATE:
-		si_meminfo(&i);
-		return i.freeram * 1000 / i.totalram;
+		return __damons_get_wmark_free_mem_rate();

Since __damons_get_wmark_free_mem_rate() is just one line function and damos_wmark_metric_value() is the only user of the code, I think we could just writ the code here?

I do this in mine first patch, but then, I fold this into "__damons_get_wmark_free_mem_rate"

due to I think the "__damons_get_wmark_free_mem_rate" may change the meaning for furture,

and may si_meminfo will come back soon?(If we need more info to get the rate?). And, also, the

static function If just some user use, it will be inline, so, I just think fold it will be better.

Do you think so?

Thanks,

Huan

Quoted 9 lines
Quoted 6 lines
mm/damon/core.c +0 -0
  	default:
  		break;
  	}
Signature · 1 line
2.34.1

Thanks,
SJ

author
#3 lore raw
Quoted 24 lines · 杨欢
Quoted 23 lines · SeongJae Park

Hi Huan,

Quoted 1 line · On Mon, 18 Sep 2023 17:49:34 +0800 Huan Yang <[email protected]> wrote:

si_meminfo() will read and assign more info not just free/ram pages.

Nice catch :)

Quoted 16 lines

For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages is ok to save cpu.

---
   mm/damon/core.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index bcd2bd9d6c10..1cddee9ae73b 100644
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
   	return true;
   }
 
Quoted 4 lines
Quoted 3 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1281

Quoted 2 lines
mm/damon/core.c +1 -1
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)

Nit. s/damons/damos/ would look more consistently, in my opinion?

HI, SJ, sorry, what's this mean?

Haha, I get, yes, damos is better. If you agree with below, I will resend a new, rename to

__damos_get_wmark_free_mem_rate.

Quoted 41 lines
Quoted 5 lines
Quoted 5 lines
mm/damon/core.c +2 -1
   {
-	struct sysinfo i;
+	return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
Quoted 10 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1290

Quoted 7 lines
mm/damon/core.c +3 -2
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
   	switch (metric) {
   	case DAMOS_WMARK_FREE_MEM_RATE:
-		si_meminfo(&i);
-		return i.freeram * 1000 / i.totalram;
+		return __damons_get_wmark_free_mem_rate();

Since __damons_get_wmark_free_mem_rate() is just one line function and damos_wmark_metric_value() is the only user of the code, I think we could just writ the code here?

I do this in mine first patch, but then, I fold this into "__damons_get_wmark_free_mem_rate"

due to I think the "__damons_get_wmark_free_mem_rate" may change the meaning for furture,

and may si_meminfo will come back soon?(If we need more info to get the rate?). And, also, the

static function If just some user use, it will be inline, so, I just think fold it will be better.

Do you think so?

Thanks,

Huan

Quoted 7 lines
Quoted 5 lines
mm/damon/core.c +0 -0
   	default:
   		break;
   	}
Signature · 1 line
2.34.1

Thanks,
SJ

maintainer
#4 lore raw

Hi Huan,

Quoted 28 lines · On Mon, 18 Sep 2023 12:12:01 +0000 杨欢 <[email protected]> wrote:
Quoted 27 lines · 杨欢
Quoted 26 lines · SeongJae Park

Hi Huan,

Quoted 1 line · On Mon, 18 Sep 2023 17:49:34 +0800 Huan Yang <[email protected]> wrote:

si_meminfo() will read and assign more info not just free/ram pages.

Nice catch :)

Quoted 13 lines

For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages is ok to save cpu.

---
   mm/damon/core.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index bcd2bd9d6c10..1cddee9ae73b 100644

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1281

Quoted 5 lines
mm/damon/core.c +1 -1
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
   	return true;
   }
 
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)

Nit. s/damons/damos/ would look more consistently, in my opinion?

Quoted 37 lines
Quoted 1 line

HI, SJ, sorry, what's this mean?

Haha, I get, yes, damos is better. If you agree with below, I will resend a new, rename to

__damos_get_wmark_free_mem_rate.

Quoted 30 lines
Quoted 5 lines
Quoted 5 lines
mm/damon/core.c +2 -1
   {
-	struct sysinfo i;
+	return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
Quoted 11 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1290

Quoted 7 lines
mm/damon/core.c +3 -2
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
   	switch (metric) {
   	case DAMOS_WMARK_FREE_MEM_RATE:
-		si_meminfo(&i);
-		return i.freeram * 1000 / i.totalram;
+		return __damons_get_wmark_free_mem_rate();

Since __damons_get_wmark_free_mem_rate() is just one line function and damos_wmark_metric_value() is the only user of the code, I think we could just writ the code here?

I do this in mine first patch, but then, I fold this into "__damons_get_wmark_free_mem_rate"

due to I think the "__damons_get_wmark_free_mem_rate" may change the meaning for furture,

and may si_meminfo will come back soon?(If we need more info to get the rate?). And, also, the

static function If just some user use, it will be inline, so, I just think fold it will be better.

Do you think so?

Unfortunately I don't think so. What would be the future use case that would require changing the meaning of the metric? I cannot imagine those off the top of my head. Even if such use case is found, such change would be a user-visible behavioral change, which we would like to avoid. If such change is really needed, I think we would keep the current metric as is and create an alternative metric that having the new meaning. Anyway, we can think about such case when it really happened.

Also, the current code is doing the calculation in damos_wmark_metric_value(). If there is no specific reason to split the logic out to a new function, I'd prefer keeping the overall structure as similar as is now.

Please let me know if I'm missing something.

Thanks,
SJ

Quoted 15 lines
Quoted 13 lines

Thanks,

Huan

Quoted 7 lines
Quoted 5 lines
mm/damon/core.c +0 -0
   	default:
   		break;
   	}
Signature · 1 line
2.34.1

Thanks,
SJ

author
#5 lore raw
Quoted 64 lines · SeongJae Park

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Hi Huan,

Quoted 58 lines · On Mon, 18 Sep 2023 12:12:01 +0000 杨欢 <[email protected]> wrote:
Quoted 24 lines · 杨欢
Quoted 23 lines · SeongJae Park

Hi Huan,

Quoted 1 line · On Mon, 18 Sep 2023 17:49:34 +0800 Huan Yang <[email protected]> wrote:

si_meminfo() will read and assign more info not just free/ram pages.

Nice catch :)

Quoted 16 lines

For just DAMOS_WMARK_FREE_MEM_RATE use, only get free and ram pages is ok to save cpu.

---
    mm/damon/core.c | 10 ++++++----
    1 file changed, 6 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index bcd2bd9d6c10..1cddee9ae73b 100644
@@ -1278,14 +1278,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
           return true;
    }
 
Quoted 4 lines
Quoted 3 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1281

Quoted 2 lines
mm/damon/core.c +1 -1
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static unsigned long __damons_get_wmark_free_mem_rate(void)

Nit. s/damons/damos/ would look more consistently, in my opinion?

HI, SJ, sorry, what's this mean?

Haha, I get, yes, damos is better. If you agree with below, I will resend a new, rename to

__damos_get_wmark_free_mem_rate.

Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
mm/damon/core.c +2 -1
    {
- struct sysinfo i;
+ return global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages();
+}
 
Quoted 10 lines

mm/damon/core.c static bool kdamond_need_stop(struct damon_ctx *ctx) · line 1290

Quoted 7 lines
mm/damon/core.c +3 -2
+static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+{
           switch (metric) {
           case DAMOS_WMARK_FREE_MEM_RATE:
-         si_meminfo(&i);
-         return i.freeram * 1000 / i.totalram;
+         return __damons_get_wmark_free_mem_rate();

Since __damons_get_wmark_free_mem_rate() is just one line function and damos_wmark_metric_value() is the only user of the code, I think we could just writ the code here?

I do this in mine first patch, but then, I fold this into "__damons_get_wmark_free_mem_rate"

due to I think the "__damons_get_wmark_free_mem_rate" may change the meaning for furture,

and may si_meminfo will come back soon?(If we need more info to get the rate?). And, also, the

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

static function If just some user use, it will be inline, so, I just think fold it will be better.

Do you think so?

Unfortunately I don't think so. What would be the future use case that would require changing the meaning of the metric? I cannot imagine those off the top

Maybe care about [min, low, high] watermark? Or someting. But,

Quoted 5 lines

of my head. Even if such use case is found, such change would be a user-visible behavioral change, which we would like to avoid. If such change is really needed, I think we would keep the current metric as is and create an alternative metric that having the new meaning. Anyway, we can think about such case when it really happened.

Yes, you are right, if need a new case, just create an alternative metric.

Quoted 6 lines

Also, the current code is doing the calculation in damos_wmark_metric_value(). If there is no specific reason to split the logic out to a new function, I'd prefer keeping the overall structure as similar as is now.

Please let me know if I'm missing something.

No sure reason to split it into function, keep it in damos_wmark_metric_value() is

better.

I'll send new patch.

Thanks,

Huan

Quoted 17 lines

Thanks,
SJ

Quoted 12 lines
Quoted 11 lines

Thanks,

Huan

Quoted 7 lines
Quoted 5 lines
mm/damon/core.c +0 -1
           default:
                   break;
           }
--

2.34.1

Thanks,
SJ