From nobody Thu Oct 9 11:00:22 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E09692FCFC5 for ; Wed, 18 Jun 2025 17:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750268455; cv=none; b=c4Qsu+11JWV70a9d5McwGVLOvoc+6uygHJRS1uPWkkTa73WB1puOcXWtaHcQPAWG4oO/rkn1CNzNuzK6jhDonu1EA2el6uVcfpa3QpzJoamlW08GHau24nizuTWTvBW86c17KxvmBMCJD+qw52GcPPDLuGcoYPt93ug9Mgg20TI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750268455; c=relaxed/simple; bh=kK+1H5O+WM/ACnNcL3KxA88ivXOG9CXAUU38rvMnDO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+eKwaloCauzt6cYSWTg/Wi+eamB2RmiXj03/tlq2rJnOa2y4viVzVydmaRb+9QlgnYi8xQorhb0DQWRhk2Vb1koKP+hNJLWCWfKWS1OuOnZMOhtStLrpmvE/LyZPji9JLay6DMDep1+6Ht5mgACBb00b9Pb6rqZk293jHY6a1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aJk6bjMP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aJk6bjMP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750268450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fdGmEg3KxJkHEQxrZBJZz4koG+H5rtVXjjGZN1RlWcM=; b=aJk6bjMPWbz4fo9tanBF/Bn1ScFgtQCU8aABBU+OXvHWGl/p9U0IyOfT+Rf3hWWsryJZna MttHCiRmfO03kAVsZKY0plHGlrtW+zqLnDHw5y4VkLsuYXqhTVJ8PT6KaLFmMV+En1/jL/ i8lHCQ3oSmt7j6MxqmziS2CoGv+6Z/M= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-PzV2P5n3N-WodLoLrLj9RQ-1; Wed, 18 Jun 2025 13:40:48 -0400 X-MC-Unique: PzV2P5n3N-WodLoLrLj9RQ-1 X-Mimecast-MFC-AGG-ID: PzV2P5n3N-WodLoLrLj9RQ_1750268447 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-450cb8f8b1bso15227185e9.3 for ; Wed, 18 Jun 2025 10:40:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750268447; x=1750873247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fdGmEg3KxJkHEQxrZBJZz4koG+H5rtVXjjGZN1RlWcM=; b=boY4hiPiOKmMweA+/zQSL/xOp+/1UqNEYEViv9xypVvi5rKP0adgcz7J4XZRxc7qv8 yRnfJlmGMokxvrxf2+cyTjc0E6dfA4CLe0T9ayjd+DFQyBgpKW/1pVVldRxUcOLjVcPZ Qm8XuDOa4axIgm/0p7rXxdRWOHJXzzKAosuyYO7vXp/S91RFAmPv5Wgu0SodHLX4NLGA KrJXKR1PYXzmNFX92CFSxbFnc6m8hPL/ftP+K8CmtR5zgNpHMB04Tscpuz4ftNI2YegW 7NK2n644QPan5We2MNo7BBG/oeu+i6SO4A0JcujYqo+nXu4JJjHUPLJOe2/FZjVxVBtP 8AZg== X-Gm-Message-State: AOJu0YxkhWIK/BR1OhOm0FLpmJ6/7sn7A4O0t3KcDnOh1es5VoUtXP9x R2IEyPFgso/XwbaUEg15iIeOXJUwci459DrrgGmXbf0gClZMeXvJxI3bvRthUiOZv7htDCKIzLq yWAB7pV75B75Sj81YjC05zKh81ckEHe2zFomWTpDR6gVTVW1zbDfsZ5CmO7o+WGxXQuBroWOpb/ BfI7P/+L+KnYwZmvUiPtx6MgLOoktdqMIC6xUHYJIs8Ampxi3H X-Gm-Gg: ASbGncsEHG6NSfzqIOzgtlUSHIA3I9al+Mb6Kc5LQ+XkMSsLabQGqgOU5Kf+d6xp+bP OM1oTryhP2G4wYaV09aqmxR4Kpmh8CcpKjkNKcASG89k66bNE29RXS4XiSvxhw7dhUTrr5yjap0 K0J66bEcnZ11yWLcvYQz52tRO9bpi7jVC3m4Rt5fbTzH7rYbGt/wOZ9n44Caa9yhXFUK/SvgEg3 so7ZdKV16d6U31hv66n34jGxmB49JOetGVe+DB5pyx2Xj+jpszXMgUbqmJGx8EqnT6gqXHOaxRQ XH9kS/icdVcH+cwSN2iTp+W8Q49/2jsWVtMnHhjdnaEdJiUH69bYkOAG78VwWFBcoTjSMZd+53z tVHPw+g== X-Received: by 2002:a05:600c:5253:b0:453:66f:b96e with SMTP id 5b1f17b1804b1-4534219a64fmr154403525e9.11.1750268446668; Wed, 18 Jun 2025 10:40:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXftk3ZXBXIBGlT1RpZSgQfC+IysEY/Lblmm+ealanQwQ/CfiKMmfIF1BFjPpj67LfRQmzUw== X-Received: by 2002:a05:600c:5253:b0:453:66f:b96e with SMTP id 5b1f17b1804b1-4534219a64fmr154402755e9.11.1750268446175; Wed, 18 Jun 2025 10:40:46 -0700 (PDT) Received: from localhost (p200300d82f2d2400405203b5fff94ed0.dip0.t-ipconnect.de. [2003:d8:2f2d:2400:4052:3b5:fff9:4ed0]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4535e97aa15sm3975415e9.2.2025.06.18.10.40.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jun 2025 10:40:45 -0700 (PDT) From: David Hildenbrand 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 , Andrew Morton , Jonathan Corbet , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Jerrin Shaji George , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Alexander Viro , Christian Brauner , Jan Kara , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , "Matthew Wilcox (Oracle)" , Minchan Kim , Sergey Senozhatsky , Brendan Jackman , Johannes Weiner , Jason Gunthorpe , John Hubbard , Peter Xu , Xu Xin , Chengming Zhou , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Rik van Riel , Harry Yoo , Qi Zheng , Shakeel Butt Subject: [PATCH RFC 11/29] mm/migrate: move movable_ops page handling out of move_to_new_folio() Date: Wed, 18 Jun 2025 19:39:54 +0200 Message-ID: <20250618174014.1168640-12-david@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250618174014.1168640-1-david@redhat.com> References: <20250618174014.1168640-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's move that handling directly into migrate_folio_move(), so we can simplify move_to_new_folio(). While at it, fixup the documentation a bit. Note that unmap_and_move_huge_page() does not care, because it only deals with actual folios. (we only support migration of individual movable_ops pages) Signed-off-by: David Hildenbrand Reviewed-by: Zi Yan --- mm/migrate.c | 61 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 456e41dad83a2..db807f9bbf975 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1024,11 +1024,12 @@ static int fallback_migrate_folio(struct address_sp= ace *mapping, } =20 /* - * Move a page to a newly allocated page - * The page is locked and all ptes have been successfully removed. + * Move a src folio to a newly allocated dst folio. * - * The new page will have replaced the old page if this function - * is successful. + * The src and dst folios are locked and the src folios was unmapped from + * the page tables. + * + * On success, the src folio was replaced by the dst folio. * * Return value: * < 0 - error code @@ -1037,34 +1038,30 @@ static int fallback_migrate_folio(struct address_sp= ace *mapping, static int move_to_new_folio(struct folio *dst, struct folio *src, enum migrate_mode mode) { + struct address_space *mapping =3D folio_mapping(src); int rc =3D -EAGAIN; - bool is_lru =3D !__folio_test_movable(src); =20 VM_BUG_ON_FOLIO(!folio_test_locked(src), src); VM_BUG_ON_FOLIO(!folio_test_locked(dst), dst); =20 - if (likely(is_lru)) { - struct address_space *mapping =3D folio_mapping(src); - - if (!mapping) - rc =3D migrate_folio(mapping, dst, src, mode); - else if (mapping_inaccessible(mapping)) - rc =3D -EOPNOTSUPP; - else if (mapping->a_ops->migrate_folio) - /* - * Most folios have a mapping and most filesystems - * provide a migrate_folio callback. Anonymous folios - * are part of swap space which also has its own - * migrate_folio callback. This is the most common path - * for page migration. - */ - rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, - mode); - else - rc =3D fallback_migrate_folio(mapping, dst, src, mode); + if (!mapping) + rc =3D migrate_folio(mapping, dst, src, mode); + else if (mapping_inaccessible(mapping)) + rc =3D -EOPNOTSUPP; + else if (mapping->a_ops->migrate_folio) + /* + * Most folios have a mapping and most filesystems + * provide a migrate_folio callback. Anonymous folios + * are part of swap space which also has its own + * migrate_folio callback. This is the most common path + * for page migration. + */ + rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, + mode); + else + rc =3D fallback_migrate_folio(mapping, dst, src, mode); =20 - if (rc !=3D MIGRATEPAGE_SUCCESS) - goto out; + if (rc =3D=3D MIGRATEPAGE_SUCCESS) { /* * For pagecache folios, src->mapping must be cleared before src * is freed. Anonymous folios must stay anonymous until freed. @@ -1074,10 +1071,7 @@ static int move_to_new_folio(struct folio *dst, stru= ct folio *src, =20 if (likely(!folio_is_zone_device(dst))) flush_dcache_folio(dst); - } else { - rc =3D migrate_movable_ops_page(&dst->page, &src->page, mode); } -out: return rc; } =20 @@ -1328,20 +1322,21 @@ static int migrate_folio_move(free_folio_t put_new_= folio, unsigned long private, int rc; int old_page_state =3D 0; struct anon_vma *anon_vma =3D NULL; - bool is_lru =3D !__folio_test_movable(src); struct list_head *prev; =20 __migrate_folio_extract(dst, &old_page_state, &anon_vma); prev =3D dst->lru.prev; list_del(&dst->lru); =20 + if (unlikely(__folio_test_movable(src))) { + rc =3D migrate_movable_ops_page(&dst->page, &src->page, mode); + goto out_unlock_both; + } + rc =3D move_to_new_folio(dst, src, mode); if (rc) goto out; =20 - if (unlikely(!is_lru)) - goto out_unlock_both; - /* * When successful, push dst to LRU immediately: so that if it * turns out to be an mlocked page, remove_migration_ptes() will --=20 2.49.0