Split migration bitmaps by ramblock
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
Why?
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
reason 2:
In case where the host page is a multiple of the the TARGET_PAGE_SIZE, we do a lot of work when we are synchronizing the bitmaps to pass it to target page size. The idea is to change the bitmaps on that RAMBlocks to mean host page size and not TARGET_PAGE_SIZE.
Note that there are two reason for this, ARM and PPC do things like guests with 4kb pages on hosts with 16/64kb hosts, and then we have HugePages. Note all the workarounds that postcopy has to do because to work in HugePages size.
Please, comment?
Later, Juan.
Juan Quintela (1):
ram: Split dirty bitmap by RAMBlock
include/exec/ram_addr.h | 13 +++- migration/ram.c | 201 ++++++++++++++++++------------------------------ 2 files changed, 85 insertions(+), 129 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/1 ram: Split dirty bitmap by RAMBlock
Both the ram bitmap and the unsent bitmap are split by RAMBlock.
--- include/exec/ram_addr.h | 13 +++- migration/ram.c | 201 ++++++++++++++++++------------------------------ 2 files changed, 85 insertions(+), 129 deletions(-)
include/exec/ram_addr.h +10 -3
@@ -39,6 +39,14 @@ struct RAMBlock { QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers;int fd;size_t page_size; +/* dirty bitmap used during migration */ +unsigned long *bmap; +/* bitmap of pages that haven't been sent even once +* only maintained and used in postcopy at the moment +* where it's used to send the dirtymap at the start +* of the postcopy phase +*/ +unsigned long *unsentmap; };static inline bool offset_in_ramblock (RAMBlock *b,ram_addr_t offset)
@@ -353,16 +361,15 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,static inline -uint64_t cpu_physical_memory_sync_dirty_bitmap (unsigned long *dest, -RAMBlock *rb, +uint64_t cpu_physical_memory_sync_dirty_bitmap (RAMBlock *rb,ram_addr_t start,ram_addr_t length,int64_t *real_dirty_pages) {ram_addr_t addr; - start = rb->offset + start;unsigned long page =BIT_WORD (start >>TARGET_PAGE_BITS );uint64_t num_dirty =0 ; +unsigned long *dest = rb->bmap;/* start address is aligned at the start of a word? */ if (((page *BITS_PER_LONG ) <<TARGET_PAGE_BITS ) == start) {
migration/ram.c +75 -126
370 lines not on this page · raw message
Signature · 1 line
2.9.3
Hi Juan,
First of all, I like the refactor patchset about RAMState, it makes
things clean, great!
Quoted 8 lines · Juan Quintela
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
Why?
Quoted 8 lines
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
Here you said 'synchonize the bitmap before sending the pages', do you mean synchronize the bitmap from kvm? If so, I doubt the performance... because every synchronization will require a ioctl(). If not, the synchronization of per block is useless.
Currently, migration thread will synchronize the bitmap from kvm every iter(migration_bitmap_sync()). The RAMBlock already has kind of per block bitmap for this kind of sync. And the migration bitmap is used to put all those per block bitmap together for data sending use.
Quoted 24 lines
reason 2:
In case where the host page is a multiple of the the
TARGET_PAGE_SIZE, we do a lot of work when we are synchronizing the bitmaps to pass it to target page size. The idea is to change the bitmaps on that RAMBlocks to mean host page size and notTARGET_PAGE_SIZE.Note that there are two reason for this, ARM and PPC do things like guests with 4kb pages on hosts with 16/64kb hosts, and then we have HugePages. Note all the workarounds that postcopy has to do because to work in HugePages size.
Please, comment?
Later, Juan.
Juan Quintela (1):
ram: Split dirty bitmap by RAMBlockinclude/exec/ram_addr.h | 13 +++- migration/ram.c | 201 ++++++++++++++++++------------------------------ 2 files changed, 85 insertions(+), 129 deletions(-)
Signature · 2 lines
Thanks, Yang
Quoted 4 lines · Yang Hongyang
Hi Juan,
First of all, I like the refactor patchset about RAMState, it makes
things clean, great!
Thanks.
The whole idea of the series was to make testing changes easier.
Quoted 23 lines · Juan Quintela
Quoted 8 lines
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
Why?
Quoted 8 lines
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
Here you said 'synchonize the bitmap before sending the pages', do you mean synchronize the bitmap from kvm? If so, I doubt the performance... because every synchronization will require a
ioctl(). If not, the synchronization of per block is useless.
Quoted 4 lines
Currently, migration thread will synchronize the bitmap from kvm every iter(migration_bitmap_sync()). The RAMBlock already has kind of per block bitmap for this kind of sync. And the migration bitmap is used to put all those per block bitmap together for data sending use.
Hi
For huge memory machines, we are doing it always in one go.
bitmap_sync(1TB RAM)
walk bitmap for 512MB of RAM, at that point, it is very probable that this page is again dirty in the KVM bitmap, so, we send it, but as it is dirty again, we would have to send it in the next pass. This sent is completely useless.
So my idea is to split things in smaller chunks. As we have to do an ioctl, we wouldn't want to synchronize page by page, but perhaps 16MB at a time, 64MB, anything less than the whole amount of memory.
Later, Juan.
Quoted 42 lines · Juan Quintela
Quoted 4 lines · Yang Hongyang
Hi Juan,
First of all, I like the refactor patchset about RAMState, it makes
things clean, great!Thanks.
The whole idea of the series was to make testing changes easier.
Quoted 23 lines · Juan Quintela
Quoted 8 lines
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
Why?
Quoted 8 lines
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
Here you said 'synchonize the bitmap before sending the pages', do you mean synchronize the bitmap from kvm? If so, I doubt the performance... because every synchronization will require a
ioctl(). If not, the synchronization of per block is useless.Quoted 4 lines
Currently, migration thread will synchronize the bitmap from kvm every iter(migration_bitmap_sync()). The RAMBlock already has kind of per block bitmap for this kind of sync. And the migration bitmap is used to put all those per block bitmap together for data sending use.
Hi
For huge memory machines, we are doing it always in one go.
Quoted 5 lines
bitmap_sync(1TB RAM)
walk bitmap for 512MB of RAM, at that point, it is very probable that this page is again dirty in the KVM bitmap, so, we send it, but as it is dirty again, we would have to send it in the next pass. This sent is completely useless.
I got your point, the problem is KVM do not have the ability to sync in small chunks currently, even it has, it will generate lots of ioctls:
KVM bitmap sync is per Memory Region IIRC, think we have a 1T mem guest, 16 MRs for example, currently, every iter we need to do 16 ioctls. But if we sync in small chunks, 64M for example, we might need to do 16384 ioctls in the worst case. eg:mem press(dirty rate) is very high.
Quoted 7 lines
So my idea is to split things in smaller chunks. As we have to do an ioctl, we wouldn't want to synchronize page by page, but perhaps 16MB at a time, 64MB, anything less than the whole amount of memory.
Later, Juan.
Signature · 2 lines
Thanks, Yang
Quoted 51 lines · * Yang Hongyang ([email protected]) wrote:
Quoted 42 lines · Juan Quintela
Quoted 4 lines · Yang Hongyang
Hi Juan,
First of all, I like the refactor patchset about RAMState, it makes
things clean, great!Thanks.
The whole idea of the series was to make testing changes easier.
Quoted 23 lines · Juan Quintela
Quoted 8 lines
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
Why?
Quoted 8 lines
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
Here you said 'synchonize the bitmap before sending the pages', do you mean synchronize the bitmap from kvm? If so, I doubt the performance... because every synchronization will require a
ioctl(). If not, the synchronization of per block is useless.Quoted 4 lines
Currently, migration thread will synchronize the bitmap from kvm every iter(migration_bitmap_sync()). The RAMBlock already has kind of per block bitmap for this kind of sync. And the migration bitmap is used to put all those per block bitmap together for data sending use.
Hi
For huge memory machines, we are doing it always in one go.Quoted 5 lines
bitmap_sync(1TB RAM)
walk bitmap for 512MB of RAM, at that point, it is very probable that this page is again dirty in the KVM bitmap, so, we send it, but as it is dirty again, we would have to send it in the next pass. This sent is completely useless.
Quoted 6 lines
I got your point, the problem is KVM do not have the ability to sync in small chunks currently, even it has, it will generate lots of ioctls:
KVM bitmap sync is per Memory Region IIRC, think we have a 1T mem guest, 16 MRs for example, currently, every iter we need to do 16 ioctls. But if we sync in small chunks, 64M for example, we might need to do 16384 ioctls in the worst case. eg:mem press(dirty rate) is very high.
Yes but I think people have suggested it should have that ability for a long time; so hopefully we can add it.
I'd assumed the sizes of these chunks would be a bit bigger, a few GB each maybe and also assumed we'd have a separate thread that was doing the syncing from a different thread to the one doing the writing, trying to keep ahead of the write pointer.
Even with the structure Juan has here, we could get to syncing each NUMA node separately like that which would kind of makes some sense.
Dave
Quoted 13 lines
Quoted 8 lines
So my idea is to split things in smaller chunks. As we have to do an ioctl, we wouldn't want to synchronize page by page, but perhaps 16MB at a time, 64MB, anything less than the whole amount of memory.
Later, Juan.
Signature · 2 lines
Thanks, Yang
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:
Hi
This series split the migration and unsent bitmaps by ramblock. This makes it easier to synchronize in small bits. This is on top of the RAMState and not-hotplug series.
So I think generally this is a good idea; my main reason is I'd like to see per-NUMA node syncing, preferably tied with multi-fd so that each of the NUMA nodes syncs and stuffs data over it's own NIC. Although we would still have to be careful about cases where one node is hammering it's RAM and the others are idleing.
Quoted 18 lines
Why?
reason 1:
People have complained that by the time that we detect that a page is sent, it has already been marked dirty "again" inside kvm, so we are going to send it again. On top of this patch, my idea is, for words of the bitmap that have any bit set, just synchonize the bitmap before sending the pages. I have not looking into performance numbers yet, jsut asking for comments about how it is done.
reason 2:
In case where the host page is a multiple of the the
TARGET_PAGE_SIZE, we do a lot of work when we are synchronizing the bitmaps to pass it to target page size. The idea is to change the bitmaps on that RAMBlocks to mean host page size and notTARGET_PAGE_SIZE.
Quoted 4 lines
Note that there are two reason for this, ARM and PPC do things like guests with 4kb pages on hosts with 16/64kb hosts, and then we have HugePages. Note all the workarounds that postcopy has to do because to work in HugePages size.
There are some fun problems with changing the bitmap page size; off the top of my head, the ones I can remember include:
a) I'm sure I've seen rare cases where a target page is marked as dirty inside a hostpage; I'm guessing that was qemu's doing, but there are more subtle cases, e.g. running a 4kb guest on a 64kb host; it's legal - and 4kb power guests used to exist; I think in those cases you see KVM only marking one target page as dirty.
b) Are we required to support migration across hosts of different pagesize; and if we do that what size should a bit represent?
People asked about it during postcopy but I think it's restricted to matching sizes. I don't think precopy has any requirement for matching host pagesize at the moment. 64bit ARM does 4k, 64k and I think 16k was added later.
c) Hugepages have similar issues; precopy doesn't currently have any requirement for the hugepage selection on the two hosts to match, but it does on postcopy. Also you don't want to have a single dirty bit for a 1GB host hugepage if you can handle detecting changes at a finer grain level.
Dave
Quoted 14 lines
Please, comment?
Later, Juan.
Juan Quintela (1):
ram: Split dirty bitmap by RAMBlockinclude/exec/ram_addr.h | 13 +++- migration/ram.c | 201 ++++++++++++++++++------------------------------ 2 files changed, 85 insertions(+), 129 deletions(-)Signature · 1 line
2.9.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:
Note that there are two reason for this, ARM and PPC do things like guests with 4kb pages on hosts with 16/64kb hosts, and then we have HugePages. Note all the workarounds that postcopy has to do because to work in HugePages size.
Quoted 7 lines
There are some fun problems with changing the bitmap page size; off the top of my head, the ones I can remember include:
a) I'm sure I've seen rare cases where a target page is marked as dirty inside a hostpage; I'm guessing that was qemu's doing, but there are more subtle cases, e.g. running a 4kb guest on a 64kb host; it's legal - and 4kb power guests used to exist; I think in those cases you see KVM only marking one target page as dirty.
/*
* bitmap-traveling is faster than memory-traveling (for addr...)
* especially when most of the memory is not dirty.
*/
for (i = 0; i < len; i++) {
if (bitmap[i] != 0) {
c = leul_to_cpu(bitmap[i]);
do {
j = ctzl(c);
c &= ~(1ul << j);
page_number = (i * HOST_LONG_BITS + j) * hpratio;
addr = page_number * TARGET_PAGE_SIZE;
ram_addr = start + addr;
cpu_physical_memory_set_dirty_range(ram_addr,
TARGET_PAGE_SIZE * hpratio, clients);
} while (c != 0);
}
}Thisis the code that we end using when we are synchronizing from kvm, so if we don't have all pages of a host page set to one (or zero) I think we are doing something wrong, no? Or I am missunderstanding the code?
Quoted 6 lines
b) Are we required to support migration across hosts of different pagesize; and if we do that what size should a bit represent?
People asked about it during postcopy but I think it's restricted to matching sizes. I don't think precopy has any requirement for matching host pagesize at the moment. 64bit ARM does 4k, 64k and I think 16k was added later.
With current precopy, we should work independently of the host page size (famous last words), and in a 1st step, I will only send pages of the size TARGET_PAGE_SIZE. I will only change the bitmaps. We can add bigger pages later.
Quoted 5 lines
c) Hugepages have similar issues; precopy doesn't currently have any requirement for the hugepage selection on the two hosts to match, but it does on postcopy. Also you don't want to have a single dirty bit for a 1GB host hugepage if you can handle detecting changes at a finer grain level.
I agree here, I was thinking more on the Power/ARM case than the HugePage case. For the 2MB page, we could think about doing it, for the 1GB case, it is not gonna work.
Later, Juan.
Quoted 35 lines · * Juan Quintela ([email protected]) wrote:
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:
Note that there are two reason for this, ARM and PPC do things like guests with 4kb pages on hosts with 16/64kb hosts, and then we have HugePages. Note all the workarounds that postcopy has to do because to work in HugePages size.
Quoted 7 lines
There are some fun problems with changing the bitmap page size; off the top of my head, the ones I can remember include:
a) I'm sure I've seen rare cases where a target page is marked as dirty inside a hostpage; I'm guessing that was qemu's doing, but there are more subtle cases, e.g. running a 4kb guest on a 64kb host; it's legal - and 4kb power guests used to exist; I think in those cases you see KVM only marking one target page as dirty./* * bitmap-traveling is faster than memory-traveling (for addr...) * especially when most of the memory is not dirty. */ for (i = 0; i < len; i++) { if (bitmap[i] != 0) { c = leul_to_cpu(bitmap[i]); do { j = ctzl(c); c &= ~(1ul << j); page_number = (i * HOST_LONG_BITS + j) * hpratio; addr = page_number * TARGET_PAGE_SIZE; ram_addr = start + addr; cpu_physical_memory_set_dirty_range(ram_addr, TARGET_PAGE_SIZE * hpratio, clients); } while (c != 0); } }
Quoted 3 lines
Thisis the code that we end using when we are synchronizing from kvm, so if we don't have all pages of a host page set to one (or zero) I think we are doing something wrong, no? Or I am missunderstanding the code?
Hmm, that does look like that - so perhaps the case I was seeing was just qemu setting it somewhere?
(I definitely remember seeing it because I remember dumping the bitmaps and checking for them; but I can't remember the circumstance)
Quoted 18 lines
Quoted 6 lines
b) Are we required to support migration across hosts of different pagesize; and if we do that what size should a bit represent?
People asked about it during postcopy but I think it's restricted to matching sizes. I don't think precopy has any requirement for matching host pagesize at the moment. 64bit ARM does 4k, 64k and I think 16k was added later.With current precopy, we should work independently of the host page size (famous last words), and in a 1st step, I will only send pages of the size
TARGET_PAGE_SIZE. I will only change the bitmaps. We can add bigger pages later.Quoted 5 lines
c) Hugepages have similar issues; precopy doesn't currently have any requirement for the hugepage selection on the two hosts to match, but it does on postcopy. Also you don't want to have a single dirty bit for a 1GB host hugepage if you can handle detecting changes at a finer grain level.
Quoted 3 lines
I agree here, I was thinking more on the Power/ARM case than the HugePage case. For the 2MB page, we could think about doing it, for the 1GB case, it is not gonna work.
Yep,
Dave
Quoted 1 line
Later, Juan.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK