From: SJ Park <sj@kernel.org>
To: SJ Park <sj@kernel.org>
Cc: Kyuwon Cho <kyuwon.cho@skku.edu>,
Andrew Morton <akpm@linux-foundation.org>,
Quanmin Yan <yanquanmin1@huawei.com>,
Aveline Noir <jm5905938@gmail.com>,
sashiko-bot@kernel.org, sashiko-reviews@lists.linux.dev,
damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
Date: Fri, 4 Dec 2026 06:53:04 -0800 [thread overview]
Message-ID: <20261204145305.581638-1-sj@kernel.org> (raw)
In-Reply-To: <20261204144750.581395-1-sj@kernel.org>
On Fri, 04 Dec 2026 06:47:57 -0800 SJ Park <sj@kernel.org> wrote:
> On Fri, 4 Dec 2026 15:36:56 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
>
> > damon_pa_pageout() advances its cursor by PAGE_SIZE or the current folio
> > size. If the physical end of a region is near PHYS_ADDR_MAX, either
> > addition can wrap the cursor to zero and make the action walk almost the
> > entire physical address space.
>
> The v1 of this was describing the resulting user impact quite well. But
> somehow it is dropped in v2. Please add a user impact description. Also,
> walking the almost the entire physical address space is already bad. But I
> think the worst scenario is that this could be even an infinite loop. Am I
> correct? If so, maybe something like below could be added.
>
> """
> Depending on to where the wrap makes the loop start from again, and the folio
> status and sizes in the address range, the walk can be repeated multiple times.
> In the worst case, it could be infinite.
>
> As a result, kdamond pages out unexpectedly many memory and consume system
> resource. Users cannot stop that since kdamond is busy and therefore don't
> respond to DAMON sysfs user inputs.
>
> The near-PHYS_ADDR_MAX end address region would be rare in real. But the
> consequence is quite bad.
> """
>
> >
> > Saturate each advance at the converted region end. Calculate the end in
> > the loop for now so this stable fix does not depend on the separate change
> > that hoists the conversion out of the loop.
>
> Now I think the 'end' calculation should be done out of the loop, if we will
> use 'end' anyway. Read below for more details. So the last sentence could be
> dropped.
>
> >
> > Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
Also, seems this Fixes: is wrong. The issue has started before the commit,
isn't it?
Thanks,
SJ
> > Cc: stable@vger.kernel.org
> > Suggested-by: SJ Park <sj@kernel.org>
> > Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
> > ---
> > mm/damon/paddr.c | 11 ++++++++---
> > 1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> > index d7e01f3fdcdb..a0a310e7bd80 100644
> > --- a/mm/damon/paddr.c
> > +++ b/mm/damon/paddr.c
> > @@ -319,7 +319,8 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
> > unsigned long addr_unit, struct damos *s,
> > unsigned long *sz_filter_passed)
> > {
> > - phys_addr_t addr, applied;
> > + phys_addr_t addr, end, applied;
> > + unsigned long size;
> > LIST_HEAD(folio_list);
> > bool install_young_filter = true;
> > struct damos_filter *filter;
> > @@ -342,11 +343,13 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
> >
> > addr = damon_pa_phys_addr(r->ar.start, addr_unit);
> > while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) {
> > + end = damon_pa_phys_addr(r->ar.end, addr_unit);
> > folio = damon_get_monitor_folio(PHYS_PFN(addr));
> > if (folio && !folio_test_lru(folio))
> > goto put_folio;
> > if (damon_pa_invalid_damos_folio(folio, s)) {
> > - addr += PAGE_SIZE;
> > + size = PAGE_SIZE;
> > + addr = size < end - addr ? addr + size : end;
>
> In the v1 of this, I objected calculating 'end' before the loop because it
> looked unrelated optimization.
>
> Now I understand 'end' is used here, to make the above line shorter and easy to
> read. I agree it is a good decision. In this case, calculatiing 'end' before
> the loop and reusing makes more sense. Let's do that as a part of this patch.
>
> > continue;
> > }
> >
> > @@ -364,7 +367,9 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
> > else
> > list_add(&folio->lru, &folio_list);
> > put_folio:
> > - addr = PFN_PHYS(folio_pfn(folio)) + folio_size(folio);
> > + addr = PFN_PHYS(folio_pfn(folio));
> > + size = folio_size(folio);
> > + addr = size < end - addr ? addr + size : end;
> > folio_put(folio);
> > }
> > if (install_young_filter)
> > --
> > 2.43.0
> >
> >
>
>
> Thanks,
> SJ
>
Thanks,
SJ
next prev parent reply other threads:[~2026-12-04 14:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
2026-12-04 14:47 ` SJ Park
2026-12-04 14:53 ` SJ Park [this message]
2026-12-04 15:36 ` Aveline Noir
2026-12-04 16:20 ` Kyuwon Cho
2026-12-04 16:19 ` Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 2/4] mm/damon/paddr: prevent address wrap in LRU action walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 3/4] mm/damon/paddr: prevent address wrap in migration walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 4/4] mm/damon/paddr: prevent address wrap in stat walks Kyuwon Cho
2026-12-04 6:59 ` [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks sashiko-bot
2026-12-04 15:17 ` SJ Park
2026-12-04 16:22 ` Kyuwon Cho
2026-12-04 17:13 ` SJ Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204145305.581638-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=jm5905938@gmail.com \
--cc=kyuwon.cho@skku.edu \
--cc=linux-mm@kvack.org \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yanquanmin1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox