mapped-ram.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Mapped-ram
  2. ==========
  3. Mapped-ram is a new stream format for the RAM section designed to
  4. supplement the existing ``file:`` migration and make it compatible
  5. with ``multifd``. This enables parallel migration of a guest's RAM to
  6. a file.
  7. The core of the feature is to ensure that RAM pages are mapped
  8. directly to offsets in the resulting migration file. This enables the
  9. ``multifd`` threads to write exclusively to those offsets even if the
  10. guest is constantly dirtying pages (i.e. live migration). Another
  11. benefit is that the resulting file will have a bounded size, since
  12. pages which are dirtied multiple times will always go to a fixed
  13. location in the file, rather than constantly being added to a
  14. sequential stream. Having the pages at fixed offsets also allows the
  15. usage of O_DIRECT for save/restore of the migration stream as the
  16. pages are ensured to be written respecting O_DIRECT alignment
  17. restrictions.
  18. Usage
  19. -----
  20. On both source and destination, enable the ``multifd`` and
  21. ``mapped-ram`` capabilities:
  22. ``migrate_set_capability multifd on``
  23. ``migrate_set_capability mapped-ram on``
  24. Use a ``file:`` URL for migration:
  25. ``migrate file:/path/to/migration/file``
  26. Mapped-ram migration is best done non-live, i.e. by stopping the VM on
  27. the source side before migrating.
  28. For best performance enable the ``direct-io`` parameter as well:
  29. ``migrate_set_parameter direct-io on``
  30. Use-cases
  31. ---------
  32. The mapped-ram feature was designed for use cases where the migration
  33. stream will be directed to a file in the filesystem and not
  34. immediately restored on the destination VM\ [#alternatives]_. These could be
  35. thought of as snapshots. We can further categorize them into live and
  36. non-live.
  37. - Non-live snapshot
  38. If the use case requires a VM to be stopped before taking a snapshot,
  39. that's the ideal scenario for mapped-ram migration. Not having to
  40. track dirty pages, the migration will write the RAM pages to the disk
  41. as fast as it can.
  42. Note: if a snapshot is taken of a running VM, but the VM will be
  43. stopped after the snapshot by the admin, then consider stopping it
  44. right before the snapshot to take benefit of the performance gains
  45. mentioned above.
  46. - Live snapshot
  47. If the use case requires that the VM keeps running during and after
  48. the snapshot operation, then mapped-ram migration can still be used,
  49. but will be less performant. Other strategies such as
  50. background-snapshot should be evaluated as well. One benefit of
  51. mapped-ram in this scenario is portability since background-snapshot
  52. depends on async dirty tracking (KVM_GET_DIRTY_LOG) which is not
  53. supported outside of Linux.
  54. .. [#alternatives] While this same effect could be obtained with the usage of
  55. snapshots or the ``file:`` migration alone, mapped-ram provides
  56. a performance increase for VMs with larger RAM sizes (10s to
  57. 100s of GiBs), specially if the VM has been stopped beforehand.
  58. RAM section format
  59. ------------------
  60. Instead of having a sequential stream of pages that follow the
  61. RAMBlock headers, the dirty pages for a RAMBlock follow its header
  62. instead. This ensures that each RAM page has a fixed offset in the
  63. resulting migration file.
  64. A bitmap is introduced to track which pages have been written in the
  65. migration file. Pages are written at a fixed location for every
  66. ramblock. Zero pages are ignored as they'd be zero in the destination
  67. migration as well.
  68. ::
  69. Without mapped-ram: With mapped-ram:
  70. --------------------- --------------------------------
  71. | ramblock 1 header | | ramblock 1 header |
  72. --------------------- --------------------------------
  73. | ramblock 2 header | | ramblock 1 mapped-ram header |
  74. --------------------- --------------------------------
  75. | ... | | padding to next 1MB boundary |
  76. --------------------- | ... |
  77. | ramblock n header | --------------------------------
  78. --------------------- | ramblock 1 pages |
  79. | RAM_SAVE_FLAG_EOS | | ... |
  80. --------------------- --------------------------------
  81. | stream of pages | | ramblock 2 header |
  82. | (iter 1) | --------------------------------
  83. | ... | | ramblock 2 mapped-ram header |
  84. --------------------- --------------------------------
  85. | RAM_SAVE_FLAG_EOS | | padding to next 1MB boundary |
  86. --------------------- | ... |
  87. | stream of pages | --------------------------------
  88. | (iter 2) | | ramblock 2 pages |
  89. | ... | | ... |
  90. --------------------- --------------------------------
  91. | ... | | ... |
  92. --------------------- --------------------------------
  93. | RAM_SAVE_FLAG_EOS |
  94. --------------------------------
  95. | ... |
  96. --------------------------------
  97. where:
  98. - ramblock header: the generic information for a ramblock, such as
  99. idstr, used_len, etc.
  100. - ramblock mapped-ram header: the information added by this feature:
  101. bitmap of pages written, bitmap size and offset of pages in the
  102. migration file.
  103. Restrictions
  104. ------------
  105. Since pages are written to their relative offsets and out of order
  106. (due to the memory dirtying patterns), streaming channels such as
  107. sockets are not supported. A seekable channel such as a file is
  108. required. This can be verified in the QIOChannel by the presence of
  109. the QIO_CHANNEL_FEATURE_SEEKABLE.
  110. The improvements brought by this feature apply only to guest physical
  111. RAM. Other types of memory such as VRAM are migrated as part of device
  112. states.