mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shivank Garg <shivankg@amd.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	"Byungchul Park" <byungchul@sk.com>,
	Gregory Price <gourry@gourry.net>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Alistair Popple <apopple@nvidia.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Yiannis Nikolakopoulos <yiannis@zptcorp.com>,
	"Bharata B Rao" <bharata@amd.com>,
	David Rientjes <rientjes@google.com>,
	Huan Nguyen <nhuhuan@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	Hugh Dickins <hughd@google.com>,
	"Vlastimil Babka" <vbabka@kernel.org>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	Shivank Garg <shivankg@amd.com>
Subject: [PATCH v2 0/8] mm/migrate: separate hugetlb, movable_ops and LRU migration paths
Date: Thu, 19 Nov 2026 07:11:55 +0000	[thread overview]
Message-ID: <20261119-migrate-refactor-shivank-v2-0-f4535bd0bc52@amd.com> (raw)

migrate_pages() handles hugetlb folios, movable_ops pages and LRU folios,
although their locking, mapping and retry requirements differ. It already
dispatches hugetlb folios to a dedicated engine, but that engine rescans
the whole source list on every retry pass, movable_ops pages still pass
through the regular folio unmap and move machinery, and the LRU batching,
synchronous fallback and split folio retry are open-coded in
migrate_pages() itself.

This series sorts the source list by migration class once, gives each
class its own entry point, and splits the LRU batch engine into explicit
unmap, TLB flush, move and undo phases.

Thanks to Zi Yan and David Hildenbrand for the discussions and suggestions
that helped shape this series. I also used LLM tools to refine my ideas,
identify the edge-cases/bugs.

Old flow
========

migrate_pages(mode, reason)
  |
  +-- migrate_hugetlbs()
  |     `-- scan the mixed source list (from) on each retry
  |
  `-- split the remaining list into batches
        |
        +-- MIGRATE_ASYNC
        |     `-- migrate_pages_batch()
        |           inline unmap/retry -> flush -> move/retry
        |
        `-- MIGRATE_SYNC[_LIGHT]
              `-- migrate_pages_sync()
                   +-- try async batch pre-pass
                   `-- retry failures one at a time through
                       migrate_pages_batch()

movable_ops pages are identified by branches inside the batch unmap and
move paths.

New flow
========

migrate_pages(mode, reason)
  |
  +-- sort the source list into hugetlb, movable_ops and LRU lists
  |
  +-- migrate_hugetlbs()
  |     `-- retry each hugetlb folio
  |
  +-- migrate_movable_ops_pages()
  |     `-- allocate, lock, invoke the movable_ops callback and retry
  |
  `-- migrate_lru_folios()
        `-- form bounded LRU batches
              `-- __migrate_lru_folios()
                    +-- async: migrate_folios_batch()
                    +-- sync:
                    |   +-- async batch pre-pass
                    |   `-- retry failures one at a time
                    `-- one async attempt for folios split on the way

migrate_folios_batch()
  |
  +-- migrate_folios_unmap()
  +-- try_to_unmap_flush()
  +-- migrate_folios_move()
  `-- migrate_folios_undo()

migrate_pages() now only sorts and dispatches classes. Each entry point
owns its retries; the LRU entry point also owns batching, the synchronous
fallback and the split folio retry. Folios that are not migrated are still
returned through the original source list.

Motivation
==========

This refactor makes the migration control flow easier to follow and gives
new optimizations clear boundaries and insertion points.

Separating movable_ops also prepares for memdescs, where these pages are
expected to lose their folio representation and folio->lru handoff. The
current list interface remains, but its folio dependencies are now isolated.

As a side benefit, a folio's class is tested once when the source
list is sorted, instead of in every unmap, move and retry pass, and
retrying a hugetlb folio no longer rescans the whole source list.

Behavior Changes
================

No functional change is intended for the LRU and hugetlb migration paths.

The movable_ops pass has three intentional differences:

  - movable_ops pages are attempted before LRU folios;
  - movable_ops pages no longer use the LRU asynchronous pre-pass;
    synchronous callers use their requested mode from the first attempt;
  - a movable_ops callback returning -EAGAIN drops both page locks and
    releases the destination, so a retry allocates a new one.

---
Changes in v2:
- Rebase onto mm-core/for-next.
- Drop the migrate_control patches, will post as a separate
  series; and this series is limited to mm/migrate.c.
- migrate_pages() now sorts hugetlb folios and movable_ops pages onto
  their own lists in a single pass, instead of migrate_hugetlbs() and
  migrate_movable_ops_pages() each scanning the source list.
- movable_ops: count permanent failures in nr_failed_pages as they happen,
  mirroring migrate_hugetlbs(); the totals are unchanged.
- Avoid the migrate_lru_folios() -> __migrate_lru_folios() rename
  by introducing the per-batch function under its final name.
- Some rewording of comments and commit text.
- Link to v1: https://lore.kernel.org/r/20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com

---
Shivank Garg (8):
      mm/migrate: extract folio unmap phase
      mm/migrate: handle retries in migrate_folios_move()
      mm/migrate: factor out folio splitting on allocation failure
      mm/migrate: use a dedicated list for hugetlb folios
      mm/migrate: add a dedicated movable_ops migration pass
      mm/migrate: rename migrate_pages_batch() to migrate_folios_batch()
      mm/migrate: fold the LRU batch paths into __migrate_lru_folios()
      mm/migrate: add migrate_lru_folios() entry point

 mm/migrate.c | 561 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 378 insertions(+), 183 deletions(-)
---
base-commit: f7d95bf74091373fad7273db4557df9b5a902335
change-id: 20260824-migrate-refactor-shivank-4ee3949fcdcb

Best regards,
-- 
Shivank Garg <shivankg@amd.com>


             reply	other threads:[~2026-11-19  7:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:11 Shivank Garg [this message]
2026-11-19  7:11 ` [PATCH v2 1/8] mm/migrate: extract folio unmap phase Shivank Garg
2026-11-19  7:11 ` [PATCH v2 2/8] mm/migrate: handle retries in migrate_folios_move() Shivank Garg
2026-11-19  7:11 ` [PATCH v2 3/8] mm/migrate: factor out folio splitting on allocation failure Shivank Garg
2026-11-19  7:11 ` [PATCH v2 4/8] mm/migrate: use a dedicated list for hugetlb folios Shivank Garg
2026-11-19  7:12 ` [PATCH v2 5/8] mm/migrate: add a dedicated movable_ops migration pass Shivank Garg
2026-11-19  7:12 ` [PATCH v2 6/8] mm/migrate: rename migrate_pages_batch() to migrate_folios_batch() Shivank Garg
2026-11-19  7:12 ` [PATCH v2 7/8] mm/migrate: fold the LRU batch paths into __migrate_lru_folios() Shivank Garg
2026-11-19  7:12 ` [PATCH v2 8/8] mm/migrate: add migrate_lru_folios() entry point Shivank Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-migrate-refactor-shivank-v2-0-f4535bd0bc52@amd.com \
    --to=shivankg@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bharata@amd.com \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=hughd@google.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=muchun.song@linux.dev \
    --cc=nhuhuan@google.com \
    --cc=osalvador@suse.de \
    --cc=rientjes@google.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=yiannis@zptcorp.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®