From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796395992; b=Bz+vOYrhFDl/jkXhZighaTSC+sYKYUxmIjUr6xyqfe+7bUI+JjtQR1x3ZTlJl1qZej41 fzXTvZ89wkMi43ezHZKmnoonmqcYhsARYNqfRy1yUuoUtI2c7S66/hWPNfiKxBJOKy+ET mIQtefKjfhkXpgRlM+IDfbxKpX9t64CFWzY6Oa7Gv7wigCefKIvajMsszH94suyklD15W tsNz/5+7S7HXfNrRhxmQrSyUqJgDd+SbfqHP4aIpF00dLZHdI+/c5H9PqdnQD6WAjIXSo DONZosbq13/GbuL8d6micmJ6SMAYpqt3bf+wU0qTpiAU4VyvQHn2l2IMOjbUWFFg8Jg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395992; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=A1vIBXHyHyyQECa+xDPESpga+2ag9Ei1ghC2QtpCxuI=; b=BWZAPei5zhGPo8jM9g+7CiRaM05QGH+0AHthtdhrvTGPx3mgqNOYN5xJXLPD183I4u7o jHUjrsX5OOGKgauYZWGPGYgbRs1JJeAa6ZwNwlo74CNI16gyigVjxsbRszmJHTRnFOZKs t4ypgnSCd+WeD+CEiKCJ4SaBXVOfYfRYAZtriA+u0wW1NXkvKpC/D9+T6Ki+sLNGw82Gn tMANl+NfkMnsSDdxYUUV4qarA+r5oci81NCV/kLy6bt/M+Tn6z0NrPWLLkDzTRFswvkXd KoVA+pD9ooSnjtYKdeoK88Vlwjm2NmEZzLcClcXg+qvqBHqEjAC9gOnQxP0QVqbnnJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YiVUBkoK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F92D606A33B; Fri, 4 Dec 2026 14:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YiVUBkoK Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA2DC1F00A1E; Fri, 4 Dec 2026 14:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796395992; bh=A1vIBXHyHyyQECa+xDPESpga+2ag9Ei1ghC2QtpCxuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YiVUBkoKMR/Ij8dio7/z0aZVNlphhGWl43pHyZIcC6PQxA3aaMS7GvGF9qEUHxOzW TlK3oBN8n1xK4gBY5VBuCcCo9NYkzynEEStKqEvCOSc2iQP4U6q+9dg5Syzy4HwwDb uHPSkMcGDGjB06qo/3kmm1apJ8qDI5XNyRVSIMkAVjeZWyRzLPA5EYrFytj5G7vn1w s8F1G/NcFMSYl9xRsXCw9fzDGBdsstUD4gJZhkyKlFELdY6cXBEBkXVUs8oQOCJMZl WpXywDmlOqVVrD4xTHB8tn6dC2dt8E/foQ2Loy2tgoQVyEyKjsLc6WnjJU2uHJ06PS KJeMZrfCa893A== From: SJ Park To: SJ Park Cc: Kyuwon Cho , Andrew Morton , Quanmin Yan , Aveline Noir , 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 Message-ID: <20261204145305.581638-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261204144750.581395-1-sj@kernel.org> References: X-Mailing-List: damon@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Fri, 04 Dec 2026 06:47:57 -0800 SJ Park wrote: > On Fri, 4 Dec 2026 15:36:56 +0900 Kyuwon Cho 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 > > Signed-off-by: Kyuwon Cho > > --- > > 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