From patchwork Tue Dec 27 12:27:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13082242 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 7EB37C4332F for ; Tue, 27 Dec 2022 12:11:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E2C18E0009; Tue, 27 Dec 2022 07:11:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42EAB8E0001; Tue, 27 Dec 2022 07:11:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 081A88E0009; Tue, 27 Dec 2022 07:11:40 -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 DF8B98E0006 for ; Tue, 27 Dec 2022 07:11:40 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B68F3AB0A4 for ; Tue, 27 Dec 2022 12:11:40 +0000 (UTC) X-FDA: 80287971960.12.D54193B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 55FF61C0008 for ; Tue, 27 Dec 2022 12:11:37 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672143099; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BKedCFIcZJbnFJGoZRc65JoI0iXStmrLhVHYAPBp4oE=; b=hvPM5DG9Q3D7gAs59w+uFzuLG/YoZgCNWMZenL6vZkLHI0aLBMSgok7PSIHz43Q02c9njK kDHI0jjKl7Ft2/Gx1zyAgYtkgPEx2V73fADSpnJ3UEWup6S2ftPZsZQExoWKJWIyeAS6Cz gtJSVjBqPmA93hYGkLBDtYb3h6UORsE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672143099; a=rsa-sha256; cv=none; b=WirxE2oN614/RaIsanlNogck/8YQmJgiFGonAxis0XxZPIGOSnaBq+Jxa6JpLPAfSsKA5O JOt3SuX/uGmGInO83LArG4zk2/6wpm6XUHTDGNzrB/VmPNjrSuts21EvCIbAZd7uo5wRq6 jsDpYVXGkK4HrRE4n7ZYOpOS+BU4oMY= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NhD0l4NwnzkWs9; Tue, 27 Dec 2022 20:07:03 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 27 Dec 2022 20:11:34 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v2 4/7] mm: damon: paddr: convert damon_pa_*() to use folios Date: Tue, 27 Dec 2022 20:27:11 +0800 Message-ID: <20221227122714.161224-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221227122714.161224-1-wangkefeng.wang@huawei.com> References: <20221227122714.161224-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Stat-Signature: dhndpxepzqaitbmhuncqqnjtc8kgkgrr X-Rspam-User: X-Rspamd-Queue-Id: 55FF61C0008 X-Rspamd-Server: rspam06 X-HE-Tag: 1672143097-506101 X-HE-Meta: U2FsdGVkX1+HyFeyEm/LYUrQFPSbTbQ1a1By5iOb4zIk0k/UTutW6wY34MZHLsIEOhExWVBY8EeESaQj8GLRwytxf7RkSdUVii1dt3SuD7iPgD7Hbok2cVVzUnzwvM8VAdBpHLeDOUoXwmy3j89+rwdOaRuWcyV2BAJZvXst8OIns9z1pJDtAGpPGFV0MdTODwtUfjtFwB9GYUT4x4guu4yeh94A0i20qmz+ZplqhZsIKrDnJHrWepd6aU/y+NYJJ2+NiBf67nua7S7RqDi0crEsW3YA0i5/qEAnlRoXIYbKATx7WizX54lLty5w/c8wXNP9eBJwVS+jlt607fJ4jb+6ZuldcQ5O+EPXyksCzMowy/1y2vVqb5M5iWuO4vrDCT19sfoW1oUIgeqvI0oH+pkhFeV7BbREpWgCu7nefDGDiQvVOHt/wxQVSkV41h/fzyvZ6H/2/x4BJROB0jZUJ2RBQbdH2hoBiuI3iL71rWaI/xMbHZw1pXn4zEGTNQC1HNx28ObjFtKBe7mNrJLRqIyhT8TB1sILsPMXd1oOE5N6wTmAS2N2kU583Y/kce3qdulswoBKw/5Nmfwt/hEtuaRo39MS3dCDyKXWIj9K5hQEeID+DUqjPtfgXXsa5F/J9vkBfuavzrIt2fo8+KEM6VdngRU/lWsO3GhFzbEt7ZtlZwFb3JyMASDWldeq+82Q2qMcW3LijOvaGgdF5ldDkp49mWurqYkpBKMUkRrr0l99tNdJlC0qk2Tm1glHo/QoXSS7G6NvP30fLVC/g4xuGgO8cMF6e34HvKVnEazRw68pBh1pilanYttt4OGyBqWOSINImlpZnYbd1B55cgtmai0FE/FV79js21cn2Zn4M9k1yii8n59Gzqz5n9htnRb3XgNGv/u8NoVBcF9kJqjYcL+OxLuEp9HP+RSmym12WFWBVu2LOTx6JbCqhWyTkMdBssv5BiQoCJJ0BdZm3l0 uSgfIs03 x1KC+quARV6rRebQ= 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: With damon_get_folio(), let's convert all the damon_pa_*() to use folios. Signed-off-by: Kefeng Wang --- mm/damon/paddr.c | 59 +++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 6334c99e5152..728a96c929fc 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -33,17 +33,15 @@ static bool __damon_pa_mkold(struct folio *folio, struct vm_area_struct *vma, static void damon_pa_mkold(unsigned long paddr) { - struct folio *folio; - struct page *page = damon_get_page(PHYS_PFN(paddr)); + struct folio *folio = damon_get_folio(PHYS_PFN(paddr)); struct rmap_walk_control rwc = { .rmap_one = __damon_pa_mkold, .anon_lock = folio_lock_anon_vma_read, }; bool need_lock; - if (!page) + if (!folio) return; - folio = page_folio(page); if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { folio_set_idle(folio); @@ -58,7 +56,6 @@ static void damon_pa_mkold(unsigned long paddr) if (need_lock) folio_unlock(folio); - out: folio_put(folio); } @@ -122,8 +119,7 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma, static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) { - struct folio *folio; - struct page *page = damon_get_page(PHYS_PFN(paddr)); + struct folio *folio = damon_get_folio(PHYS_PFN(paddr)); struct damon_pa_access_chk_result result = { .page_sz = PAGE_SIZE, .accessed = false, @@ -135,9 +131,8 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) }; bool need_lock; - if (!page) + if (!folio) return false; - folio = page_folio(page); if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { if (folio_test_idle(folio)) @@ -203,18 +198,18 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) } static bool __damos_pa_filter_out(struct damos_filter *filter, - struct page *page) + struct folio *folio) { bool matched = false; struct mem_cgroup *memcg; switch (filter->type) { case DAMOS_FILTER_TYPE_ANON: - matched = PageAnon(page); + matched = folio_test_anon(folio); break; case DAMOS_FILTER_TYPE_MEMCG: rcu_read_lock(); - memcg = page_memcg_check(page); + memcg = page_memcg_check(folio_page(folio, 0)); if (!memcg) matched = false; else @@ -231,12 +226,12 @@ static bool __damos_pa_filter_out(struct damos_filter *filter, /* * damos_pa_filter_out - Return true if the page should be filtered out. */ -static bool damos_pa_filter_out(struct damos *scheme, struct page *page) +static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio) { struct damos_filter *filter; damos_for_each_filter(filter, scheme) { - if (__damos_pa_filter_out(filter, page)) + if (__damos_pa_filter_out(filter, folio)) return true; } return false; @@ -245,33 +240,33 @@ static bool damos_pa_filter_out(struct damos *scheme, struct page *page) static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s) { unsigned long addr, applied; - LIST_HEAD(page_list); + LIST_HEAD(folio_list); for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) { - struct page *page = damon_get_page(PHYS_PFN(addr)); + struct folio *folio = damon_get_folio(PHYS_PFN(addr)); - if (!page) + if (!folio) continue; - if (damos_pa_filter_out(s, page)) { - put_page(page); + if (damos_pa_filter_out(s, folio)) { + folio_put(folio); continue; } - ClearPageReferenced(page); - test_and_clear_page_young(page); - if (isolate_lru_page(page)) { - put_page(page); + folio_clear_referenced(folio); + folio_test_clear_young(folio); + if (folio_isolate_lru(folio)) { + folio_put(folio); continue; } - if (PageUnevictable(page)) { - putback_lru_page(page); + if (folio_test_unevictable(folio)) { + folio_putback_lru(folio); } else { - list_add(&page->lru, &page_list); - put_page(page); + list_add(&folio->lru, &folio_list); + folio_put(folio); } } - applied = reclaim_pages(&page_list); + applied = reclaim_pages(&folio_list); cond_resched(); return applied * PAGE_SIZE; } @@ -282,14 +277,12 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( unsigned long addr, applied = 0; for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) { - struct page *page = damon_get_page(PHYS_PFN(addr)); - struct folio *folio; + struct folio *folio = damon_get_folio(PHYS_PFN(addr)); - if (!page) + if (!folio) continue; - folio = page_folio(page); - if (damos_pa_filter_out(s, &folio->page)) { + if (damos_pa_filter_out(s, folio)) { folio_put(folio); continue; }