From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C60E47AF5F; Tue, 14 Jul 2026 13:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037163; cv=none; b=eig9MHfTYsIipRmOND07OlG7zy8LY+EJikI7OeWdueAmqN7WXtEeLbbXQ5EOa7w/nbaf+BJ8V2RQuyolUGI4d0f38lR6rA6Eg+g9F4Sb2OTq2QT7p1jnf6inq3ci3EhzU/t5D5a7znCLbWd9LwBmrbaKCAduDqW64+5iu8IeFUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037163; c=relaxed/simple; bh=5ScejZ7WR20mP7M32rQjyj8bSoc3hvLkckL0qcqy7ww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ao+/C/hIFdwL82R38WuMhLWedhJoNlVBiRG4fIf9WRLP1YXZnB+362Wx22VHtg1kB8snRVuKStfE6XLkyc76u6PFV2PeuKTXW2GvBTL+0yspVpE2yLHkmr4SCBRuj3sj85Md9DTh3Bpx30abWLRgD1AkJM1OmwXuhoTejIx+/yA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TXSHgfay; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TXSHgfay" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4B211F000E9; Tue, 14 Jul 2026 13:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784037162; bh=MTFa+hpzXfcfyF1zP3rvNz2Fhu2Cffg36gE6sioOaYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TXSHgfayZDyKOjxmFxTfQTlWYACYLOF1UShP6zz/S0vV6siNuJJPHalozH+s0r8YB gwGVBU9sm99r4zVvNBWuJM1x8YMeYOjk52ctqyyS/FKv4mZVpB9grooZW1flRLiEvy mZ462KChCsmiktOfOujR+u2hYkPpRwQrtBUN6GnKJ7PnCC6pzIJdQ4ATSo/4G82BVL dhQehNgCxHx7kY4C9tgNQ7ADb73tY2p9BPVlwJWlzJh0yUwccX4uaq4PkveFw5beMy cR0YFSEFjgDehYed2pJ1V7dCiy3CLqHNr/aldqnn1cGafOo/FkG2vJWlG/P1US5xCR bXuLRqUFzMaJw== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/5] mm/damon/paddr: drop last same folio access check reuse optimization Date: Tue, 14 Jul 2026 06:52:32 -0700 Message-ID: <20260714135236.92699-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260714135236.92699-1-sj@kernel.org> References: <20260714135236.92699-1-sj@kernel.org> Precedence: bulk X-Mailing-List: damon@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit It can race when multiple kdamonds are being used. The problem from the race is doubtful, but the gain from the optimization is also doubtful. Simply drop the optimization in favor of code simplicity. The user impact is doubtfully trivial. After all, this kind of interference can happen only by intentional user setup. Even if it happens, it will be rare, and the consequence is degradation of the best-effort monitoring results. No critical consequences like kernel panic or memory corruption happen. The race was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org Fixes: a28397beb55b ("mm/damon: implement primitives for physical address space monitoring") Cc: # 5.16.x Signed-off-by: SJ Park --- mm/damon/paddr.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b85f88a7a38f4..e4f98d67461f5 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -65,7 +65,7 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx) } } -static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz) +static bool damon_pa_young(phys_addr_t paddr) { struct folio *folio = damon_get_folio(PHYS_PFN(paddr)); bool accessed; @@ -74,7 +74,6 @@ static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz) return false; accessed = damon_folio_young(folio); - *folio_sz = folio_size(folio); folio_put(folio); return accessed; } @@ -82,23 +81,12 @@ static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz) static void __damon_pa_check_access(struct damon_region *r, unsigned long addr_unit) { - static phys_addr_t last_addr; - static unsigned long last_folio_sz = PAGE_SIZE; - static bool last_accessed; + bool accessed; phys_addr_t sampling_addr = damon_pa_phys_addr( r->sampling_addr, addr_unit); - /* If the region is in the last checked page, reuse the result */ - if (ALIGN_DOWN(last_addr, last_folio_sz) == - ALIGN_DOWN(sampling_addr, last_folio_sz)) { - damon_update_region_access_rate(r, last_accessed); - return; - } - - last_accessed = damon_pa_young(sampling_addr, &last_folio_sz); - damon_update_region_access_rate(r, last_accessed); - - last_addr = sampling_addr; + accessed = damon_pa_young(sampling_addr); + damon_update_region_access_rate(r, accessed); } static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) -- 2.47.3