Skip to content

Commit

Permalink
mm/damon: Remove duplicate get_monitoring_region() definitions
Browse files Browse the repository at this point in the history
In lru_sort.c and reclaim.c, they are all define get_monitoring_region()
function, there is no need to define it separately.

BTW, this patch remove tow struct 'damon_lru_sort_ram_walk_arg' and
'damon_reclaim_ram_walk_arg', though the two struct are removed, if we
want to add more fields to these struct for other purposes later, it will
not too late for us to use them again.
For example:
    struct damon_reclaim_ram_walk_arg {
	struct damon_addr_range raw_walk;
	xxx  A;
	xxx  B;
    }
    struct damon_lru_sort_ram_walk_arg {
	struct damon_addr_range raw_walk;
	xxx  A;
	xxx  B;
    }

Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
  • Loading branch information
Xin Hao authored and intel-lab-lkp committed Sep 7, 2022
1 parent 0066f1b commit 28cd0cc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 66 deletions.
35 changes: 2 additions & 33 deletions mm/damon/lru_sort.c
Expand Up @@ -13,6 +13,8 @@
#include <linux/sched.h>
#include <linux/workqueue.h>

#include "ops-common.h"

#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
Expand Down Expand Up @@ -257,39 +259,6 @@ module_param(nr_cold_quota_exceeds, ulong, 0400);
static struct damon_ctx *ctx;
static struct damon_target *target;

struct damon_lru_sort_ram_walk_arg {
unsigned long start;
unsigned long end;
};

static int walk_system_ram(struct resource *res, void *arg)
{
struct damon_lru_sort_ram_walk_arg *a = arg;

if (a->end - a->start < resource_size(res)) {
a->start = res->start;
a->end = res->end;
}
return 0;
}

/*
* Find biggest 'System RAM' resource and store its start and end address in
* @start and @end, respectively. If no System RAM is found, returns false.
*/
static bool get_monitoring_region(unsigned long *start, unsigned long *end)
{
struct damon_lru_sort_ram_walk_arg arg = {};

walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram);
if (arg.end <= arg.start)
return false;

*start = arg.start;
*end = arg.end;
return true;
}

/* Create a DAMON-based operation scheme for hot memory regions */
static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
{
Expand Down
28 changes: 28 additions & 0 deletions mm/damon/ops-common.c
Expand Up @@ -172,3 +172,31 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r,

return hotness;
}

static inline int walk_system_ram(struct resource *res, void *arg)
{
struct damon_addr_range *a = arg;

if (a->end - a->start < resource_size(res)) {
a->start = res->start;
a->end = res->end;
}
return 0;
}

/*
* Find biggest 'System RAM' resource and store its start and end address in
* @start and @end, respectively. If no System RAM is found, returns false.
*/
bool get_monitoring_region(unsigned long *start, unsigned long *end)
{
struct damon_addr_range arg = {};

walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram);
if (arg.end <= arg.start)
return false;

*start = arg.start;
*end = arg.end;
return true;
}
1 change: 1 addition & 0 deletions mm/damon/ops-common.h
Expand Up @@ -16,3 +16,4 @@ int damon_pageout_score(struct damon_ctx *c, struct damon_region *r,
struct damos *s);
int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
struct damos *s);
bool get_monitoring_region(unsigned long *start, unsigned long *end);
35 changes: 2 additions & 33 deletions mm/damon/reclaim.c
Expand Up @@ -13,6 +13,8 @@
#include <linux/sched.h>
#include <linux/workqueue.h>

#include "ops-common.h"

#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
Expand Down Expand Up @@ -229,39 +231,6 @@ module_param(nr_quota_exceeds, ulong, 0400);
static struct damon_ctx *ctx;
static struct damon_target *target;

struct damon_reclaim_ram_walk_arg {
unsigned long start;
unsigned long end;
};

static int walk_system_ram(struct resource *res, void *arg)
{
struct damon_reclaim_ram_walk_arg *a = arg;

if (a->end - a->start < resource_size(res)) {
a->start = res->start;
a->end = res->end;
}
return 0;
}

/*
* Find biggest 'System RAM' resource and store its start and end address in
* @start and @end, respectively. If no System RAM is found, returns false.
*/
static bool get_monitoring_region(unsigned long *start, unsigned long *end)
{
struct damon_reclaim_ram_walk_arg arg = {};

walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram);
if (arg.end <= arg.start)
return false;

*start = arg.start;
*end = arg.end;
return true;
}

static struct damos *damon_reclaim_new_scheme(void)
{
struct damos_watermarks wmarks = {
Expand Down

0 comments on commit 28cd0cc

Please sign in to comment.