Until now, memory provided by a single virtio-mem device was usually either onlined completely to ZONE_MOVABLE (online_movable) or to ZONE_NORMAL (online_kernel), so we didn't actually care about "what" we are unplugging; however, that will change in the future when we will have memory blocks in different zones within a single virtio-mem device. There are two reasons why we want to track to which zone a memory block belongs to and prioritize ZONE_MOVABLE blocks: 1) Memory managed by ZONE_MOVABLE can more likely get unplugged, therefore, resulting in a faster memory hotunplug process. Further, we can more reliably unplug and remove complete memory blocks, removing metadata allocated for the whole memory block. 2) We want to avoid corner cases where unplugging with the current scheme (highest to lowest address) could result in accidential zone imbalances, whereby we remove too much ZONE_NORMAL memory for ZONE_MOVABLE memory of the same device. This series unplugs ZONE_MOVABLE memory blocks first, before falling back to ZONE_NORMAL ones. Patch #1 is an unrelated fix, previously sent in other context that didn't get picked up yet. Patch #2-#4 and #6 are cleanups. Patch #5 and #7 implement ZONE_MOVABLE aware handling in Sub Block Mode and Big Block Mode respectively. Cc: "Michael S. Tsirkin" <mst@xxxxxxxxxx> Cc: Jason Wang <jasowang@xxxxxxxxxx> Cc: Marek Kedzierski <mkedzier@xxxxxxxxxx> Cc: Hui Zhu <teawater@xxxxxxxxx> Cc: Pankaj Gupta <pankaj.gupta.linux@xxxxxxxxx> Cc: Wei Yang <richard.weiyang@xxxxxxxxxxxxxxxxx> Cc: Oscar Salvador <osalvador@xxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx Cc: linux-mm@xxxxxxxxx David Hildenbrand (7): virtio-mem: don't read big block size in Sub Block Mode virtio-mem: use page_zonenum() in virtio_mem_fake_offline() virtio-mem: simplify high-level plug handling in Sub Block Mode virtio-mem: simplify high-level unplug handling in Sub Block Mode virtio-mem: prioritize unplug from ZONE_MOVABLE in Sub Block Mode virtio-mem: simplify high-level unplug handling in Big Block Mode virtio-mem: prioritize unplug from ZONE_MOVABLE in Big Block Mode drivers/virtio/virtio_mem.c | 338 +++++++++++++++++++----------------- 1 file changed, 174 insertions(+), 164 deletions(-) base-commit: 8124c8a6b35386f73523d27eacb71b5364a68c4c -- 2.31.1