From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796134758; b=GWrV4BhzNC8OzM6bD8mGKQDku1Lnn4qMzgaN9uO5PDqYpm2u2np5E5c4diotvCVutsu4 9Re+XAYSaHYxR+nf9/BT33LWWqa3xJ99UG+ASHtsFlY9syoNdLBOfUrEI5FUh6VFpO+WW Z33uuHTmNclOaWSC2LJ33xhW4VxfJYLV6Lbc7n+bTvxnawqYEebqwqBkaRzVWTz623IVC bEd1IryrGriUplgEyVReMOoI1IsAoTCp6wK2M2cQve8BzdVorQwz96C4DqLw1IWZk0Qyd 2dvU1JXrM08BGZ2rsUscY2P1ks8zgQfuERvJ3SpA5LvxQrYaJ6yAatNUU6HD5DQ+t2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796134758; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=udnZ+2SNbs0p0/j/8fuFlp03iX69v9FKQZkqYQ9vrqw=; b=fvSu2zC+eh6mBho7JqXpsi4OQdjKifIPBX1MfpQMge29G9FVdqsnHVz4nOEVo8jEcrc/ NIC1qMXAjKN8uADPxDlcFlZ05dfzrEkLCPvFwT6Lc39PXcOV7L3pb/fxbIrhlRH/QCKw+ Vt00iyX8v5N1zs7TPuSMOeNC7NOcSP2wqLJWbQUEI59c8ldyIzf8vS1LqPborWKwVP4O0 DT3jJfManz3488nw323P2q5k2kMJ8VgJB78UPwdUw1lSClPyNPIuMJaGKVU6ATJxV2cpR AvGeQHjjTxrAk6eOsD5oeCp4MSRJKYhi5jf2z4iSQDJOfrpVlvKB0T8gRxEZIe+8KUQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YRZKZTUn; arc=none smtp.remote-ip=198.175.65.18 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69972606A330; Tue, 1 Dec 2026 14:19:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69972606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YRZKZTUn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796134759; x=1827670759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=udnZ+2SNbs0p0/j/8fuFlp03iX69v9FKQZkqYQ9vrqw=; b=YRZKZTUngiB9ORjitDEXiU/7LhXqRuUZBkAAQWoUDbp7MIjxxk+TfTmU x1bX/gV8MUgnZHR5SWvWWX3peDMaYtOd2MlwTD4pAEQSVypspuHE36soN NEzyxX9t5NMFnweQwBYsvfHdyBmpiLXXbAgDGp4ghz4YvR9/dctjTAakx Fs3fKqDrqMrLMy1WU3LqpYiVP8nFg9pS969EzZ5TxYv7RVuEcLjUcG8hu 3xahnSbDSOrjpVdCEtw7y1VCE3fPPTJcpRFSIOku+QVmdQXfNj3MrG5KS nWYWhIYeh78QjetFjiLVxyHVZY6Em8M/Gp+T+o4Zezj6zI8WEiB9wa5li g==; X-CSE-ConnectionGUID: bgOtg7doQ0STNXOoCWX32A== X-CSE-MsgGUID: clxU3lMfSy6lsIoMY8iCTg== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5019194" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="5019194" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 06:19:16 -0800 X-CSE-ConnectionGUID: VJbEb4bvRbqiqufBiVb3zw== X-CSE-MsgGUID: Cqf6Gxu0Q/uGRaipGPFyRw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13380685" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by fmviesa005.fm.intel.com with ESMTP; 01 Dec 2026 06:19:14 -0800 From: Daniel Byrne To: Shivank Garg , Ravi Jonnalagadda Cc: Andrew Morton , David Hildenbrand , 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 , Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , Yiannis Nikolakopoulos , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , "Aneesh Kumar K.V" , Nathan Lynch , Frank Li , Dan Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Day , dmaengine@vger.kernel.org, Vinicius Costa Gomes , Frank Li , Dave Jiang , Daniel Byrne Subject: [RFC PATCH 01/10] mm/migrate: skip data copy for already-copied folios Date: Tue, 1 Dec 2026 06:12:50 -0800 Message-ID: <20261201141259.2124188-2-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201141259.2124188-1-daniel1.byrne@intel.com> References: <20261201141259.2124188-1-daniel1.byrne@intel.com> X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Shivank Garg Add FOLIO_CONTENT_COPIED marker to the dst->migrate_info migration state. When set, it tells __migrate_folio() to skip folio_mc_copy() and perform metadata-only migration. This bit is not set yet, the batch-copy path enables it later in a subsequent patch. Update __migrate_folio_extract() to preserve FOLIO_CONTENT_COPIED while it consumes old states of src folio. Move the dst->migrate_info state enum to migrate.h header file so offload drivers can see FOLIO_CONTENT_COPIED. On 32Bit, we do not have spare bit to store FOLIO_CONTENT_COPIED info, migration copy offload is disabled for them. Signed-off-by: Shivank Garg [daniel: rebased to v7.4-rc2] Signed-off-by: Daniel Byrne --- Patch 1/5 of RFC v6, rebased to v7.4-rc2. No other change. It is here so that the series applies. include/linux/migrate.h | 25 +++++++++++++++++++++++++ mm/migrate.c | 29 +++++++++++++---------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 78424b3824c2..28b471dfae23 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -73,6 +73,31 @@ int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); int set_movable_ops(const struct movable_operations *ops, enum pagetype type); +/* + * To record some information during migration, we use the migrate_info + * field of struct folio of the newly allocated destination folio, + * together with the anon_vma pointer. The state is encoded in the + * unused low bits of the pointer. + * This is safe because nobody is using it except us. + * + * FOLIO_WAS_MAPPED and FOLIO_WAS_MLOCKED record the src folios's state + * at unmap time and are consumed during the move/undo phase. + * FOLIO_CONTENT_COPIED tells __migrate_folio() that the folio contents + * have already been copied, so the per-folio copy can be skipped. A + * driver must set this bit on each dst folio it copied. + */ +enum { + FOLIO_WAS_MAPPED = BIT(0), + FOLIO_WAS_MLOCKED = BIT(1), + FOLIO_OLD_STATES = FOLIO_WAS_MAPPED | FOLIO_WAS_MLOCKED, +#ifdef CONFIG_64BIT + FOLIO_CONTENT_COPIED = BIT(2), +#else + /* On 32bit we do not have a spare bit, migration-copy offload is disabled. */ + FOLIO_CONTENT_COPIED = 0, +#endif +}; + #else static inline void putback_movable_pages(struct list_head *l) {} diff --git a/mm/migrate.c b/mm/migrate.c index 875079464930..ca52cd32e25e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -871,14 +871,21 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, enum migrate_mode mode) { int rc, expected_count = folio_expected_ref_count(src) + 1; + const bool already_copied = dst->migrate_info & FOLIO_CONTENT_COPIED; + + /* Consume the content copied marker */ + if (already_copied) + dst->migrate_info &= ~FOLIO_CONTENT_COPIED; /* Check whether src does not have extra refs before we do more work */ if (folio_ref_count(src) != expected_count) return -EAGAIN; - rc = folio_mc_copy(dst, src); - if (unlikely(rc)) - return rc; + if (!already_copied) { + rc = folio_mc_copy(dst, src); + if (unlikely(rc)) + return rc; + } rc = __folio_migrate_mapping(mapping, dst, src, expected_count); if (rc) @@ -1141,17 +1148,6 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, return rc; } -/* - * To record some information during migration, we use the migrate_info - * field of struct folio of the newly allocated destination folio. - * This is safe because nobody is using it except us. - */ -enum { - FOLIO_WAS_MAPPED = BIT(0), - FOLIO_WAS_MLOCKED = BIT(1), - FOLIO_OLD_STATES = FOLIO_WAS_MAPPED | FOLIO_WAS_MLOCKED, -}; - static void __migrate_folio_record(struct folio *dst, int old_folio_state, struct anon_vma *anon_vma) { @@ -1163,9 +1159,10 @@ static void __migrate_folio_extract(struct folio *dst, { unsigned long info = dst->migrate_info; - *anon_vmap = (struct anon_vma *)(info & ~FOLIO_OLD_STATES); + *anon_vmap = (struct anon_vma *)(info & ~(FOLIO_OLD_STATES | + FOLIO_CONTENT_COPIED)); *old_folio_state = info & FOLIO_OLD_STATES; - dst->migrate_info = 0; + dst->migrate_info &= FOLIO_CONTENT_COPIED; } /* Restore the source folio to the original state upon failure */ -- 2.43.0