linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] Make MIGRATE_ISOLATE a standalone bit
@ 2025-05-09 20:01 Zi Yan
  2025-05-09 20:01 ` [PATCH v4 1/4] mm/page_isolation: make page isolation " Zi Yan
                   ` (5 more replies)
  0 siblings, 6 replies; 42+ messages in thread
From: Zi Yan @ 2025-05-09 20:01 UTC (permalink / raw)
  To: David Hildenbrand, Oscar Salvador, Johannes Weiner, linux-mm
  Cc: Andrew Morton, Vlastimil Babka, Baolin Wang, Kirill A . Shutemov,
	Mel Gorman, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Richard Chang, linux-kernel, Zi Yan

Hi David and Oscar,

Can you take a look at Patch 2, which changes how online_pages() set
online pageblock migratetypes? It used to first set all pageblocks to
MIGRATE_ISOLATE, then let undo_isolate_page_range() move the pageblocks
to MIGRATE_MOVABLE. After MIGRATE_ISOLATE becomes a standalone bit, all
online pageblocks need to have a migratetype other than MIGRATE_ISOLATE.
Let me know if there is any issue with my changes.

Hi Johannes,

Patch 2 now have set_pageblock_migratetype() not accepting
MIGRATE_ISOLATE. I think it makes code better. Thank you for the great
feedback.

Hi all,

This patchset moves MIGRATE_ISOLATE to a standalone bit to avoid
being overwritten during pageblock isolation process. Currently,
MIGRATE_ISOLATE is part of enum migratetype (in include/linux/mmzone.h),
thus, setting a pageblock to MIGRATE_ISOLATE overwrites its original
migratetype. This causes pageblock migratetype loss during
alloc_contig_range() and memory offline, especially when the process
fails due to a failed pageblock isolation and the code tries to undo the
finished pageblock isolations.

It is on top of mm-everything-2025-05-09-01-57 with v3 reverted.

In terms of performance for changing pageblock types, no performance
change is observed:

1. I used perf to collect stats of offlining and onlining all memory of a
40GB VM 10 times and see that get_pfnblock_flags_mask() and
set_pfnblock_flags_mask() take about 0.12% and 0.02% of the whole process
respectively with and without this patchset across 3 runs.

2. I used perf to collect stats of dd from /dev/random to a 40GB tmpfs file
and find get_pfnblock_flags_mask() takes about 0.05% of the process with and
without this patchset across 3 runs.


Changelog
===
From v3[2]:
1. kept the original is_migrate_isolate_page()
2. moved {get,set,clear}_pageblock_isolate() to mm/page_isolation.c
3. used a single version for get_pageblock_migratetype() and
   get_pfnblock_migratetype().
4. replace get_pageblock_isolate() with
   get_pageblock_migratetype() == MIGRATE_ISOLATE, a
   get_pageblock_isolate() becomes private in mm/page_isolation.c
5. made set_pageblock_migratetype() not accept MIGRATE_ISOLATE, so that
   people need to use the dedicate {get,set,clear}_pageblock_isolate() APIs.
6. changed online_page() from mm/memory_hotplug.c to first set pageblock
   migratetype to MIGRATE_MOVABLE, then isolate pageblocks.
7. added __maybe_unused to get_pageblock_isolate(), since it is only
   used in VM_BUG_ON(), which could be not present when MM debug is off.
   It is reported by kernel test robot.
7. fixed test_pages_isolated() type issues reported by kernel test
   robot.

From v2[1]:
1. Moved MIGRATETYPE_NO_ISO_MASK to Patch 2, where it is used.
2. Removed spurious changes in Patch 1.
3. Refactored code so that migratetype mask is passed properly for all
callers to {get,set}_pfnblock_flags_mask().
4. Added toggle_pageblock_isolate() for setting and clearing
MIGRATE_ISOLATE.
5. Changed get_pageblock_migratetype() when CONFIG_MEMORY_ISOLATION to
handle MIGRATE_ISOLATE case. It acts like a parsing layer for
get_pfnblock_flags_mask().


Design
===

Pageblock flags are read in words to achieve good performance and existing
pageblock flags take 4 bits per pageblock. To avoid a substantial change
to the pageblock flag code, pageblock flag bits are expanded to use 8
and MIGRATE_ISOLATE is moved to use the last bit (bit 7).

It might look like the pageblock flags have doubled the overhead, but in
reality, the overhead is only 1 byte per 2MB/4MB (based on pageblock config),
or 0.0000476 %.

Any comment and/or suggestion is welcome. Thanks.

[1] https://lore.kernel.org/linux-mm/20250214154215.717537-1-ziy@nvidia.com/
[2] https://lore.kernel.org/linux-mm/20250507211059.2211628-2-ziy@nvidia.com/


Zi Yan (4):
  mm/page_isolation: make page isolation a standalone bit.
  mm/page_isolation: remove migratetype from
    move_freepages_block_isolate()
  mm/page_isolation: remove migratetype from undo_isolate_page_range()
  mm/page_isolation: remove migratetype parameter from more functions.

 drivers/virtio/virtio_mem.c     |   3 +-
 include/linux/gfp.h             |   6 +-
 include/linux/mmzone.h          |  17 +++--
 include/linux/page-isolation.h  |  33 +++++++--
 include/linux/pageblock-flags.h |   9 ++-
 include/trace/events/kmem.h     |  14 ++--
 mm/cma.c                        |   2 +-
 mm/memory_hotplug.c             |  14 ++--
 mm/page_alloc.c                 | 126 ++++++++++++++++++++++++--------
 mm/page_isolation.c             | 114 +++++++++++++++--------------
 10 files changed, 226 insertions(+), 112 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2025-05-21 12:18 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09 20:01 [PATCH v4 0/4] Make MIGRATE_ISOLATE a standalone bit Zi Yan
2025-05-09 20:01 ` [PATCH v4 1/4] mm/page_isolation: make page isolation " Zi Yan
2025-05-13 11:32   ` Brendan Jackman
2025-05-13 14:53     ` Zi Yan
2025-05-19  8:08   ` David Hildenbrand
2025-05-19 15:08     ` Zi Yan
2025-05-19 16:42       ` David Hildenbrand
2025-05-19 17:15         ` Zi Yan
2025-05-21 11:16         ` Zi Yan
2025-05-21 11:57           ` David Hildenbrand
2025-05-21 12:00             ` Zi Yan
2025-05-21 12:11               ` David Hildenbrand
2025-05-21 12:18                 ` Zi Yan
2025-05-09 20:01 ` [PATCH v4 2/4] mm/page_isolation: remove migratetype from move_freepages_block_isolate() Zi Yan
2025-05-12  6:25   ` kernel test robot
2025-05-12 16:10   ` Lorenzo Stoakes
2025-05-12 16:13     ` Zi Yan
2025-05-12 16:19       ` Lorenzo Stoakes
2025-05-12 16:28         ` Zi Yan
2025-05-12 22:00     ` Andrew Morton
2025-05-12 23:20     ` Zi Yan
2025-05-19  8:21   ` David Hildenbrand
2025-05-19 23:06     ` Zi Yan
2025-05-20  8:58       ` David Hildenbrand
2025-05-09 20:01 ` [PATCH v4 3/4] mm/page_isolation: remove migratetype from undo_isolate_page_range() Zi Yan
2025-05-09 20:01 ` [PATCH v4 4/4] mm/page_isolation: remove migratetype parameter from more functions Zi Yan
2025-05-17 20:21   ` Vlastimil Babka
2025-05-18  0:07     ` Zi Yan
2025-05-18 16:32   ` Johannes Weiner
2025-05-18 17:24     ` Zi Yan
2025-05-17 20:26 ` [PATCH v4 0/4] Make MIGRATE_ISOLATE a standalone bit Vlastimil Babka
2025-05-18  0:20   ` Zi Yan
2025-05-19 14:15     ` David Hildenbrand
2025-05-19 14:35       ` Zi Yan
2025-05-20  8:58         ` David Hildenbrand
2025-05-20 13:18           ` Zi Yan
2025-05-20 13:20             ` David Hildenbrand
2025-05-20 13:31               ` Zi Yan
2025-05-20 13:33                 ` David Hildenbrand
2025-05-20 14:07                   ` Zi Yan
2025-05-19  7:44 ` David Hildenbrand
2025-05-19 14:01   ` Zi Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).