Skip to content

RFC migration: Support hugetlb doublemaps

Peter Xu qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest21 patches 47 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21update linux headersinclude/standard-headers/drm/drm_fourcc.h include/standard-headers/linux/ethtool.h include/standard-headers/linux/fuse.h +15 more+526 -560 replies
2/21util: Include osdep.h first in util/mmap-alloc.cutil/mmap-alloc.c+1 -13 replies
3/21physmem: Add qemu_ram_is_hugetlb()include/exec/cpu-common.h softmmu/physmem.c+6 -02 replies
4/21madvise: Include linux/mman.h under linux-headers/include/qemu/madvise.h+4 -02 replies
5/21madvise: Add QEMU_MADV_SPLITinclude/qemu/madvise.h+7 -01 reply
6/21madvise: Add QEMU_MADV_COLLAPSEinclude/qemu/madvise.h+7 -03 replies
7/21ramblock: Cache file offset for file-backed ramblocksinclude/exec/ramblock.h softmmu/physmem.c+7 -01 reply
8/21ramblock: Cache the length to do file mmap() on ramblocksinclude/exec/ramblock.h softmmu/physmem.c+9 -74 replies
9/21ramblock: Add RAM_READONLYbackends/hostmem-file.c include/exec/memory.h include/exec/ram_addr.h +2 more+16 -202 replies
10/21ramblock: Add ramblock_file_map()include/exec/ram_addr.h softmmu/physmem.c+18 -85 replies
11/21migration: Add hugetlb-doublemap capmigration/migration.c migration/migration.h qapi/migration.json+54 -23 replies
12/21migration: Introduce page size for-migration-onlymigration/migration.c migration/postcopy-ram.c migration/ram.c +1 more+36 -164 replies
13/21migration: Add migration_ram_pagesize_largest()include/exec/cpu-common.h migration/migration.c migration/ram.c +2 more+14 -152 replies
14/21migration: Map hugetlbfs ramblocks twice, and pre-allocateinclude/exec/ramblock.h migration/ram.c+66 -05 replies
15/21migration: Teach qemu about minor faults and doublemapmigration/postcopy-ram.c migration/postcopy-ram.h+81 -193 replies
16/21migration: Enable doublemap with MADV_SPLITmigration/postcopy-ram.c migration/ram.c+34 -01 reply
17/21migration: Rework ram discard logic for hugetlb double-mapinclude/exec/cpu-common.h migration/ram.c migration/trace-events +1 more+48 -11 reply
18/21migration: Allow postcopy_register_shared_ufd() to failhw/virtio/vhost-user.c migration/postcopy-ram.c migration/postcopy-ram.h+17 -51 reply
19/21migration: Add postcopy_mark_received()migration/postcopy-ram.c+21 -141 reply
20/21migration: Handle page faults using UFFDIO_CONTINUEmigration/postcopy-ram.c migration/trace-events+55 -42 replies
21/21migration: Collapse huge pages again after postcopy finishedmigration/ram.c migration/trace-events+32 -01 reply

Reviews trailers per patch

18 of 21 patches have a Reviewed-by or Acked-by.

PatchDr. David Alan GilbertPhilippe Mathieu-DaudéJuan Quintela
1/21
2/21R-b R-b R-b
3/21R-b R-b
4/21R-b R-b
5/21R-b
6/21R-b
7/21R-b
8/21R-b R-b
9/21R-b R-b
10/21R-b R-b
11/21R-b R-b
12/21R-b
13/21R-b R-b
14/21R-b R-b
15/21R-b
16/21R-b
17/21R-b
18/21R-b
19/21R-b
20/21
21/21

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH RFC 00/21] migration: Support hugetlb doublemaps

Based-on: <[email protected]>
[PATCH 0/5] migration: Fix disorder of channel creations

Trees for reference:
https://github.com/xzpeter/linux/releases/tag/doublemap-v0.1
https://github.com/xzpeter/qemu/releases/tag/doublemap-v0.1

This is an RFC series that only for early discussion purpose but not for merging.

This patchset allows postcopy to work with huge pages better by migrating huge pages in small page sizes. It relies on a kernel feature called "hugetlb HGM" which is currently proposed on the Linux kernel mailing list by James Houghton, latest version v1:

https://lore.kernel.org/r/[email protected]

[PS: The kernel v1 patchset may need a few fixups to make QEMU work, which
are all contained in the tree link provided tagged doublemap-v0.1 above]

The kernel series is still during review upstream, so the API is still not stable.

I kept the old name of "doublemap" in this QEMU patchset to represent HGM. With that, huge pages can be mapped with even smaller sizes than the huge page itself. It can drastically reduce page fault latencies during postcopy if the guest has hugepage backed memories and make postcopy start working with huge pages. The average page request latency can drop from ~1sec to ~250us for 1G backed in the initial test results.

UFFDIO_COPY doesn't support mapping huge pages in small sizes, so one major part of this series introduced UFFDIO_CONTINUE to resolve page faults for hugetlb mappings.

Sampled page latency histogram for 18G guest with/without doublemap (preempt=on, single thread busy spin workload over 18G map):

Before:

@delay_us:

[64, 128)              3 |@                                                   |
[128, 256)            84 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[256, 512)            10 |@@@@@@                                              |
[512, 1K)              1 |                                                    |
[1K, 2K)               0 |                                                    |
[2K, 4K)               0 |                                                    |
[4K, 8K)               0 |                                                    |
[8K, 16K)              0 |                                                    |
[16K, 32K)             0 |                                                    |
[32K, 64K)             0 |                                                    |
[64K, 128K)            0 |                                                    |
[128K, 256K)           0 |                                                    |
[256K, 512K)           0 |                                                    |
[512K, 1M)             0 |                                                    |
[1M, 2M)              17 |@@@@@@@@@@                                          |
[2M, 4M)              21 |@@@@@@@@@@@@@                                       |
[4M, 8M)               8 |@@@@                                                |
[8M, 16M)              4 |@@                                                  |

After:

@delay_us:

[16, 32)               6 |                                                    |
[32, 64)               6 |                                                    |
[64, 128)           3117 |@@                                                  |
[128, 256)         70815 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[256, 512)         30460 |@@@@@@@@@@@@@@@@@@@@@@                              |
[512, 1K)           1135 |                                                    |
[1K, 2K)              34 |                                                    |
[2K, 4K)              42 |                                                    |
[4K, 8K)             126 |                                                    |
[8K, 16K)             91 |                                                    |
[16K, 32K)             0 |                                                    |
[32K, 64K)             1 |                                                    |

Any early comment welcomed. Thanks.

Peter Xu (21):
update linux headers
util: Include osdep.h first in util/mmap-alloc.c
physmem: Add qemu_ram_is_hugetlb()
madvise: Include linux/mman.h under linux-headers/
madvise: Add QEMU_MADV_SPLIT
madvise: Add QEMU_MADV_COLLAPSE
ramblock: Cache file offset for file-backed ramblocks
ramblock: Cache the length to do file mmap() on ramblocks
ramblock: Add RAM_READONLY
ramblock: Add ramblock_file_map()
migration: Add hugetlb-doublemap cap
migration: Introduce page size for-migration-only
migration: Add migration_ram_pagesize_largest()
migration: Map hugetlbfs ramblocks twice, and pre-allocate
migration: Teach qemu about minor faults and doublemap
migration: Enable doublemap with MADV_SPLIT
migration: Rework ram discard logic for hugetlb double-map
migration: Allow postcopy_register_shared_ufd() to fail
migration: Add postcopy_mark_received()
migration: Handle page faults using UFFDIO_CONTINUE
migration: Collapse huge pages again after postcopy finished

 backends/hostmem-file.c                       |   3 +-
 hw/virtio/vhost-user.c                        |   9 +-
 include/exec/cpu-common.h                     |   3 +-
 include/exec/memory.h                         |   4 +-
 include/exec/ram_addr.h                       |   6 +-
 include/exec/ramblock.h                       |  14 +
 include/qemu/madvise.h                        |  18 ++
 include/standard-headers/drm/drm_fourcc.h     |  63 +++-
 include/standard-headers/linux/ethtool.h      |  81 ++++-
 include/standard-headers/linux/fuse.h         |  20 +-
 .../linux/input-event-codes.h                 |   4 +
 include/standard-headers/linux/pci_regs.h     |   2 +
 include/standard-headers/linux/virtio_blk.h   |  19 ++
 include/standard-headers/linux/virtio_bt.h    |   8 +
 include/standard-headers/linux/virtio_net.h   |   4 +
 linux-headers/asm-arm64/kvm.h                 |   1 +
 linux-headers/asm-generic/hugetlb_encode.h    |  26 +-
 linux-headers/asm-generic/mman-common.h       |   4 +
 linux-headers/asm-mips/mman.h                 |   4 +
 linux-headers/asm-riscv/kvm.h                 |   7 +
 linux-headers/asm-x86/kvm.h                   |  11 +-
 linux-headers/linux/kvm.h                     |  32 +-
 linux-headers/linux/psci.h                    |  14 +
 linux-headers/linux/userfaultfd.h             |   4 +
 linux-headers/linux/vfio.h                    | 278 +++++++++++++++++-
 migration/migration.c                         |  56 +++-
 migration/migration.h                         |   1 +
 migration/postcopy-ram.c                      | 228 +++++++++++---
 migration/postcopy-ram.h                      |   5 +-
 migration/ram.c                               | 165 ++++++++++-
 migration/ram.h                               |   2 +
 migration/trace-events                        |   6 +-
 qapi/migration.json                           |   7 +-
 softmmu/memory.c                              |   8 +-
 softmmu/physmem.c                             |  92 ++++--
 util/mmap-alloc.c                             |   2 +-
 36 files changed, 1051 insertions(+), 160 deletions(-)
Signature · 1 line
2.37.3