All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux.dev,
	linux-fsdevel@vger.kernel.org,
	"David Hildenbrand" <david@redhat.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Jerrin Shaji George" <jerrin.shaji-george@broadcom.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Jan Kara" <jack@suse.cz>, "Zi Yan" <ziy@nvidia.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Joshua Hahn" <joshua.hahnjy@gmail.com>,
	"Rakie Kim" <rakie.kim@sk.com>,
	"Byungchul Park" <byungchul@sk.com>,
	"Gregory Price" <gourry@gourry.net>,
	"Ying Huang" <ying.huang@linux.alibaba.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Minchan Kim" <minchan@kernel.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Brendan Jackman" <jackmanb@google.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Peter Xu" <peterx@redhat.com>, "Xu Xin" <xu.xin16@zte.com.cn>,
	"Chengming Zhou" <chengming.zhou@linux.dev>,
	"Miaohe Lin" <linmiaohe@huawei.com>,
	"Naoya Horiguchi" <nao.horiguchi@gmail.com>,
	"Oscar Salvador" <osalvador@suse.de>,
	"Rik van Riel" <riel@surriel.com>,
	"Harry Yoo" <harry.yoo@oracle.com>,
	"Qi Zheng" <zhengqi.arch@bytedance.com>,
	"Shakeel Butt" <shakeel.butt@linux.dev>
Subject: [PATCH RFC 18/29] mm: remove __folio_test_movable()
Date: Wed, 18 Jun 2025 19:40:01 +0200	[thread overview]
Message-ID: <20250618174014.1168640-19-david@redhat.com> (raw)
In-Reply-To: <20250618174014.1168640-1-david@redhat.com>

Convert to page_has_movable_ops(). While at it, cleanup relevant code
a bit.

The data_race() in migrate_folio_unmap() is questionable: we already
hold a page reference, and concurrent modifications can no longer
happen (iow: __ClearPageMovable() no longer exists). Drop it for now,
we'll rework page_has_movable_ops() soon either way to no longer
rely on page->mapping.

Wherever we cast from folio to page now is a clear sign that this
code has to be decoupled.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/linux/page-flags.h |  6 ------
 mm/migrate.c               | 43 ++++++++++++--------------------------
 mm/vmscan.c                |  6 ++++--
 3 files changed, 17 insertions(+), 38 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index c67163b73c5ec..4c27ebb689e3c 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -744,12 +744,6 @@ static __always_inline bool PageAnon(const struct page *page)
 	return folio_test_anon(page_folio(page));
 }
 
-static __always_inline bool __folio_test_movable(const struct folio *folio)
-{
-	return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) ==
-			PAGE_MAPPING_MOVABLE;
-}
-
 static __always_inline bool page_has_movable_ops(const struct page *page)
 {
 	return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
diff --git a/mm/migrate.c b/mm/migrate.c
index 5f97369eac2f9..37e722fbfee70 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -219,12 +219,7 @@ void putback_movable_pages(struct list_head *l)
 			continue;
 		}
 		list_del(&folio->lru);
-		/*
-		 * We isolated non-lru movable folio so here we can use
-		 * __folio_test_movable because LRU folio's mapping cannot
-		 * have PAGE_MAPPING_MOVABLE.
-		 */
-		if (unlikely(__folio_test_movable(folio))) {
+		if (unlikely(page_has_movable_ops(&folio->page))) {
 			putback_movable_ops_page(&folio->page);
 		} else {
 			node_stat_mod_folio(folio, NR_ISOLATED_ANON +
@@ -237,26 +232,20 @@ void putback_movable_pages(struct list_head *l)
 /* Must be called with an elevated refcount on the non-hugetlb folio */
 bool isolate_folio_to_list(struct folio *folio, struct list_head *list)
 {
-	bool isolated, lru;
-
 	if (folio_test_hugetlb(folio))
 		return folio_isolate_hugetlb(folio, list);
 
-	lru = !__folio_test_movable(folio);
-	if (lru)
-		isolated = folio_isolate_lru(folio);
-	else
-		isolated = isolate_movable_ops_page(&folio->page,
-						    ISOLATE_UNEVICTABLE);
-
-	if (!isolated)
-		return false;
-
-	list_add(&folio->lru, list);
-	if (lru)
+	if (page_has_movable_ops(&folio->page)) {
+		if (!isolate_movable_ops_page(&folio->page,
+					      ISOLATE_UNEVICTABLE))
+			return false;
+	} else {
+		if (!folio_isolate_lru(folio))
+			return false;
 		node_stat_add_folio(folio, NR_ISOLATED_ANON +
 				    folio_is_file_lru(folio));
-
+	}
+	list_add(&folio->lru, list);
 	return true;
 }
 
@@ -1140,12 +1129,7 @@ static void migrate_folio_undo_dst(struct folio *dst, bool locked,
 static void migrate_folio_done(struct folio *src,
 			       enum migrate_reason reason)
 {
-	/*
-	 * Compaction can migrate also non-LRU pages which are
-	 * not accounted to NR_ISOLATED_*. They can be recognized
-	 * as __folio_test_movable
-	 */
-	if (likely(!__folio_test_movable(src)) && reason != MR_DEMOTION)
+	if (likely(!page_has_movable_ops(&src->page)) && reason != MR_DEMOTION)
 		mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON +
 				    folio_is_file_lru(src), -folio_nr_pages(src));
 
@@ -1164,7 +1148,6 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
 	int rc = -EAGAIN;
 	int old_page_state = 0;
 	struct anon_vma *anon_vma = NULL;
-	bool is_lru = data_race(!__folio_test_movable(src));
 	bool locked = false;
 	bool dst_locked = false;
 
@@ -1265,7 +1248,7 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
 		goto out;
 	dst_locked = true;
 
-	if (unlikely(!is_lru)) {
+	if (unlikely(page_has_movable_ops(&dst->page))) {
 		__migrate_folio_record(dst, old_page_state, anon_vma);
 		return MIGRATEPAGE_UNMAP;
 	}
@@ -1330,7 +1313,7 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,
 	prev = dst->lru.prev;
 	list_del(&dst->lru);
 
-	if (unlikely(__folio_test_movable(src))) {
+	if (unlikely(page_has_movable_ops(&src->page))) {
 		rc = migrate_movable_ops_page(&dst->page, &src->page, mode);
 		goto out_unlock_both;
 	}
diff --git a/mm/vmscan.c b/mm/vmscan.c
index efc818a0bbecb..e5d04c98af976 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1651,9 +1651,11 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,
 	unsigned int noreclaim_flag;
 
 	list_for_each_entry_safe(folio, next, folio_list, lru) {
+		/* TODO: these pages should not even appear in this list. */
+		if (page_has_movable_ops(&folio->page))
+			continue;
 		if (!folio_test_hugetlb(folio) && folio_is_file_lru(folio) &&
-		    !folio_test_dirty(folio) && !__folio_test_movable(folio) &&
-		    !folio_test_unevictable(folio)) {
+		    !folio_test_dirty(folio) && !folio_test_unevictable(folio)) {
 			folio_clear_active(folio);
 			list_move(&folio->lru, &clean_folios);
 		}
-- 
2.49.0


  parent reply	other threads:[~2025-06-18 17:41 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 17:39 [PATCH RFC 00/29] mm/migration: rework movable_ops page migration (part 1) David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 01/29] mm/balloon_compaction: we cannot have isolated pages in the balloon list David Hildenbrand
2025-06-18 18:32   ` Zi Yan
2025-06-18 17:39 ` [PATCH RFC 02/29] mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize() David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 03/29] mm/zsmalloc: drop PageIsolated() related VM_BUG_ONs David Hildenbrand
2025-06-18 18:37   ` Zi Yan
2025-06-19  2:44   ` Sergey Senozhatsky
2025-06-30  6:49   ` Harry Yoo
2025-06-18 17:39 ` [PATCH RFC 04/29] mm/page_alloc: allow for making page types sticky until freed David Hildenbrand
2025-06-18 18:04   ` Zi Yan
2025-06-18 18:06     ` Matthew Wilcox
2025-06-18 18:09       ` Zi Yan
2025-06-18 18:08     ` Zi Yan
2025-06-23 15:26       ` David Hildenbrand
2025-06-23 15:28         ` Zi Yan
2025-06-30  6:59         ` Harry Yoo
2025-06-18 18:43   ` Zi Yan
2025-06-23 15:27     ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 05/29] mm/balloon_compaction: make PageOffline sticky David Hildenbrand
2025-06-18 18:50   ` Zi Yan
2025-06-23 15:28     ` David Hildenbrand
2025-06-23 15:29       ` Zi Yan
2025-06-30  7:07   ` Harry Yoo
2025-06-18 17:39 ` [PATCH RFC 06/29] mm/zsmalloc: make PageZsmalloc() sticky David Hildenbrand
2025-06-18 18:51   ` Zi Yan
2025-06-19  2:45   ` Sergey Senozhatsky
2025-06-30  7:08   ` Harry Yoo
2025-06-18 17:39 ` [PATCH RFC 07/29] mm/migrate: rename isolate_movable_page() to isolate_movable_ops_page() David Hildenbrand
2025-06-18 18:14   ` Zi Yan
2025-06-18 18:39     ` Matthew Wilcox
2025-06-18 18:48       ` Zi Yan
2025-06-23 15:33         ` David Hildenbrand
2025-06-23 15:42           ` Zi Yan
2025-06-23 15:53             ` David Hildenbrand
2025-06-27 15:37             ` David Hildenbrand
2025-06-29 11:28           ` Huang, Ying
2025-06-30  0:20             ` Alistair Popple
2025-06-30  0:58               ` Huang, Ying
2025-06-30  6:41                 ` Alistair Popple
2025-06-30  8:04   ` Harry Yoo
2025-06-30  8:16     ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 08/29] mm/migrate: rename putback_movable_folio() to putback_movable_ops_page() David Hildenbrand
2025-06-18 19:10   ` Zi Yan
2025-06-18 19:18     ` Matthew Wilcox
2025-06-18 19:25       ` Zi Yan
2025-06-18 20:04         ` Matthew Wilcox
2025-06-23 15:37           ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 09/29] mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page() David Hildenbrand
2025-06-20 19:30   ` Zi Yan
2025-06-18 17:39 ` [PATCH RFC 10/29] mm/migrate: remove folio_test_movable() and folio_movable_ops() David Hildenbrand
2025-06-20 19:36   ` Zi Yan
2025-06-18 17:39 ` [PATCH RFC 11/29] mm/migrate: move movable_ops page handling out of move_to_new_folio() David Hildenbrand
2025-06-20 20:06   ` Zi Yan
2025-06-30 12:07   ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 12/29] mm/zsmalloc: stop using __ClearPageMovable() David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 13/29] mm/balloon_compaction: " David Hildenbrand
2025-06-30  1:18   ` Huang, Ying
2025-06-30  8:17     ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 14/29] mm/migrate: remove __ClearPageMovable() David Hildenbrand
2025-06-20 20:15   ` Zi Yan
2025-06-23 15:43     ` David Hildenbrand
2025-06-18 17:39 ` [PATCH RFC 15/29] mm/migration: remove PageMovable() David Hildenbrand
2025-06-20 20:19   ` Zi Yan
2025-06-18 17:39 ` [PATCH RFC 16/29] mm: rename __PageMovable() to page_has_movable_ops() David Hildenbrand
2025-06-20 20:37   ` Zi Yan
2025-06-23 15:47     ` David Hildenbrand
2025-06-23 16:05       ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 17/29] mm/page_isolation: drop __folio_test_movable() check for large folios David Hildenbrand
2025-06-20 20:38   ` Zi Yan
2025-06-18 17:40 ` David Hildenbrand [this message]
2025-06-20 20:41   ` [PATCH RFC 18/29] mm: remove __folio_test_movable() Zi Yan
2025-06-30 10:38   ` David Hildenbrand
2025-06-18 17:40 ` [PATCH RFC 19/29] mm: stop storing migration_ops in page->mapping David Hildenbrand
2025-06-20 20:45   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 20/29] mm: convert "movable" flag in page->mapping to a page flag David Hildenbrand
2025-06-23 14:14   ` Zi Yan
2025-06-23 15:50     ` David Hildenbrand
2025-06-18 17:40 ` [PATCH RFC 21/29] mm: rename PG_isolated to PG_movable_ops_isolated David Hildenbrand
2025-06-23 14:16   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 22/29] mm/page-flags: rename PAGE_MAPPING_MOVABLE to PAGE_MAPPING_ANON_KSM David Hildenbrand
2025-06-23 14:17   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 23/29] mm/page-alloc: remove PageMappingFlags() David Hildenbrand
2025-06-23 14:20   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 24/29] mm/page-flags: remove folio_mapping_flags() David Hildenbrand
2025-06-23 14:20   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 25/29] mm: simplify folio_expected_ref_count() David Hildenbrand
2025-06-23 14:23   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 26/29] mm: rename PAGE_MAPPING_* to FOLIO_MAPPING_* David Hildenbrand
2025-06-23 14:25   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 27/29] docs/mm: convert from "Non-LRU page migration" to "movable_ops page migration" David Hildenbrand
2025-06-23 14:28   ` Zi Yan
2025-06-18 17:40 ` [PATCH RFC 28/29] mm/balloon_compaction: "movable_ops" doc updates David Hildenbrand
2025-06-18 17:40 ` [PATCH RFC 29/29] mm/balloon_compaction: provide single balloon_page_insert() and balloon_mapping_gfp_mask() David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250618174014.1168640-19-david@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=arnd@arndb.de \
    --cc=brauner@kernel.org \
    --cc=byungchul@sk.com \
    --cc=chengming.zhou@linux.dev \
    --cc=christophe.leroy@csgroup.eu \
    --cc=corbet@lwn.net \
    --cc=eperezma@redhat.com \
    --cc=gourry@gourry.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=jack@suse.cz \
    --cc=jackmanb@google.com \
    --cc=jasowang@redhat.com \
    --cc=jerrin.shaji-george@broadcom.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=maddy@linux.ibm.com \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=mst@redhat.com \
    --cc=nao.horiguchi@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=osalvador@suse.de \
    --cc=peterx@redhat.com \
    --cc=rakie.kim@sk.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtualization@lists.linux.dev \
    --cc=willy@infradead.org \
    --cc=xu.xin16@zte.com.cn \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=zhengqi.arch@bytedance.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.