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 2CE29C8302F for ; Mon, 30 Jun 2025 13:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40DAE6B00B2; Mon, 30 Jun 2025 09:00:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 396496B00B3; Mon, 30 Jun 2025 09:00:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AD246B00B4; Mon, 30 Jun 2025 09:00:47 -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 18F736B00B2 for ; Mon, 30 Jun 2025 09:00:47 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7E1131404CE for ; Mon, 30 Jun 2025 13:00:46 +0000 (UTC) X-FDA: 83612076492.01.8C96FDA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 3BD45100013 for ; Mon, 30 Jun 2025 13:00:44 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xc2Bbyxa; spf=pass (imf14.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.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=1751288444; 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=ZjlP0D3eY9tZf8Nb4qLq/i9Tdq3zqU6lo6GiM8rDh3E=; b=0yoomKDn3hJ6hXi0BEIIilAdKiMxQ5bQCY0XXbWQOQpsXwlYywzRF/sMqoZi5GoZCEC1xl 2oQj0ufMcp90Izu95hb1kMR2P99bJaS1R/3+lNWbNepigKEC29R8wmH61UreKfNjiv5wJa UZSHyjb+VOoUwiYizlP1UiTqsxwX6Q4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xc2Bbyxa; spf=pass (imf14.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.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=1751288444; a=rsa-sha256; cv=none; b=Su1LTaagEK8n+HIA2CiH81O0G6sCCSlytHmHWK3JIg7Ou/I8Mcnfc85Vu4jKGEbB9KvAyR Sd56vEbiBflZuJr2aHNnvI9THR8D5S35m/KiZ2w04pbvd0G61uBZie/QSctrUmMWk3O1Xi yKvUGTMkRISfj9dR6nkC0hebAIuz6qw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751288443; 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=ZjlP0D3eY9tZf8Nb4qLq/i9Tdq3zqU6lo6GiM8rDh3E=; b=Xc2BbyxaolFYAItkD3cPbv536Lry9ZvpGTCufvz44zN4UZIrHu5FEtr+G3PmV3U2jAJhWk vAYd0Yw7vjMU850ZTSOwssxR/fro39IFyfy3x6WfsfBoeyDROlOorkKKUFKmH4TRNSXnqS pjTt2e5u4fQ04Ysiq0X8iTMELgRpDug= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-9r7DfhvTMg2wJBAZ_TPUxw-1; Mon, 30 Jun 2025 09:00:42 -0400 X-MC-Unique: 9r7DfhvTMg2wJBAZ_TPUxw-1 X-Mimecast-MFC-AGG-ID: 9r7DfhvTMg2wJBAZ_TPUxw_1751288441 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-451deff247cso25978755e9.1 for ; Mon, 30 Jun 2025 06:00:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751288441; x=1751893241; 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=ZjlP0D3eY9tZf8Nb4qLq/i9Tdq3zqU6lo6GiM8rDh3E=; b=DxvLwg1I3wd8fUVp+ibDMWkIcG5xP/BTJ+gfDglmIgLcBxJSynJb5lqWtfydZTZMZv qRi9A2/+a9vpOYn7FEoVr6JVz1x7WjkDnJBvXSMNgGWJkBxUTS5xmbILvIX68o8ky49u T29rGfsuHjOC04PgKuCtIiT6H82vqRPa5URBaswHdaAG7q7rZhmnUO4/Zo7KrQJ6wfY7 CyQaa7wxGs5v+uH3H9Peo1ObLfdKEGXqWOkQDsOQmaak5SPHgMhOwzVGLxC2+mX9NIAj SE+nw3MpncqSTebs4nYdIOhThWxL5dvhSvM758J/07pR7EZ5xSu7/lfJmFAj/ie09tTc 3ROQ== X-Gm-Message-State: AOJu0YxAs9GiKHypdEadyhVP6ccRhE2UbWXAh+8Rva8wIl4JGNDcda3h nqtQPUwzFuWgG0Rcj1r/1Eb+wNFxk77dWBKiQ69su3rNkWWXv9AN9SAfCsZmWbr7/RkvKifmM66 ZaUWH+J/8E1TpNanPEvjd+4ynIXw5ymAjOpOKAqqa+bUzZT820M67 X-Gm-Gg: ASbGncvQDbh90sPhr0YEIoZnmNWCg9ZOw3FBRFzt1qkU/OLC/r0Is4nYB60T1KZu5Rd O//Kc2cm1NMcTJyuqb23G8AITuwKemjR6JILCHSQiybwAcHr2FRT04dd/Rqs2KgnoZPoF0ctKSg 5lxvC87Zru6M7it7kA8GktIY17teT5PEtL9t8hUACSyz0IbbL5oCNlcoynumt9/iff3kZhYKS4A o6OaU0NlGKpMaTh8sbWfzYlkbXeBXpdwynNWkvcn+kQ7hsIptdUhS87ndGYFOyd9vrRJHp1K/Fq 5e6AVjhPL+u5KO2pYk5xqC/IrIYF0lUs/bTypXT/S+oAPD21eIoMfxyiBvZ0PJzS2r+j49NylWv jj+qXcV4= X-Received: by 2002:a05:6000:200e:b0:3a6:daff:9e5 with SMTP id ffacd0b85a97d-3a6f31023bdmr13743580f8f.7.1751288440445; Mon, 30 Jun 2025 06:00:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaNYb3ONKvqKvr320nfpncqFiQLJi8PiPIyho0Wzz9N7dVDIemJ3QiyBdfpFdZCgx38anKxQ== X-Received: by 2002:a05:6000:200e:b0:3a6:daff:9e5 with SMTP id ffacd0b85a97d-3a6f31023bdmr13743499f8f.7.1751288439567; Mon, 30 Jun 2025 06:00:39 -0700 (PDT) Received: from localhost (p200300d82f40b30053f7d260aff47256.dip0.t-ipconnect.de. [2003:d8:2f40:b300:53f7:d260:aff4:7256]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a892e52ca4sm10445235f8f.58.2025.06.30.06.00.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jun 2025 06:00:39 -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 v1 09/29] mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page() Date: Mon, 30 Jun 2025 14:59:50 +0200 Message-ID: <20250630130011.330477-10-david@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250630130011.330477-1-david@redhat.com> References: <20250630130011.330477-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iWnTSC4TWLCyau4ZkjVn1eJDONKFJ99NmYRhi9i4U0c_1751288441 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: 78ntzozdgqrq4zf7wqm5zf9zzyo1r3gd X-Rspamd-Queue-Id: 3BD45100013 X-Rspamd-Server: rspam11 X-Rspam-User: X-HE-Tag: 1751288444-153475 X-HE-Meta: U2FsdGVkX18STg2dCtoGw2Rckw9pXZy8l05hdiQulbKlSCDrXVR60ZE6E5KZSrfEXwv4Zn7wmpToYI5PcNDMB9tFWX9z73OMujqVToViThkJ+M5dne7Na2Mdd1mfdX757mF7WzeYUm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A0q64Eo6zvYj8r4 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. Reviewed-by: Zi Yan 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 d97f7cd137e63..0898ddd2f661f 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