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=1796395677; b=j57gFmvBU0kDIcM73NzK8uE+DBD7RE4myb3HlaC2sKC6ItQjVKGFeTtH21cVdtbmg+Ik 8m50LOUjL+a08cVOJMXhRFrke607ilxNGIjOUzRX4tIx5ub8J9nGNj6NAyjqS+/1+jBDU thM6hLUnRRar39Fxve8HYRAX1RAfVaSK4pTieaVtyxL/Zmh9pB8o5jEbP/JpprD+bJmuV 7eCKymy2SB3faNQbKCA0qtsJfeuiUyPXbkvjLVULesM9i2G67xlxJVBDVRq8gKXjvdOL0 xsSlNsVYn1r2uSrtnoz2oOPMFWbULGmJJSuPJdB2iBeepSvOFMJeTsdvr/I5Noek+YA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395677; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=AdsuF3wZMRM8JYh4Cz8lx4t4fCglgyVzAISoDiYWPfU=; b=RdHX4oQXQL+Wa3ZtBGwpPFk1CH1VCDS/JUai83IxjfXy9o3OF8vyCA5Hs11hR53RwW1C Vfu/ssLl7KSBf9B2pkxp0/96UxPca/4c3kRRG+aZ4Vw6gGhAj/GfyHCHT1zaqaXAY1XUP swIU2CT8hlxFoQ9sIJTz5j9HSMwt31WTArJsWoqYAIhTuqGUCxT6mwE9gOJacmMDaBi/v LuFGH5gAfGrjGfw6JEdp5+ESRoZFADKpl5cCmY/3oHc1PPwESiDV5vQWzPz6eCMHwgFPl GnavedQ00ncQUYqL6jKjP3L0NA+Ov3qBuFGz/CLb3J0Bul5Uc6QBAFECD0qYUa+ixwA== 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=k5d9wnWB; 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 9A41C606A32C; Fri, 4 Dec 2026 14:47:57 +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=k5d9wnWB Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF1FE1F000CE; Fri, 4 Dec 2026 14:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796395677; bh=AdsuF3wZMRM8JYh4Cz8lx4t4fCglgyVzAISoDiYWPfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k5d9wnWBvDg6agdDq1t9CF0bL7OOTWjewB8rV5x2Lp1w95V3vKB+z1wUBsvZHweta hDpEtRourffrfAIPB6297eOsYe9oZH6k3pj2t6b3jjzQiITOZJIf3X9E9csc9jNUbt VIhuExfaeJEwSTce1DmGkLJ9jM5qaH3FtUDSa1SEfoYJE+hkrEI715k5abt3dcClY2 wiocU3H8+gqHej3f113IxMJ6xV1+cGhwaooPw+9ozT3R/32oG4vCmE9HzJ6Hkpaa8z ZjhRpeUQeTvZDHo/RIJg85zULa4H5BLQ9jj3xlwNmef0yg5dQv4gEwUGPSTWAsRUYk GL+G+S9mDRqZg== From: SJ Park To: Kyuwon Cho Cc: SJ Park , 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:47:49 -0800 Message-ID: <20261204144750.581395-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <179636379461.1106205.2801729183986757789@skku.edu> 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, 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") > 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