Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

[sj@kernel.org: return error if monitoring target region is invalid]
Link: https://lkml.kernel.org/r/20260317053631.87907-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20260316235118.873-1-sj@kernel.org
Fixes: 369c415e6073 ("mm/damon: introduce DAMON_STAT module")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> [6.17+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
84481e70 631c1111

+50 -3
+50 -3
mm/damon/stat.c
··· 145 145 return 0; 146 146 } 147 147 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 + 148 196 static struct damon_ctx *damon_stat_build_ctx(void) 149 197 { 150 198 struct damon_ctx *ctx; 151 199 struct damon_attrs attrs; 152 200 struct damon_target *target; 153 - unsigned long start = 0, end = 0; 154 201 155 202 ctx = damon_new_ctx(); 156 203 if (!ctx) ··· 227 180 if (!target) 228 181 goto free_out; 229 182 damon_add_target(ctx, target); 230 - if (damon_set_region_biggest_system_ram_default(target, &start, &end, 231 - ctx->min_region_sz)) 183 + if (damon_stat_set_monitoring_region(target, ctx->addr_unit, 184 + ctx->min_region_sz)) 232 185 goto free_out; 233 186 return ctx; 234 187 free_out: