From mboxrd@z Thu Jan 1 00:00:00 1970 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 94542C7115A for ; Wed, 18 Jun 2025 17:40:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DBA96B0093; Wed, 18 Jun 2025 13:40:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 365B56B00B1; Wed, 18 Jun 2025 13:40:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DFC76B00B2; Wed, 18 Jun 2025 13:40:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 063AC6B0093 for ; Wed, 18 Jun 2025 13:40:49 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D5F7F14080C for ; Wed, 18 Jun 2025 17:40:48 +0000 (UTC) X-FDA: 83569236576.22.B335861 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 61BA0A000C for ; Wed, 18 Jun 2025 17:40:45 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RCpxvbjO; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750268446; a=rsa-sha256; cv=none; b=zneVBCUUjYidIukIXmbTK/nJy5VNk/03OKWrxePOaVNjGEPLWmYmDjdytJ30SlTFYimCfb okJn4/avWO/SRvUSfXetC/Rrv9nCyMGbRDDwGUx/VXdDTkT0pOSGva/T6QGp2RICOLZ2C2 IZCrYpZQTNB76zivi+utFqoL+gayle4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RCpxvbjO; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750268446; 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:dkim-signature; bh=j8LuODrccx/EBs9A7vTNySqHbhe9k9tI08r8Ga0Xgcs=; b=bsKb6e0DypfQHUS5QI7p+N6/iSfUcACgHYmcy37g38oP9jcLfUiWBOe/0Caqiaz3ZVcW91 JIpmo7d3O3XuXft30LfxOIu0YgoteJBgAGnnzyaM2+qRP5lAl15RxP8vckURBoNPondA6g rPtRpvjUeNf5JQJ/hkI1cLQouP1Mexw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750268444; h=from:from: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=j8LuODrccx/EBs9A7vTNySqHbhe9k9tI08r8Ga0Xgcs=; b=RCpxvbjOuT9c9cUHmHHE5gQUFTBlbTEwmuAgOTHzu85isAMX9Ys2O/Dzxuxty2AeJmlTZd Yi71kmg/V0eeFa/FhWft8CI6lA5skAJej74NnLso3yFPKi7orD81JTKp++xzagG9SKGc+D 43nG5LqNvrX+srGE6OCU7JUTZidScBE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-KcR1bwnvMTSuusT5OxkTQw-1; Wed, 18 Jun 2025 13:40:43 -0400 X-MC-Unique: KcR1bwnvMTSuusT5OxkTQw-1 X-Mimecast-MFC-AGG-ID: KcR1bwnvMTSuusT5OxkTQw_1750268442 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-450d6768d4dso47059665e9.2 for ; Wed, 18 Jun 2025 10:40:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750268441; x=1750873241; 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=j8LuODrccx/EBs9A7vTNySqHbhe9k9tI08r8Ga0Xgcs=; b=GNZ2EiCVeJyQrLgK2FMmOPjut9u1eOOBcgwtCwJV8p8NTa32ckSsiPIjKFVDfM2wAr iZo349L/fS0jsLjMDqB59rFDmU2mMgq8nyDJU7EI6rzi9CjwvGan4Iq0Nome38h+DnHA eCWDOXnw5Q+3nxQRYUotkL37IKSepM4jd0rPpwd/1E4aSUpx5Dhn7XMMn1Trz8SuYj1o m/aHzJGSSwqIle4nlsKXlY+pbsPEuZ0wBkBbvW72rZoXd/OtlVmUa7WST4ECA6Dvd2Gd EtrEPR7MgVtWtt40Zl+3u5iJqSOEJN3W5FiJbrTbL4/lMGk10MfwJrO1LdkUqZN7RaGs MP9g== X-Gm-Message-State: AOJu0YwUj+s85ut57y3vCk5+BDzHY5qP6yMwGb28WpojTD+c1cjEgXbd c6AODU1Fo0XlCtkPZgOz22SekACbsSDYBeZcqBiTZO5UFSyii/gZlwTmTtLLoRiCyFIiJqxjDIl AbaOqET8480IsND19TEuAs4R5467fcC5HvSj1k+jgOJD36/7bdTOl X-Gm-Gg: ASbGncsuEyks53Y48Mdiy5Nt2shtF0l2asKeXmOGyFwEUGrVEuPTVFoa/Lc7LXjpLXZ RRjGTm3TwOA5LWsDT2Pd6hID1b2XiRyZCRKBoLrQ8GAlg+YVyO1YLVxx/ZTsGjpI0dtu092hV36 bhy29vVQmMvbvQflJog/vIoYvnFNsrEQiS9d/FmhC8BGvQOnQ9yyYftWkpPoH9XN0BWBTZzTYOm /JDkycLTBF6LMi0vNbd+CigSA1m2ATT5vxAkwJrj87eNYDuVqSnSo3xRdxAW9HqLx1MWq02w7s6 Rd3eIIpCW7+MQQyeCdXZFVoBiV3lLDSiByJL4Wy7QKalVKrDRyhloqy1clglveks+sPg99gFiXy Zr4mVcQ== X-Received: by 2002:a05:600c:1ca1:b0:440:54ef:dfdc with SMTP id 5b1f17b1804b1-4533cae6605mr166407595e9.8.1750268441179; Wed, 18 Jun 2025 10:40:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHc4TaNXORzdooVLODlvwGNYZ3WZPNGmS5C2sKfTSdPVLBbA2Ps3b4UKdLfdRWvy1N8seVTmg== X-Received: by 2002:a05:600c:1ca1:b0:440:54ef:dfdc with SMTP id 5b1f17b1804b1-4533cae6605mr166407185e9.8.1750268440690; Wed, 18 Jun 2025 10:40:40 -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-4535e97ab95sm3814165e9.7.2025.06.18.10.40.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jun 2025 10:40:40 -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 09/29] mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page() Date: Wed, 18 Jun 2025 19:39:52 +0200 Message-ID: <20250618174014.1168640-10-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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4AqjS1PNwLJ8OuuxftJppHSx0k3dwPxGBFr1BKnrRpQ_1750268442 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 61BA0A000C X-Stat-Signature: bqbyeogb1i6pgcicw4zdh1ajxtjkyb9z X-Rspam-User: X-HE-Tag: 1750268445-234989 X-HE-Meta: U2FsdGVkX1+0KsVDhdkzZT0OZMUTLz8BXVLa/ASuUOFLMBAesRcOHXODyMjRChFme2F3sw9WgPAIO6tVzjj6+hsyI8PoE6gnCDyUim3yeerfUjKPFbjikFou4eL6CobBkq/FTbd4mIT+Nh6HT8xCmAJaXSv/8QfDXG++0ZnM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C4/C3+AHRZ/8o6N7959cd+b7ZIWCxvinPXfisE57LMVIrhyLp6Vmd79X2iRcpT9ZCTeA2QW06+/KsrustqSTSeKOx6v6Ra/cxomfYBya3Yw6VkAhSGyoV6j9U/ShDwU7+fMBzWqxhSelgdd+Mbgn8jDbDw8MxHmRWvcVkxzExOCWDKNFhyO0dXbfL0QkCbTcqXByl14W4Ho0hw2fOHH/X1v2/wA4c4yLc0ozp7qNBf/WyWiEDDFWqMrbFsCmS3/Tv2yg7VIF57ZVQSNrk87xTgd2rjvTK9zTFIvUX0/V+gafmPeoddW1tbbeEQoB50fSqI1vzuCXmvZzYOFwFcsD0chjxol/p7jlqvogD1 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: List-Subscribe: List-Unsubscribe: Let's factor it out, simplifying the calling code. The assumption is that flush_dcache_page() is not required for movable_ops pages: as documented for flush_dcache_folio(), it really only applies when the kernel wrote to pagecache pages / pages in highmem. movable_ops callbacks should be handling flushing caches if ever required. Note that we can now change folio_mapping_flags() to folio_test_anon() to make it clearer, because movable_ops pages will never take that path. Signed-off-by: David Hildenbrand --- mm/migrate.c | 82 ++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 32e77898f7d6c..456e41dad83a2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -159,6 +159,45 @@ static void putback_movable_ops_page(struct page *page) folio_put(folio); } +/** + * migrate_movable_ops_page - migrate an isolated movable_ops page + * @page: The isolated page. + * + * Migrate an isolated movable_ops page. + * + * If the src page was already released by its owner, the src page is + * un-isolated (putback) and migration succeeds; the migration core will be the + * owner of both pages. + * + * If the src page was not released by its owner and the migration was + * successful, the owner of the src page and the dst page are swapped and + * the src page is un-isolated. + * + * If migration fails, the ownership stays unmodified and the src page + * remains isolated: migration may be retried later or the page can be putback. + * + * TODO: migration core will treat both pages as folios and lock them before + * this call to unlock them after this call. Further, the folio refcounts on + * src and dst are also released by migration core. These pages will not be + * folios in the future, so that must be reworked. + * + * Returns MIGRATEPAGE_SUCCESS on success, otherwise a negative error + * code. + */ +static int migrate_movable_ops_page(struct page *dst, struct page *src, + enum migrate_mode mode) +{ + int rc = MIGRATEPAGE_SUCCESS; + + VM_WARN_ON_ONCE_PAGE(!PageIsolated(src), src); + /* If the page was released by it's owner, there is nothing to do. */ + if (PageMovable(src)) + rc = page_movable_ops(src)->migrate_page(dst, src, mode); + if (rc == MIGRATEPAGE_SUCCESS) + ClearPageIsolated(src); + return rc; +} + /* * Put previously isolated pages back onto the appropriate lists * from where they were once taken off for compaction/migration. @@ -1023,51 +1062,20 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, mode); else rc = fallback_migrate_folio(mapping, dst, src, mode); - } else { - const struct movable_operations *mops; - /* - * In case of non-lru page, it could be released after - * isolation step. In that case, we shouldn't try migration. - */ - VM_BUG_ON_FOLIO(!folio_test_isolated(src), src); - if (!folio_test_movable(src)) { - rc = MIGRATEPAGE_SUCCESS; - folio_clear_isolated(src); + if (rc != MIGRATEPAGE_SUCCESS) goto out; - } - - mops = folio_movable_ops(src); - rc = mops->migrate_page(&dst->page, &src->page, mode); - WARN_ON_ONCE(rc == MIGRATEPAGE_SUCCESS && - !folio_test_isolated(src)); - } - - /* - * When successful, old pagecache src->mapping must be cleared before - * src is freed; but stats require that PageAnon be left as PageAnon. - */ - if (rc == MIGRATEPAGE_SUCCESS) { - if (__folio_test_movable(src)) { - VM_BUG_ON_FOLIO(!folio_test_isolated(src), src); - - /* - * We clear PG_movable under page_lock so any compactor - * cannot try to migrate this page. - */ - folio_clear_isolated(src); - } - /* - * Anonymous and movable src->mapping will be cleared by - * free_pages_prepare so don't reset it here for keeping - * the type to work PageAnon, for example. + * For pagecache folios, src->mapping must be cleared before src + * is freed. Anonymous folios must stay anonymous until freed. */ - if (!folio_mapping_flags(src)) + if (!folio_test_anon(src)) src->mapping = NULL; if (likely(!folio_is_zone_device(dst))) flush_dcache_folio(dst); + } else { + rc = migrate_movable_ops_page(&dst->page, &src->page, mode); } out: return rc; -- 2.49.0