Re: [PATCH v9.1] mm/damon: add node_eligible_mem_bp goal metric

From: SeongJae Park

Date: Mon Apr 27 2026 - 10:51:43 EST


On Sun, 26 Apr 2026 18:02:09 -0700 Ravi Jonnalagadda <ravis.opensrc@xxxxxxxxx> wrote:
[...]
> +static phys_addr_t damos_calc_eligible_bytes(struct damon_ctx *c,
> + struct damos *s, int nid, phys_addr_t *total)
> +{
> + struct damon_target *t;
> + struct damon_region *r;
> + phys_addr_t total_eligible = 0;
> + phys_addr_t node_eligible = 0;
> +
> + damon_for_each_target(t, c) {
> + damon_for_each_region(r, t) {
> + phys_addr_t addr, end_addr;
> +
> + if (!__damos_valid_target(r, s))
> + continue;
> +
> + /* Convert from core address units to physical bytes */
> + addr = (phys_addr_t)r->ar.start * c->addr_unit;
> + end_addr = (phys_addr_t)r->ar.end * c->addr_unit;
> + while (addr < end_addr) {
> + struct folio *folio;
> + phys_addr_t folio_start, folio_end;
> + phys_addr_t overlap_start, overlap_end;
> + phys_addr_t counted;
> +
> + folio = damon_get_folio(PHYS_PFN(addr));
> + if (!folio) {
> + addr = PAGE_ALIGN_DOWN(addr + PAGE_SIZE);
> + continue;
> + }

Sashiko found this could result in an infinite loop if 'addr + PAGE_SIZE'
overflows. The probability is quite low, but could we fix this? Maybe like
below?

'''
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2349,7 +2349,10 @@ static phys_addr_t damos_calc_eligible_bytes(struct damon_ctx *c,

folio = damon_get_folio(PHYS_PFN(addr));
if (!folio) {
- addr = PAGE_ALIGN_DOWN(addr + PAGE_SIZE);
+ addr = PAGE_ALIGN_DOWN(addr +
+ PAGE_SIZE);
+ if (!addr)
+ break;
continue;
}
'''

Ravi, could you please post one more version (maybe v9.2) with the abive fix if
it looks good to you?

[1] https://lore.kernel.org/20260427012429.D25C2C2BCAF@xxxxxxxxxxxxxxx


Thanks,
SJ

[...]