From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4582C04FDE for ; Tue, 13 Dec 2022 09:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235150AbiLMJOB (ORCPT ); Tue, 13 Dec 2022 04:14:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232921AbiLMJM6 (ORCPT ); Tue, 13 Dec 2022 04:12:58 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A53D1006C for ; Tue, 13 Dec 2022 01:11:20 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NWXlL3417z15NBs; Tue, 13 Dec 2022 17:10:22 +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, 13 Dec 2022 17:11:18 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio() Date: Tue, 13 Dec 2022 17:27:28 +0800 Message-ID: <20221213092735.187924-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce a wrapper function pfn_to_online_folio(), which calls pfn_to_online_page() and returns the folio of the page found, or null if no page. Signed-off-by: Kefeng Wang --- include/linux/memory_hotplug.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 9fcbf5706595..e841e4fb52a7 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -265,6 +265,13 @@ static inline void pgdat_kswapd_unlock(pg_data_t *pgda= t) {} static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {} #endif /* ! CONFIG_MEMORY_HOTPLUG */ =20 +static inline struct folio *pfn_to_online_folio(unsigned long pfn) +{ + struct page *page =3D pfn_to_online_page(pfn); + + return page ? page_folio(page) : NULL; +} + /* * Keep this declaration outside CONFIG_MEMORY_HOTPLUG as some * platforms might override and use arch_get_mappable_range() --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30B63C4708D for ; Tue, 13 Dec 2022 09:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235129AbiLMJOH (ORCPT ); Tue, 13 Dec 2022 04:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234318AbiLMJM6 (ORCPT ); Tue, 13 Dec 2022 04:12:58 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD10101E8 for ; Tue, 13 Dec 2022 01:11:21 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NWXgW3V50zqT0X; Tue, 13 Dec 2022 17: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, 13 Dec 2022 17:11:19 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 2/8] mm: page_idle: Convert page idle to use folios Date: Tue, 13 Dec 2022 17:27:29 +0800 Message-ID: <20221213092735.187924-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This change and rename all page related function to use folio, which save many compound_head() calls and kernel text. Signed-off-by: Kefeng Wang --- mm/page_idle.c | 91 ++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/mm/page_idle.c b/mm/page_idle.c index bc08332a609c..38641f94cf49 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -19,34 +19,33 @@ #define BITMAP_CHUNK_BITS (BITMAP_CHUNK_SIZE * BITS_PER_BYTE) =20 /* - * Idle page tracking only considers user memory pages, for other types of - * pages the idle flag is always unset and an attempt to set it is silently + * Idle folio tracking only considers user memory folios, for other types = of + * folios the idle flag is always unset and an attempt to set it is silent= ly * ignored. * - * We treat a page as a user memory page if it is on an LRU list, because = it is - * always safe to pass such a page to rmap_walk(), which is essential for = idle - * page tracking. With such an indicator of user pages we can skip isolated - * pages, but since there are not usually many of them, it will hardly aff= ect + * We treat a folio as a user memory folio if it is on an LRU list, becaus= e it is + * always safe to pass such a folio to rmap_walk(), which is essential for= idle + * folio tracking. With such an indicator of user folios we can skip isola= ted + * folios, but since there are not usually many of them, it will hardly af= fect * the overall result. * - * This function tries to get a user memory page by pfn as described above. + * This function tries to get a user memory folio by pfn as described abov= e. */ -static struct page *page_idle_get_page(unsigned long pfn) +static struct folio *folio_idle_get_folio(unsigned long pfn) { - struct page *page =3D pfn_to_online_page(pfn); + struct folio *folio =3D pfn_to_online_folio(pfn); =20 - if (!page || !PageLRU(page) || - !get_page_unless_zero(page)) + if (!folio || !folio_test_lru(folio) || !folio_try_get(folio)) return NULL; =20 - if (unlikely(!PageLRU(page))) { - put_page(page); - page =3D NULL; + if (unlikely(!folio_test_lru(folio))) { + folio_put(folio); + folio =3D NULL; } - return page; + return folio; } =20 -static bool page_idle_clear_pte_refs_one(struct folio *folio, +static bool folio_idle_clear_pte_refs_one(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, void *arg) { @@ -74,8 +73,8 @@ static bool page_idle_clear_pte_refs_one(struct folio *fo= lio, if (referenced) { folio_clear_idle(folio); /* - * We cleared the referenced bit in a mapping to this page. To - * avoid interference with page reclaim, mark it young so that + * We cleared the referenced bit in a mapping to this folio. To + * avoid interference with folio reclaim, mark it young so that * folio_referenced() will return > 0. */ folio_set_young(folio); @@ -83,16 +82,14 @@ static bool page_idle_clear_pte_refs_one(struct folio *= folio, return true; } =20 -static void page_idle_clear_pte_refs(struct page *page) +static void folio_idle_clear_pte_refs(struct folio *folio) { - struct folio *folio =3D page_folio(page); - /* * Since rwc.try_lock is unused, rwc is effectively immutable, so we * can make it static to save some cycles and stack. */ static struct rmap_walk_control rwc =3D { - .rmap_one =3D page_idle_clear_pte_refs_one, + .rmap_one =3D folio_idle_clear_pte_refs_one, .anon_lock =3D folio_lock_anon_vma_read, }; bool need_lock; @@ -110,12 +107,12 @@ static void page_idle_clear_pte_refs(struct page *pag= e) folio_unlock(folio); } =20 -static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *ko= bj, +static ssize_t folio_idle_bitmap_read(struct file *file, struct kobject *k= obj, struct bin_attribute *attr, char *buf, loff_t pos, size_t count) { u64 *out =3D (u64 *)buf; - struct page *page; + struct folio *folio; unsigned long pfn, end_pfn; int bit; =20 @@ -134,19 +131,19 @@ static ssize_t page_idle_bitmap_read(struct file *fil= e, struct kobject *kobj, bit =3D pfn % BITMAP_CHUNK_BITS; if (!bit) *out =3D 0ULL; - page =3D page_idle_get_page(pfn); - if (page) { - if (page_is_idle(page)) { + folio =3D folio_idle_get_folio(pfn); + if (folio) { + if (folio_test_idle(folio)) { /* - * The page might have been referenced via a + * The folio might have been referenced via a * pte, in which case it is not idle. Clear * refs and recheck. */ - page_idle_clear_pte_refs(page); - if (page_is_idle(page)) + folio_idle_clear_pte_refs(folio); + if (folio_test_idle(folio)) *out |=3D 1ULL << bit; } - put_page(page); + folio_put(folio); } if (bit =3D=3D BITMAP_CHUNK_BITS - 1) out++; @@ -155,12 +152,12 @@ static ssize_t page_idle_bitmap_read(struct file *fil= e, struct kobject *kobj, return (char *)out - buf; } =20 -static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *k= obj, +static ssize_t folio_idle_bitmap_write(struct file *file, struct kobject *= kobj, struct bin_attribute *attr, char *buf, loff_t pos, size_t count) { const u64 *in =3D (u64 *)buf; - struct page *page; + struct folio *folio; unsigned long pfn, end_pfn; int bit; =20 @@ -178,11 +175,11 @@ static ssize_t page_idle_bitmap_write(struct file *fi= le, struct kobject *kobj, for (; pfn < end_pfn; pfn++) { bit =3D pfn % BITMAP_CHUNK_BITS; if ((*in >> bit) & 1) { - page =3D page_idle_get_page(pfn); - if (page) { - page_idle_clear_pte_refs(page); - set_page_idle(page); - put_page(page); + folio =3D folio_idle_get_folio(pfn); + if (folio) { + folio_idle_clear_pte_refs(folio); + folio_set_idle(folio); + folio_put(folio); } } if (bit =3D=3D BITMAP_CHUNK_BITS - 1) @@ -192,29 +189,29 @@ static ssize_t page_idle_bitmap_write(struct file *fi= le, struct kobject *kobj, return (char *)in - buf; } =20 -static struct bin_attribute page_idle_bitmap_attr =3D +static struct bin_attribute folio_idle_bitmap_attr =3D __BIN_ATTR(bitmap, 0600, - page_idle_bitmap_read, page_idle_bitmap_write, 0); + folio_idle_bitmap_read, folio_idle_bitmap_write, 0); =20 -static struct bin_attribute *page_idle_bin_attrs[] =3D { - &page_idle_bitmap_attr, +static struct bin_attribute *folio_idle_bin_attrs[] =3D { + &folio_idle_bitmap_attr, NULL, }; =20 -static const struct attribute_group page_idle_attr_group =3D { - .bin_attrs =3D page_idle_bin_attrs, +static const struct attribute_group folio_idle_attr_group =3D { + .bin_attrs =3D folio_idle_bin_attrs, .name =3D "page_idle", }; =20 -static int __init page_idle_init(void) +static int __init folio_idle_init(void) { int err; =20 - err =3D sysfs_create_group(mm_kobj, &page_idle_attr_group); + err =3D sysfs_create_group(mm_kobj, &folio_idle_attr_group); if (err) { pr_err("page_idle: register sysfs failed\n"); return err; } return 0; } -subsys_initcall(page_idle_init); +subsys_initcall(folio_idle_init); --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4FC3C10F1B for ; Tue, 13 Dec 2022 09:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235132AbiLMJOQ (ORCPT ); Tue, 13 Dec 2022 04:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234485AbiLMJM6 (ORCPT ); Tue, 13 Dec 2022 04:12:58 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35C6140E3 for ; Tue, 13 Dec 2022 01:11:21 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NWXlL52MTzlVjH; Tue, 13 Dec 2022 17:10:22 +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, 13 Dec 2022 17:11:19 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 3/8] mm: huge_memory: convert split_huge_pages_all() to use folios Date: Tue, 13 Dec 2022 17:27:30 +0800 Message-ID: <20221213092735.187924-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Straightforwardly convert split_huge_pages_all() to use folio function. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index abe6cfd92ffa..02092dd10aa4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2933,7 +2933,7 @@ static struct shrinker deferred_split_shrinker =3D { static void split_huge_pages_all(void) { struct zone *zone; - struct page *page; + struct folio *folio; unsigned long pfn, max_zone_pfn; unsigned long total =3D 0, split =3D 0; =20 @@ -2945,25 +2945,27 @@ static void split_huge_pages_all(void) for (pfn =3D zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) { int nr_pages; =20 - page =3D pfn_to_online_page(pfn); - if (!page || !get_page_unless_zero(page)) + folio =3D pfn_to_online_folio(pfn); + if (!folio || !folio_try_get(folio)) continue; =20 - if (zone !=3D page_zone(page)) + if (zone !=3D folio_zone(folio)) goto next; =20 - if (!PageHead(page) || PageHuge(page) || !PageLRU(page)) + if (!folio_test_large(folio) + || folio_test_hugetlb(folio) + || !folio_test_lru(folio)) goto next; =20 total++; - lock_page(page); - nr_pages =3D thp_nr_pages(page); - if (!split_huge_page(page)) + folio_lock(folio); + nr_pages =3D folio_nr_pages(folio); + if (!split_folio(folio)) split++; pfn +=3D nr_pages - 1; - unlock_page(page); + folio_unlock(folio); next: - put_page(page); + folio_put(folio); cond_resched(); } } --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC82AC4332F for ; Tue, 13 Dec 2022 09:14:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235154AbiLMJOE (ORCPT ); Tue, 13 Dec 2022 04:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbiLMJM6 (ORCPT ); Tue, 13 Dec 2022 04:12:58 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5716615836 for ; Tue, 13 Dec 2022 01:11:22 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NWXgX3slFzqSsf; Tue, 13 Dec 2022 17:07:04 +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, 13 Dec 2022 17:11:20 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 4/8] mm: damon: add temporary damon_get_folio() Date: Tue, 13 Dec 2022 17:27:31 +0800 Message-ID: <20221213092735.187924-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce a temporary wrapper function damon_get_folio(), which help us to convert damon related function to use folios, and it will be droped once the conversion is completed. Signed-off-by: Kefeng Wang --- mm/damon/ops-common.c | 18 +++++++++--------- mm/damon/ops-common.h | 8 +++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 75409601f934..40b79b022129 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -13,24 +13,24 @@ #include "ops-common.h" =20 /* - * Get an online page for a pfn if it's in the LRU list. Otherwise, retur= ns + * Get an online folio for a pfn if it's in the LRU list. Otherwise, retu= rns * NULL. * - * The body of this function is stolen from the 'page_idle_get_page()'. We + * The body of this function is stolen from the 'folio_idle_get_folio()'. = We * steal rather than reuse it because the code is quite simple. */ -struct page *damon_get_page(unsigned long pfn) +struct folio *damon_get_folio(unsigned long pfn) { - struct page *page =3D pfn_to_online_page(pfn); + struct folio *folio =3D pfn_to_online_folio(pfn); =20 - if (!page || !PageLRU(page) || !get_page_unless_zero(page)) + if (!folio || !folio_test_lru(folio) || !folio_try_get(folio)) return NULL; =20 - if (unlikely(!PageLRU(page))) { - put_page(page); - page =3D NULL; + if (unlikely(!folio_test_lru(folio))) { + folio_put(folio); + folio =3D NULL; } - return page; + return folio; } =20 void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr) diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index 8d82d3722204..4ee607813981 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -7,7 +7,13 @@ =20 #include =20 -struct page *damon_get_page(unsigned long pfn); +struct folio *damon_get_folio(unsigned long pfn); +static inline struct page *damon_get_page(unsigned long pfn) +{ + struct folio *folio =3D damon_get_folio(pfn); + + return &folio->page; +} =20 void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr= ); void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr= ); --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E066C04FDE for ; Tue, 13 Dec 2022 09:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235050AbiLMJO2 (ORCPT ); Tue, 13 Dec 2022 04:14:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235121AbiLMJM6 (ORCPT ); Tue, 13 Dec 2022 04:12:58 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E05F115A35 for ; Tue, 13 Dec 2022 01:11:22 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NWXlR60YRzJqT4; Tue, 13 Dec 2022 17:10:27 +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, 13 Dec 2022 17:11:20 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 5/8] mm: damon: convert damon_ptep/pmdp_mkold() to use folios Date: Tue, 13 Dec 2022 17:27:32 +0800 Message-ID: <20221213092735.187924-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With damon_get_folio(), let's convert damon_ptep_mkold() and damon_pmdp_mkold() to use folios. Signed-off-by: Kefeng Wang --- mm/damon/ops-common.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 40b79b022129..40ea39fe204d 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -36,9 +36,9 @@ struct folio *damon_get_folio(unsigned long pfn) void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr) { bool referenced =3D false; - struct page *page =3D damon_get_page(pte_pfn(*pte)); + struct folio *folio =3D damon_get_folio(pte_pfn(*pte)); =20 - if (!page) + if (!folio) return; =20 if (pte_young(*pte)) { @@ -52,19 +52,19 @@ void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm,= unsigned long addr) #endif /* CONFIG_MMU_NOTIFIER */ =20 if (referenced) - set_page_young(page); + folio_set_young(folio); =20 - set_page_idle(page); - put_page(page); + folio_set_idle(folio); + folio_put(folio); } =20 void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE bool referenced =3D false; - struct page *page =3D damon_get_page(pmd_pfn(*pmd)); + struct folio *folio =3D damon_get_folio(pmd_pfn(*pmd)); =20 - if (!page) + if (!folio) return; =20 if (pmd_young(*pmd)) { @@ -78,10 +78,10 @@ void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm,= unsigned long addr) #endif /* CONFIG_MMU_NOTIFIER */ =20 if (referenced) - set_page_young(page); + folio_set_young(folio); =20 - set_page_idle(page); - put_page(page); + folio_set_idle(folio); + folio_put(folio); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ } =20 --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24012C4332F for ; Tue, 13 Dec 2022 09:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234777AbiLMJOW (ORCPT ); Tue, 13 Dec 2022 04:14:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233843AbiLMJM7 (ORCPT ); Tue, 13 Dec 2022 04:12:59 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72AC215FF0 for ; Tue, 13 Dec 2022 01:11:23 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NWXlL3283zRptt; Tue, 13 Dec 2022 17:10:22 +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, 13 Dec 2022 17:11:21 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 6/8] mm: damon: paddr: convert damon_pa_*() to use folios Date: Tue, 13 Dec 2022 17:27:33 +0800 Message-ID: <20221213092735.187924-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With damon_get_folio(), let's convert damon_ptep_mkold() and damon_pmdp_mkold() to use folios. Signed-off-by: Kefeng Wang --- mm/damon/paddr.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 6b36de1396a4..95d4686611a5 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -33,17 +33,15 @@ static bool __damon_pa_mkold(struct folio *folio, struc= t vm_area_struct *vma, =20 static void damon_pa_mkold(unsigned long paddr) { - struct folio *folio; - struct page *page =3D damon_get_page(PHYS_PFN(paddr)); + struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); struct rmap_walk_control rwc =3D { .rmap_one =3D __damon_pa_mkold, .anon_lock =3D folio_lock_anon_vma_read, }; bool need_lock; =20 - if (!page) + if (!folio) return; - folio =3D page_folio(page); =20 if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { folio_set_idle(folio); @@ -93,7 +91,7 @@ static bool __damon_pa_young(struct folio *folio, struct = vm_area_struct *vma, DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); =20 result->accessed =3D false; - result->page_sz =3D PAGE_SIZE; + result->page_sz =3D PAGE_SIZE * folio_nr_pages(folio); while (page_vma_mapped_walk(&pvmw)) { addr =3D pvmw.address; if (pvmw.pte) { @@ -122,8 +120,7 @@ static bool __damon_pa_young(struct folio *folio, struc= t vm_area_struct *vma, =20 static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) { - struct folio *folio; - struct page *page =3D damon_get_page(PHYS_PFN(paddr)); + struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); struct damon_pa_access_chk_result result =3D { .page_sz =3D PAGE_SIZE, .accessed =3D false, @@ -135,9 +132,8 @@ static bool damon_pa_young(unsigned long paddr, unsigne= d long *page_sz) }; bool need_lock; =20 - if (!page) + if (!folio) return false; - folio =3D page_folio(page); =20 if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { if (folio_test_idle(folio)) @@ -205,28 +201,28 @@ static unsigned int damon_pa_check_accesses(struct da= mon_ctx *ctx) static unsigned long damon_pa_pageout(struct damon_region *r) { unsigned long addr, applied; - LIST_HEAD(page_list); + LIST_HEAD(folio_list); =20 for (addr =3D r->ar.start; addr < r->ar.end; addr +=3D PAGE_SIZE) { - struct page *page =3D damon_get_page(PHYS_PFN(addr)); + struct folio *folio =3D damon_get_folio(PHYS_PFN(addr)); =20 - if (!page) + if (!folio) continue; =20 - 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 =3D reclaim_pages(&page_list); + applied =3D reclaim_pages(&folio_list); cond_resched(); return applied * PAGE_SIZE; } @@ -237,12 +233,10 @@ static inline unsigned long damon_pa_mark_accessed_or= _deactivate( unsigned long addr, applied =3D 0; =20 for (addr =3D r->ar.start; addr < r->ar.end; addr +=3D PAGE_SIZE) { - struct page *page =3D damon_get_page(PHYS_PFN(addr)); - struct folio *folio; + struct folio *folio =3D damon_get_folio(PHYS_PFN(addr)); =20 - if (!page) + if (!folio) continue; - folio =3D page_folio(page); =20 if (mark_accessed) folio_mark_accessed(folio); --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BC6EC4332F for ; Tue, 13 Dec 2022 09:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231818AbiLMJOb (ORCPT ); Tue, 13 Dec 2022 04:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235021AbiLMJNB (ORCPT ); Tue, 13 Dec 2022 04:13:01 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 014D3164B3 for ; Tue, 13 Dec 2022 01:11:24 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NWXlP4CWPz15NQL; Tue, 13 Dec 2022 17:10:25 +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, 13 Dec 2022 17:11:21 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 7/8] mm: damon: vaddr: convert damon_young_pmd_entry() to use folio Date: Tue, 13 Dec 2022 17:27:34 +0800 Message-ID: <20221213092735.187924-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With damon_get_folio(), let's convert damon_young_pmd_entry() to use folios. Signed-off-by: Kefeng Wang --- mm/damon/vaddr.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 15f03df66db6..2fab7241aa04 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -431,7 +431,7 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned l= ong addr, { pte_t *pte; spinlock_t *ptl; - struct page *page; + struct folio *folio; struct damon_young_walk_private *priv =3D walk->private; =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -446,16 +446,16 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned= long addr, spin_unlock(ptl); goto regular_page; } - page =3D damon_get_page(pmd_pfn(*pmd)); - if (!page) + folio =3D damon_get_folio(pmd_pfn(*pmd)); + if (!folio) goto huge_out; - if (pmd_young(*pmd) || !page_is_idle(page) || + if (pmd_young(*pmd) || !folio_test_idle(folio) || mmu_notifier_test_young(walk->mm, addr)) { *priv->page_sz =3D HPAGE_PMD_SIZE; priv->young =3D true; } - put_page(page); + folio_put(folio); huge_out: spin_unlock(ptl); return 0; @@ -469,15 +469,15 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned= long addr, pte =3D pte_offset_map_lock(walk->mm, pmd, addr, &ptl); if (!pte_present(*pte)) goto out; - page =3D damon_get_page(pte_pfn(*pte)); - if (!page) + folio =3D damon_get_folio(pte_pfn(*pte)); + if (!folio) goto out; - if (pte_young(*pte) || !page_is_idle(page) || + if (pte_young(*pte) || !folio_test_idle(folio) || mmu_notifier_test_young(walk->mm, addr)) { - *priv->page_sz =3D PAGE_SIZE; + *priv->page_sz =3D PAGE_SIZE * folio_nr_pages(folio); priv->young =3D true; } - put_page(page); + folio_put(folio); out: pte_unmap_unlock(pte, ptl); return 0; --=20 2.35.3 From nobody Thu Sep 18 01:13:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD0A9C4708D for ; Tue, 13 Dec 2022 09:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234643AbiLMJOf (ORCPT ); Tue, 13 Dec 2022 04:14:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235125AbiLMJNC (ORCPT ); Tue, 13 Dec 2022 04:13:02 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A509164B7 for ; Tue, 13 Dec 2022 01:11:24 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NWXlM2s0HzRpws; Tue, 13 Dec 2022 17:10:23 +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, 13 Dec 2022 17:11:22 +0800 From: Kefeng Wang To: Andrew Morton , David Hildenbrand , Oscar Salvador , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next 8/8] mm: damon: remove unneed damon_get_page() Date: Tue, 13 Dec 2022 17:27:35 +0800 Message-ID: <20221213092735.187924-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213092735.187924-1-wangkefeng.wang@huawei.com> References: <20221213092735.187924-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After all damon_get_page() callers are converted to damon_get_folio(), remove unneed wrapper damon_get_page(). Signed-off-by: Kefeng Wang --- mm/damon/ops-common.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index 4ee607813981..35a2e42a27da 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -8,13 +8,6 @@ #include =20 struct folio *damon_get_folio(unsigned long pfn); -static inline struct page *damon_get_page(unsigned long pfn) -{ - struct folio *folio =3D damon_get_folio(pfn); - - return &folio->page; -} - void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr= ); void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr= ); =20 --=20 2.35.3