]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/damon: simplify scheme create in lru_sort.c
authorXin Hao <xhao@linux.alibaba.com>
Thu, 15 Sep 2022 13:30:41 +0000 (13:30 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 3 Oct 2022 21:03:26 +0000 (14:03 -0700)
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.

[yangyingliang@huawei.com: change damon_lru_sort_stub_pattern to static]
Link: https://lkml.kernel.org/r/20220917121228.1889699-1-yangyingliang@huawei.com
Link: https://lkml.kernel.org/r/20220915133041.71819-1-sj@kernel.org
Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Suggested-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Xin Hao <xhao@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/lru_sort.c

index 07a0908963fd09b0966b21e0a61f44f27e9c6765..a91c1e364fc7b1405dc916a94ac88525f52c2fa3 100644 (file)
@@ -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);
 
+static struct damos_access_pattern damon_lru_sort_stub_pattern = {
+       /* Find regions having PAGE_SIZE or larger size */
+       .min_sz_region = PAGE_SIZE,
+       .max_sz_region = ULONG_MAX,
+       /* no matter its access frequency */
+       .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,36 +169,19 @@ 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_pattern;
 
+       pattern.min_nr_accesses = hot_thres;
        return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
 }
 
 /* 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_pattern;
 
+       pattern.max_nr_accesses = 0;
+       pattern.min_age_region = cold_thres;
        return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
 }