Skip to content

Commit 84481e7

Browse files
sjp38akpm00
authored andcommitted
mm/damon/stat: monitor all System RAM resources
DAMON_STAT usage document (Documentation/admin-guide/mm/damon/stat.rst) says it monitors the system's entire physical memory. But, it is monitoring only the biggest System RAM resource of the system. When there are multiple System RAM resources, this results in monitoring only an unexpectedly small fraction of the physical memory. For example, suppose the system has a 500 GiB System RAM, 10 MiB non-System RAM, and 500 GiB System RAM resources in order on the physical address space. DAMON_STAT will monitor only the first 500 GiB System RAM. This situation is particularly common on NUMA systems. Select a physical address range that covers all System RAM areas of the system, to fix this issue and make it work as documented. [[email protected]: return error if monitoring target region is invalid] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 369c415 ("mm/damon: introduce DAMON_STAT module") Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [6.17+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 631c111 commit 84481e7

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

mm/damon/stat.c

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,59 @@ static int damon_stat_damon_call_fn(void *data)
145145
return 0;
146146
}
147147

148+
struct damon_stat_system_ram_range_walk_arg {
149+
bool walked;
150+
struct resource res;
151+
};
152+
153+
static int damon_stat_system_ram_walk_fn(struct resource *res, void *arg)
154+
{
155+
struct damon_stat_system_ram_range_walk_arg *a = arg;
156+
157+
if (!a->walked) {
158+
a->walked = true;
159+
a->res.start = res->start;
160+
}
161+
a->res.end = res->end;
162+
return 0;
163+
}
164+
165+
static unsigned long damon_stat_res_to_core_addr(resource_size_t ra,
166+
unsigned long addr_unit)
167+
{
168+
/*
169+
* Use div_u64() for avoiding linking errors related with __udivdi3,
170+
* __aeabi_uldivmod, or similar problems. This should also improve the
171+
* performance optimization (read div_u64() comment for the detail).
172+
*/
173+
if (sizeof(ra) == 8 && sizeof(addr_unit) == 4)
174+
return div_u64(ra, addr_unit);
175+
return ra / addr_unit;
176+
}
177+
178+
static int damon_stat_set_monitoring_region(struct damon_target *t,
179+
unsigned long addr_unit, unsigned long min_region_sz)
180+
{
181+
struct damon_addr_range addr_range;
182+
struct damon_stat_system_ram_range_walk_arg arg = {};
183+
184+
walk_system_ram_res(0, -1, &arg, damon_stat_system_ram_walk_fn);
185+
if (!arg.walked)
186+
return -EINVAL;
187+
addr_range.start = damon_stat_res_to_core_addr(
188+
arg.res.start, addr_unit);
189+
addr_range.end = damon_stat_res_to_core_addr(
190+
arg.res.end + 1, addr_unit);
191+
if (addr_range.end <= addr_range.start)
192+
return -EINVAL;
193+
return damon_set_regions(t, &addr_range, 1, min_region_sz);
194+
}
195+
148196
static struct damon_ctx *damon_stat_build_ctx(void)
149197
{
150198
struct damon_ctx *ctx;
151199
struct damon_attrs attrs;
152200
struct damon_target *target;
153-
unsigned long start = 0, end = 0;
154201

155202
ctx = damon_new_ctx();
156203
if (!ctx)
@@ -180,8 +227,8 @@ static struct damon_ctx *damon_stat_build_ctx(void)
180227
if (!target)
181228
goto free_out;
182229
damon_add_target(ctx, target);
183-
if (damon_set_region_biggest_system_ram_default(target, &start, &end,
184-
ctx->min_region_sz))
230+
if (damon_stat_set_monitoring_region(target, ctx->addr_unit,
231+
ctx->min_region_sz))
185232
goto free_out;
186233
return ctx;
187234
free_out:

0 commit comments

Comments
 (0)