From patchwork Mon Mar 11 20:45:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13589314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E061C5475B for ; Mon, 11 Mar 2024 20:46:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80FEC6B0121; Mon, 11 Mar 2024 16:46:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BF846B0122; Mon, 11 Mar 2024 16:46:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 687146B0123; Mon, 11 Mar 2024 16:46:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 576F16B0121 for ; Mon, 11 Mar 2024 16:46:01 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D42DC80442 for ; Mon, 11 Mar 2024 20:46:00 +0000 (UTC) X-FDA: 81885940080.29.3DCA7CF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 35F1740005 for ; Mon, 11 Mar 2024 20:45:59 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=td2zp50G; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710189959; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zsIMqcXcJhWYwGsWoJ7Jty+YO7EmPMuaCF/Fyz2ErpY=; b=gZN2BtyPC7hyhiH9WvgOsGYJV22tyxukwbctnAebvDaYU0y0KDqpVLF3r3BdRzTE5S1BtC Bn4zCl4sMzxPwJKGRsZUoWHhCzqfhmMbLiN4f50cPLz1rGeuCrsLY9i9wrY2Yea3hYKJx7 IGhvKQCQYfVtF1NfQei8l1Dl9kHqiIs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=td2zp50G; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710189959; a=rsa-sha256; cv=none; b=fQrIMLiFDFJbXhQzpW382lhZaHP4KEbjOR5nE+Rs+E8LLiF/1bN67rtB5+V5GVUTK48JbB mmRCMzu9NRORSEUMICa9XCxy7bYxleBFEY3dtcELb3gC4QVGnjCu+VnVv4JVc2TTB/Rpqn ym2trpbp91bzq0iddu1R4xjYZSotWNM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4C67960F70; Mon, 11 Mar 2024 20:45:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71566C433F1; Mon, 11 Mar 2024 20:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710189958; bh=UuuVmb738blr2pB61tpIDxHO3PUHT5WkafuK2N/sEFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=td2zp50GqM3oHJlnxChlumu1/94uTMfKJnHQqsPeNz16+H1HzcBmhqMqLCxRnMiFT Y6uES8HIJjl+SwTjfzxxHWYm+HL7Z3FRMMt8SbJ9+lErFtA6V6qmidyHFf/O1V3gPa orY1Iuv9SnlsA0OQmdzQMplsz01BPPxSnwAYPYfxwwBz9IRoHNmVTJxQ6dT1g+Bpj/ Mb9LP01sZNLXrNR4tN0kff+1oELPmWRnlNUDDrlBJc+JG4mFHKCS6+OQ6l5d0PfAln GJtW1BE+HA8yuyegskWeYCXue0tYoSL4okBtkLcYd9TO1WiASR7WDg5ifi0C/Yigm1 fEFGgsi50HezQ== From: SeongJae Park To: Cc: honggyu.kim@sk.com, hyeongtak.ji@sk.com, kernel_team@skhynix.com, SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 1/4] mm/damon/paddr: implement damon_folio_young() Date: Mon, 11 Mar 2024 13:45:42 -0700 Message-Id: <20240311204545.47097-2-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240311204545.47097-1-sj@kernel.org> References: <20240311204545.47097-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 35F1740005 X-Stat-Signature: 78tza8orq53eqj6q4jh75baoiiinzjjx X-Rspam-User: X-HE-Tag: 1710189958-839079 X-HE-Meta: U2FsdGVkX1+nXHs70msqFptwLCm/GTu1SDHEZgW+u9vjLhff3p82q9CRaDAb45uqzLdqniBSzwo3d/DTm8Z+cuxZtmTUA4owI90uCf8lv0g4Eke11hcBZzn0kR/2fbGRfrwfglMMbylg2j2oByLWWldw2vURpr2YTLzvDehDuNEPttJ/jDLhYecESTZEn1oPgU+MEmjuqjDxGgFKZ2m+okdVKKFIX5T0kqnOVt2ejxEfEOTPLQn9iSpW0M+hf1nVKJtQ+0CAKjoV8yNoUssA+WkB6HC9FCG2U5cjmrWDqkG+FrbFFVUdtGtiT5OWLLrxmpAz7zhm0J8tVPmalbngQspWvys0fIlQZbtQIMewbDLDfwMXhpSTfdk4qUJ2mQ6mieYXAa8jJZRYbLlIhyUjmPdjNu5SiqrFMds+C6VsetaXXdeOlE2T4gVmLZ6xf8RrzklqJ86Np+SeMu5Xk8zeaNAS9DKM1X+Zc6pmHe2wtkoSQiJUUU850u+J0cn2uuuBLDv3KZ8cpU8X4ZQXLTfHkahGw+04i5cDAnTmil8ww/LBj2l3blYF0kYVWm+St+z1cUe0VFnJdLRJnLMVfpIRrr4SxTFIdE4Q+U7CL+uJ060uqCf0g29SP7pIHp97SC4xXDfvbL47BaO8FqDuFTdKxymL4sdeKTaBk/jWrb3Rcu3wBud7lBWdme2BDKz65exffzyr5DtmJqIOOb1kGCk5R3A7e80g8UeMjoqhEGaMgt573GKJRwWBZ8kwZq/QzaAakehi5SKxRwVCvqe+QNX0xbFZ5+tn9xnOigfzAiGyCNGxvp7re/zMmajOWiqbArPmdN9JquKQn3zhsZ6avxJsyU2zFDWXXK3HCriAXARfl822dJmgVEn2ArH8R7zdqIqDJZlWCVVDBYuHRMKdgsoUlpJC9re2w/Y6FcExQqRIt2pL5ZSoP/6oYEWuB8GEFSVcCQXoNwR64yxrnulLbNn R+oEavCq P7Dbl X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: damon_pa_young() receives physical address, get the folio covering the address, and show if the folio is accessed since the last check. Split the internal logic for checking access to the given folio, for future reuse of the logic from code that already got the folio of the address of the question. Also, change the rmap walker function's name from __damon_pa_young() to damon_folio_young_one(), for consistent naming. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 5e6dc312072c..25c3ba2a9eaf 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -79,8 +79,8 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx) } } -static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma, - unsigned long addr, void *arg) +static bool damon_folio_young_one(struct folio *folio, + struct vm_area_struct *vma, unsigned long addr, void *arg) { bool *accessed = arg; DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); @@ -111,38 +111,44 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma, return *accessed == false; } -static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) +static bool damon_folio_young(struct folio *folio) { - struct folio *folio = damon_get_folio(PHYS_PFN(paddr)); bool accessed = false; struct rmap_walk_control rwc = { .arg = &accessed, - .rmap_one = __damon_pa_young, + .rmap_one = damon_folio_young_one, .anon_lock = folio_lock_anon_vma_read, }; bool need_lock; - if (!folio) - return false; - if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { if (folio_test_idle(folio)) - accessed = false; + return false; else - accessed = true; - goto out; + return true; } need_lock = !folio_test_anon(folio) || folio_test_ksm(folio); if (need_lock && !folio_trylock(folio)) - goto out; + return false; rmap_walk(folio, &rwc); if (need_lock) folio_unlock(folio); -out: + return accessed; +} + +static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) +{ + struct folio *folio = damon_get_folio(PHYS_PFN(paddr)); + bool accessed; + + if (!folio) + return false; + + accessed = damon_folio_young(folio); *folio_sz = folio_size(folio); folio_put(folio); return accessed;