From patchwork Thu Mar 7 03:00:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13584998 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 E2385C5475B for ; Thu, 7 Mar 2024 03:00:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C68436B00E9; Wed, 6 Mar 2024 22:00:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6B56B00E7; Wed, 6 Mar 2024 22:00:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE096B00EA; Wed, 6 Mar 2024 22:00:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 609AB6B00E9 for ; Wed, 6 Mar 2024 22:00:26 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D509B1A1067 for ; Thu, 7 Mar 2024 03:00:25 +0000 (UTC) X-FDA: 81868739610.29.A3712F5 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id EE59E80013 for ; Thu, 7 Mar 2024 03:00:23 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SEsAH8mQ; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709780424; a=rsa-sha256; cv=none; b=laXg3D3uY/Qv5jd64JBEYYxLBah/aGJZrbgq+9sw4ZQcUFUbVWpAbQYIArg+xoK8LE1yD7 qk5ed3F2wdOAvugoi7A9jufUaBXsu19Vhne/BABfeM2f6NEoyRhZtNqPQ6+mIM9tvsQjoD L55Xa2AbztCO/e90sdkII6qCvgFyuRU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SEsAH8mQ; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709780424; 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=whkGAvYGCtdVg8/S6GPler0vrPFgCGQGPrgNgIhTYuo=; b=fnfeALJEISmlt2f9j/8z4qYrKOG7iXf+CRJipm2FKLBg19WdLx/t9qDop4KXMTJmd0MLWq cJr4d8vC9cyWBIQEfOfVYyczfJpn/4mJnOXJcddaU0oAZ76SKoM3JHc+uGGhn8YFCweU6G j+6sZ0DpIJXAK+Iu2gMEKmCajzaIUP8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 12251CE236C; Thu, 7 Mar 2024 03:00:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97DD0C43399; Thu, 7 Mar 2024 03:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709780420; bh=0eBYRMuRF3ohUK1LpjNQClNe+yHwQ6lEwKTScu0clBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SEsAH8mQ0+MJ9898A1IG2SQIvaIy0pUH8KdiOgj6Z61nklkkDbv+he/qFjFiJ0lI/ OrhEf2N80oOQpHKx/HJLFeyiiy38u5gHHpIhVWyGlKVUjrPVamcW3hYTrv/kXdES1a zs1s9szWp0LKHT1qi9u4/Ew0lSvG5ixmO1AAw2yHctf0QyEv8poK6Sp3rHyvGhN4mz lLKFkrBvCu3F0hhxuSvHt5/OGxd8MfRmOmV7oo1af7NugjdAZi3l9liSAfR/Vvs2kY ekTXh7f9xZMv5Z30FdHKya4JPNfZ6fcptOoyKT8ua7rmkesYAcdM5r7I4pS8EIKsdc 9KFnL4DWWQ4xQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , honggyu.kim@sk.com, hyeongtak.ji@sk.com, kernel_team@skhynix.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] mm/damon/paddr: implement damon_folio_young() Date: Wed, 6 Mar 2024 19:00:12 -0800 Message-Id: <20240307030013.47041-3-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307030013.47041-1-sj@kernel.org> References: <20240307030013.47041-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: EE59E80013 X-Stat-Signature: qzh6gsgjoi8dtzqyphij7h3ua4qbhd3x X-Rspam-User: X-HE-Tag: 1709780423-585353 X-HE-Meta: U2FsdGVkX19nMXanVeZzgpus8Ny1fIVyVhv4hrjciuVVbN4Ztit+ABlLWbtR7O4pag3QnAZeXZ3mrINNBZApUs74F7cbnKlp34arg/VfdDfdOmxjKcDGapBkTiys6nRmsImaW3olcSIlVUipu42TXWsivy42TE/9wLl6yzrqajYHgzvKNwZKof5uqWJjXIY9sCf0MHHwLVXrE9JZOkqTQbziJQgI3B6XH6t5wQceTgG8u3GLr8aG3iylQztaUQhRAsqqxEbPi0u95ZkXNTsh2qZQgy9rS6kkAQmh2ZEvvmprM7s7CSqwfq8rDsAy04O6nYKTpzXJTEbiHrEqVzLvdFGMEgiCYEeuMXuXT7hqGw9aU2StsBxFZFhgJ0YyH//ovT/ko/eUJA/Z+rGkq7zqLliuuaPZHUuC0oexx3IxIziioliQ+XOKdy8zeU3VfDW1ZlYy9ytgHBcM+tnq0Pd1pMed++E2ievzwZZ3JiozDBG2e1FBtHYIQ//7PDLCtIPTcWqFt+1IsjuzsC3WbEm3l+Y+yamRBKmCdL+z41FUB81eblHwx8FiuuUpqUWVQXDSHnYs6Q8vX9SIzxE09+BcWUoRFDaERMcJgAZdDE+LtCs+T9PwVS4Rrza80u0d3AO0EAdu48mGNv7tLzvbllUbsYKIxhEA7u7KTEyOVDs4mYH9Y/2CYNxAFdtRIamP+Zyh7VPwMwLugzl4mv7p10icpqce0SIP6wgdTQrutpRZsqa5hT3zvgWlqsMwH74uuKn0WbbTaMGjpwAMzVjNriDVzZ9F1gBqyOxWvw2tKX1AohS1ojaka9ZWWGwIszLqzMeAM00qi3Hfz469JKV5wO1jB1RTzHvQM7Hsje07DNCnlOhLWLGK3V3g0L9rbvkQtCpJ0CA1cc3FNlIcW0a44yMAioje/EcUj5C9WeSypwKq0h1LIcpcq2XeoDrGA5EEK6OQEdm+6vLMkP8UHdEJJ+S 4nkgJ9+w qE9MV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000033, 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 return if the folio is accessed since the last check. Split the internal logic for checking access to given folio, for future reuse of the logic from code that already got the folio of the address of the question. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 5e6dc312072c..deee0fdf2e5b 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -111,9 +111,8 @@ 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, @@ -122,27 +121,34 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) }; 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;