Message ID | 565b6c96250305553c21714f3c482d7d408eb4b2.1340371865.git.quintela@redhat.com |
---|---|
State | New |
Headers | show |
On 06/22/2012 04:46 PM, Juan Quintela wrote: > Calculate the number of dirty pages takes a lot on hosts with lots > of memory. Just maintain how many pages are dirty. > > Signed-off-by: Juan Quintela <quintela@redhat.com> > --- > arch_init.c | 15 +-------------- > cpu-all.h | 1 + > exec-obsolete.h | 10 ++++++++++ > 3 files changed, 12 insertions(+), 14 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index 7de1abf..545cf8f 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -228,20 +228,7 @@ static uint64_t bytes_transferred; > > static ram_addr_t ram_save_remaining(void) > { > - RAMBlock *block; > - ram_addr_t count = 0; > - > - QLIST_FOREACH(block, &ram_list.blocks, next) { > - ram_addr_t addr; > - for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { > - if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, > - DIRTY_MEMORY_MIGRATION)) { > - count++; > - } > - } > - } > - > - return count; > + return ram_list.dirty_pages; > } > > uint64_t ram_bytes_remaining(void) > diff --git a/cpu-all.h b/cpu-all.h > index 50c8b62..88cedba 100644 > --- a/cpu-all.h > +++ b/cpu-all.h > @@ -477,6 +477,7 @@ typedef struct RAMBlock { > typedef struct RAMList { > uint8_t *phys_dirty; > QLIST_HEAD(, RAMBlock) blocks; > + uint64_t dirty_pages; > } RAMList; > extern RAMList ram_list; > > diff --git a/exec-obsolete.h b/exec-obsolete.h > index f8ffce6..c099256 100644 > --- a/exec-obsolete.h > +++ b/exec-obsolete.h > @@ -74,6 +74,11 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start, > static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr, > int dirty_flags) > { > + if ((dirty_flags & MIGRATION_DIRTY_FLAG) && > + !cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE, > + MIGRATION_DIRTY_FLAG)) { > + ram_list.dirty_pages++; > + } > return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags; > } > > @@ -87,6 +92,11 @@ static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr, > { > int mask = ~dirty_flags; > > + if ((dirty_flags & MIGRATION_DIRTY_FLAG) && > + cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE, > + MIGRATION_DIRTY_FLAG)) { > + ram_list.dirty_pages--; > + } > return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask; > } > Reviewed-by: Orit Wasserman <owasserm@redhat.com>
diff --git a/arch_init.c b/arch_init.c index 7de1abf..545cf8f 100644 --- a/arch_init.c +++ b/arch_init.c @@ -228,20 +228,7 @@ static uint64_t bytes_transferred; static ram_addr_t ram_save_remaining(void) { - RAMBlock *block; - ram_addr_t count = 0; - - QLIST_FOREACH(block, &ram_list.blocks, next) { - ram_addr_t addr; - for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { - if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, - DIRTY_MEMORY_MIGRATION)) { - count++; - } - } - } - - return count; + return ram_list.dirty_pages; } uint64_t ram_bytes_remaining(void) diff --git a/cpu-all.h b/cpu-all.h index 50c8b62..88cedba 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -477,6 +477,7 @@ typedef struct RAMBlock { typedef struct RAMList { uint8_t *phys_dirty; QLIST_HEAD(, RAMBlock) blocks; + uint64_t dirty_pages; } RAMList; extern RAMList ram_list; diff --git a/exec-obsolete.h b/exec-obsolete.h index f8ffce6..c099256 100644 --- a/exec-obsolete.h +++ b/exec-obsolete.h @@ -74,6 +74,11 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start, static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr, int dirty_flags) { + if ((dirty_flags & MIGRATION_DIRTY_FLAG) && + !cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE, + MIGRATION_DIRTY_FLAG)) { + ram_list.dirty_pages++; + } return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags; } @@ -87,6 +92,11 @@ static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr, { int mask = ~dirty_flags; + if ((dirty_flags & MIGRATION_DIRTY_FLAG) && + cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE, + MIGRATION_DIRTY_FLAG)) { + ram_list.dirty_pages--; + } return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask; }
Calculate the number of dirty pages takes a lot on hosts with lots of memory. Just maintain how many pages are dirty. Signed-off-by: Juan Quintela <quintela@redhat.com> --- arch_init.c | 15 +-------------- cpu-all.h | 1 + exec-obsolete.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 14 deletions(-)