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 54585C83F03 for ; Fri, 4 Jul 2025 10:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C5E96B8027; Fri, 4 Jul 2025 06:26:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 876586B800A; Fri, 4 Jul 2025 06:26:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73E756B8027; Fri, 4 Jul 2025 06:26:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5FD996B800A for ; Fri, 4 Jul 2025 06:26:00 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 294AC80283 for ; Fri, 4 Jul 2025 10:26:00 +0000 (UTC) X-FDA: 83626201680.11.0274C24 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id EB96B20003 for ; Fri, 4 Jul 2025 10:25:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPnE7xPP; spf=pass (imf03.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751624758; 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=QfBSPQaG9xeZudkGcFWJAgBBxYLZuNBkDrffE/+eDPg=; b=pTtl3PKwOgN/35PsgcgwXLU+Z42tUaV6XJGA5eGS2KD1SkDFy9iZlXA//VpnVFr9GlLvQq S1z3+K842gzbVsJiiHJSd7UW6diM9MCGuH7qvAwQFfSb3ho6+H/6o10Xb0VS1CwaLmC4jv 88s+d/hiBUCnRMF6LJhezAqRfHg2N8E= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPnE7xPP; spf=pass (imf03.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751624758; a=rsa-sha256; cv=none; b=c6IxcyKtJnt4zcbKijIJPyHf9FyVkxG8mSsblmgK3drlijpw78LE2ZRR5E3i7XhiomjCkK W/CQgdugAnRwSZQ2AuPZ9W7QnUgJ3D7QMY6t+aGGWF3WlfNTy1i0vqdkOZg6Rs9YmbLCUU SfLtnE3pm3F2EmhiaqRbXodpjtprgQ4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751624757; 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=QfBSPQaG9xeZudkGcFWJAgBBxYLZuNBkDrffE/+eDPg=; b=RPnE7xPP9v5R4M8rwpuTVRXSAoyMbvUNZivsmnjz6q/Z9ux2JZXjhnLfjJOPvZ7/+NH2ef hEhdBpPcJghdKfcLoZfqq/0QrodrKN9tB9tNCjm9rWBBOsYztrErPyQYSTZHvwDJsw4wt5 ANF21Et031hwXurburXg0OTIPDgHWFM= 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-534-P9Uob_95Nbu13_8JUxIenA-1; Fri, 04 Jul 2025 06:25:56 -0400 X-MC-Unique: P9Uob_95Nbu13_8JUxIenA-1 X-Mimecast-MFC-AGG-ID: P9Uob_95Nbu13_8JUxIenA_1751624755 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4539b44e7b1so5192435e9.1 for ; Fri, 04 Jul 2025 03:25:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751624755; x=1752229555; 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=QfBSPQaG9xeZudkGcFWJAgBBxYLZuNBkDrffE/+eDPg=; b=aKLcvrKotJ9BRu7HI4lall8i6RfCvPPr7QWt7zaNjkK6P/WVS5uMGJERcu8JPi118l d3Ged7Y8lfvwAjoORkFeysH5AunLZ/QU8wz8fjrQZDSFo4xOUuteSYdAkA8eYghlQ/Uv V3tU8Bovxq7zN98VTy0nYI+HRIb7sxdQA2oykOIeGoneU7rKzlph87hAFB2kULZIB5p7 klIREnRpqGoehxwf2Js9JtMoqp3HVMsxt+JsoO13Ao288Wd5DGuHnAUmqWAh7rrfWmBR wLZLDUvk+DoiqHkkyFf7d3PLFL8dF1x1YlYGGIi+rHFvENS9az8/ts9Gnpthzhq4IYRz NVsQ== X-Gm-Message-State: AOJu0Yxlqu5Mf0ia6yw1PW+RER3vHZZv4vfkPl8PiwVIOUbOe34h/Nga rMXitqKy9gk9/s3veYF6eWV3hNvKz4sx2IF5hSnA3no8dNqHCR9QHbkx0KQCnt4CJ72PlLNucbv mcghWG7YOyGXJT6RMLLI6VJ32rfhS+bYsAaC3BwDvFgp4r65STYPn X-Gm-Gg: ASbGncttbpEiqH0nCOtMBurem31wQOhlmg3Tc5aBLKvvM2R3ZI3nQHCSuDZatBBpBHk RvfNfS/q6lXdjlaKgsl+kDLdLE7YsZDoPTaZqZ1bPKgmIfHUT/Ll8Q8W2AdhILKdzdC2dqd1/jM GE0TbCu6ARA5GD1F3WgDBbJklEcJCsfFDaxd7z1m6opR70OO2H53RF34+smT10TmYy3ITeVeNMq G1egGNQLEmmiaIM8V/B/lJgXca3Aq+od5O+ck3t4oucRKxg1jJ5Hd6BzaFsmqecCMqTb5HcTbc1 dmEE0/RYiv/Sgk+RVWm1SbJ0Du03RG0gdvJ7Soyf0impProLHQcL1tNfmMT7rBm6yPyIVUv9G9O 4O8rN8A== X-Received: by 2002:a05:6000:2312:b0:3a4:e54c:adf2 with SMTP id ffacd0b85a97d-3b497011964mr1275758f8f.5.1751624754863; Fri, 04 Jul 2025 03:25:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfrhXd/yIZyYpWVcak9U+vZiPIE1G2M2XMax2kqYgfF02lLZKKCminarbrdx4X4RqYGyvSNg== X-Received: by 2002:a05:6000:2312:b0:3a4:e54c:adf2 with SMTP id ffacd0b85a97d-3b497011964mr1275679f8f.5.1751624754226; Fri, 04 Jul 2025 03:25:54 -0700 (PDT) Received: from localhost (p200300d82f2c5500098823f9faa07232.dip0.t-ipconnect.de. [2003:d8:2f2c:5500:988:23f9:faa0:7232]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3b47285e241sm2143549f8f.94.2025.07.04.03.25.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jul 2025 03:25:53 -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 v2 09/29] mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page() Date: Fri, 4 Jul 2025 12:25:03 +0200 Message-ID: <20250704102524.326966-10-david@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250704102524.326966-1-david@redhat.com> References: <20250704102524.326966-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mJhNGUMxIGJCJcUhUnjxACRmnrk88YOYgSRbbX8NGco_1751624755 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: EB96B20003 X-Stat-Signature: sr3w1h7w1ie93rossicmupc1ab7ci1oe X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1751624757-579310 X-HE-Meta: U2FsdGVkX1+7eTTrj+3u9QbIMOCdpX3ba9vTqvDnQFAax2LgqxzkZZpXgOeWy8a6GdCAL1emDeTaNMKKVEGPYbBEmrFxEzpVrT7NS4p6SJG1z2Qbdv2IE9CCM4jI/Iydha6l2ztUAr+4R+BZ/LOgB0P8fHEgil9aCOLIRsl2t50R4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ZGqCamqLpWPs/a5K8TmxKRqIqGUIorBgdtMnOF4galJdwnLIig6cjUAcLIk9WKyqtc2YP8ubEgWY25EJc4ugju4i0F7lPO1DIQG5X6KTSWPlU/l43btAQl9M/ppqGADDNoev5ufs/mjgN1ihYv/zam20NoK+tDYpLZIWqA81DETRFIA1muQJHJ8z6yFGrhA3UPO69FFSabjCduqcw1YMeukNtMjU+mTctQNn00BTNhKI6P/MexrkwF7zl8lL26C2bIXBzSo41HESGehY/Vao3nMZcCIRtcH1lvV+/mAkvIVJ1otoWTIlycUg+6XmNQH1yz1hoUxR6ws3o4LfCMnRs2jsnMHoMQfTDiyZA9Teq9J1Gqm3K1isz9mi7EiyzEj3ZUcbu6oZSe+JGmV17tcXD4mjMwDQMoltu4YBi+PE/+cFg= 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. Before this change, we would have called flush_dcache_folio() also on movable_ops pages. As documented in Documentation/core-api/cachetlb.rst: "This routine need only be called for page cache pages which can potentially ever be mapped into the address space of a user process." So don't do it for movable_ops pages. If there would ever be such a movable_ops page user, it should do the flushing itself after performing the copy. 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. Reviewed-by: Zi Yan Reviewed-by: Lorenzo Stoakes 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 c3cd66b05fe2f..d66d0776036c3 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