Skip to contentSkip to conversation

mm/damon: simplify scheme create in lru_sort.c

PATCH In review Xin Hao 2 participants 3 messages Sep 15, 2022

Subsystems (2)
lore
Share & tools
lore

Xin Hao

author
#0 lore raw

PATCH v3 1/1 mm/damon: simplify scheme create in lru_sort.c

In damon_lru_sort_new_hot_scheme() and damon_lru_sort_new_cold_scheme(), they have so much in common, so we can combine them into a single function, and we just need to distinguish their differences.

Changes from v2
(https://lore.kernel.org/linux-mm/[email protected]/)
- Add static global 'struct damos_access_pattern' stub variable

---
 mm/damon/lru_sort.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)
mm/damon/lru_sort.c +19 -22
index 07a0908963fd..6a26c5822286 100644
@@ -132,6 +132,18 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
 		lru_sort_tried_cold_regions, lru_sorted_cold_regions,
 		cold_quota_exceeds);
 
+struct damos_access_pattern damon_lru_sort_stub_access_pattern = {
+	/* Find regions having PAGE_SIZE or larger size */
+	.min_sz_region = PAGE_SIZE,
+	.max_sz_region = ULONG_MAX,
+	/* and accessed for more than the threshold */
+	.min_nr_accesses = 0,
+	.max_nr_accesses = UINT_MAX,
+	/* no matter its age */
+	.min_age_region = 0,
+	.max_age_region = UINT_MAX,
+};
+
 static struct damon_ctx *ctx;
 static struct damon_target *target;
 
@@ -157,17 +169,9 @@ static struct damos *damon_lru_sort_new_scheme(
 /* Create a DAMON-based operation scheme for hot memory regions */
 static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
 {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and accessed for more than the threshold */
-		.min_nr_accesses = hot_thres,
-		.max_nr_accesses = UINT_MAX,
-		/* no matter its age */
-		.min_age_region = 0,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;
+
+	pattern.min_nr_accesses = hot_thres;
 
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
 }
@@ -175,17 +179,10 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
 /* Create a DAMON-based operation scheme for cold memory regions */
 static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
 {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and not accessed at all */
-		.min_nr_accesses = 0,
-		.max_nr_accesses = 0,
-		/* for min_age or more micro-seconds */
-		.min_age_region = cold_thres,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;
+
+	pattern.max_nr_accesses = 0;
+	pattern.min_age_region = cold_thres;
 
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
 }

--
2.31.0

maintainer
#1 lore raw

Hi Xin,

Quoted 9 lines · On Thu, 15 Sep 2022 10:36:55 +0800 Xin Hao <[email protected]> wrote:

In damon_lru_sort_new_hot_scheme() and damon_lru_sort_new_cold_scheme(), they have so much in common, so we can combine them into a single function, and we just need to distinguish their differences.

Changes from v2
(https://lore.kernel.org/linux-mm/[email protected]/)
- Add static global 'struct damos_access_pattern' stub variable

Chagelog should not be in the commit message area,

Quoted 1 line

---

but here.

Quoted 8 lines
 mm/damon/lru_sort.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)
mm/damon/lru_sort.c +0 -0
index 07a0908963fd..6a26c5822286 100644

mm/damon/lru_sort.c DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, · line 139

Quoted 8 lines
mm/damon/lru_sort.c +5 -0
@@ -132,6 +132,18 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
 		lru_sort_tried_cold_regions, lru_sorted_cold_regions,
 		cold_quota_exceeds);
 
+struct damos_access_pattern damon_lru_sort_stub_access_pattern = {
+	/* Find regions having PAGE_SIZE or larger size */
+	.min_sz_region = PAGE_SIZE,
+	.max_sz_region = ULONG_MAX,
+	/* and accessed for more than the threshold */

This comment looks inappropriate. How about 'no matter its access frequency'?

Quoted 16 lines
mm/damon/lru_sort.c +7 -2
+	.min_nr_accesses = 0,
+	.max_nr_accesses = UINT_MAX,
+	/* no matter its age */
+	.min_age_region = 0,
+	.max_age_region = UINT_MAX,
+};
+
 static struct damon_ctx *ctx;
 static struct damon_target *target;
 
@@ -157,17 +169,9 @@ static struct damos *damon_lru_sort_new_scheme(
 /* Create a DAMON-based operation scheme for hot memory regions */
 static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
 {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */

mm/damon/lru_sort.c static struct damos *damon_lru_sort_new_scheme( · line 172

Quoted 10 lines
mm/damon/lru_sort.c +1 -9
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and accessed for more than the threshold */
-		.min_nr_accesses = hot_thres,
-		.max_nr_accesses = UINT_MAX,
-		/* no matter its age */
-		.min_age_region = 0,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;

More than 80 columns. Renaming stub_access_pattern into stub_pattern might make sense.

Quoted 11 lines
mm/damon/lru_sort.c +2 -2
+
+	pattern.min_nr_accesses = hot_thres;
 
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
 }
@@ -175,17 +179,10 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
 /* Create a DAMON-based operation scheme for cold memory regions */
 static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
 {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */

mm/damon/lru_sort.c static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) · line 182

Quoted 10 lines
mm/damon/lru_sort.c +1 -9
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and not accessed at all */
-		.min_nr_accesses = 0,
-		.max_nr_accesses = 0,
-		/* for min_age or more micro-seconds */
-		.min_age_region = cold_thres,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;

More than 80 columns.

Quoted 8 lines
mm/damon/lru_sort.c +3 -1
+
+	pattern.max_nr_accesses = 0;
+	pattern.min_age_region = cold_thres;
 
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
 }
--

2.31.0

Other than the trivial things, look good. As my comments are only for trivial cosmetic things, I will make the change and post v4 on my own.

Thanks,
SJ

author
#2 lore raw
Quoted 92 lines · SeongJae Park

Hi Xin,

Quoted 9 lines · On Thu, 15 Sep 2022 10:36:55 +0800 Xin Hao <[email protected]> wrote:

In damon_lru_sort_new_hot_scheme() and damon_lru_sort_new_cold_scheme(), they have so much in common, so we can combine them into a single function, and we just need to distinguish their differences.

Changes from v2
(https://lore.kernel.org/linux-mm/[email protected]/)
- Add static global 'struct damos_access_pattern' stub variable

Chagelog should not be in the commit message area,

Quoted 1 line

---

but here.

Quoted 8 lines
  mm/damon/lru_sort.c | 41 +++++++++++++++++++----------------------
  1 file changed, 19 insertions(+), 22 deletions(-)
mm/damon/lru_sort.c +0 -0
index 07a0908963fd..6a26c5822286 100644

mm/damon/lru_sort.c DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, · line 139

Quoted 8 lines
mm/damon/lru_sort.c +5 -0
@@ -132,6 +132,18 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
  		lru_sort_tried_cold_regions, lru_sorted_cold_regions,
  		cold_quota_exceeds);
 
+struct damos_access_pattern damon_lru_sort_stub_access_pattern = {
+	/* Find regions having PAGE_SIZE or larger size */
+	.min_sz_region = PAGE_SIZE,
+	.max_sz_region = ULONG_MAX,
+	/* and accessed for more than the threshold */

This comment looks inappropriate. How about 'no matter its access frequency'?

Quoted 16 lines
mm/damon/lru_sort.c +7 -2
+	.min_nr_accesses = 0,
+	.max_nr_accesses = UINT_MAX,
+	/* no matter its age */
+	.min_age_region = 0,
+	.max_age_region = UINT_MAX,
+};
+
  static struct damon_ctx *ctx;
  static struct damon_target *target;
 
@@ -157,17 +169,9 @@ static struct damos *damon_lru_sort_new_scheme(
  /* Create a DAMON-based operation scheme for hot memory regions */
  static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
  {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */

mm/damon/lru_sort.c static struct damos *damon_lru_sort_new_scheme( · line 172

Quoted 10 lines
mm/damon/lru_sort.c +1 -9
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and accessed for more than the threshold */
-		.min_nr_accesses = hot_thres,
-		.max_nr_accesses = UINT_MAX,
-		/* no matter its age */
-		.min_age_region = 0,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;

More than 80 columns. Renaming stub_access_pattern into stub_pattern might make sense.

Quoted 11 lines
mm/damon/lru_sort.c +2 -2
+
+	pattern.min_nr_accesses = hot_thres;
 
  	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
  }
@@ -175,17 +179,10 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
  /* Create a DAMON-based operation scheme for cold memory regions */
  static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
  {
-	struct damos_access_pattern pattern = {
-		/* Find regions having PAGE_SIZE or larger size */

mm/damon/lru_sort.c static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) · line 182

Quoted 10 lines
mm/damon/lru_sort.c +1 -9
-		.min_sz_region = PAGE_SIZE,
-		.max_sz_region = ULONG_MAX,
-		/* and not accessed at all */
-		.min_nr_accesses = 0,
-		.max_nr_accesses = 0,
-		/* for min_age or more micro-seconds */
-		.min_age_region = cold_thres,
-		.max_age_region = UINT_MAX,
-	};
+	struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern;

More than 80 columns.

Quoted 4 lines
mm/damon/lru_sort.c +3 -0
+
+	pattern.max_nr_accesses = 0;
+	pattern.min_age_region = cold_thres;
 
Quoted 6 lines
Quoted 4 lines
mm/damon/lru_sort.c +0 -1
  	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
  }
--

2.31.0

Other than the trivial things, look good. As my comments are only for trivial cosmetic things, I will make the change and post v4 on my own.

Ok,  thank you very much for such a detailed review.

Quoted 3 lines

Thanks,
SJ