ram: account the amount of transferred ram better
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
		
							parent
							
								
									4c8ae0f60e
								
							
						
					
					
						commit
						3f7d7b0981
					
				
							
								
								
									
										34
									
								
								arch_init.c
								
								
								
								
							
							
						
						
									
										34
									
								
								arch_init.c
								
								
								
								
							| 
						 | 
					@ -265,16 +265,21 @@ uint64_t xbzrle_mig_pages_overflow(void)
 | 
				
			||||||
    return acct_info.xbzrle_overflows;
 | 
					    return acct_info.xbzrle_overflows;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 | 
					static size_t save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 | 
				
			||||||
        int cont, int flag)
 | 
					                             int cont, int flag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
        qemu_put_be64(f, offset | cont | flag);
 | 
					    size_t size;
 | 
				
			||||||
        if (!cont) {
 | 
					 | 
				
			||||||
                qemu_put_byte(f, strlen(block->idstr));
 | 
					 | 
				
			||||||
                qemu_put_buffer(f, (uint8_t *)block->idstr,
 | 
					 | 
				
			||||||
                                strlen(block->idstr));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    qemu_put_be64(f, offset | cont | flag);
 | 
				
			||||||
 | 
					    size = 8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!cont) {
 | 
				
			||||||
 | 
					        qemu_put_byte(f, strlen(block->idstr));
 | 
				
			||||||
 | 
					        qemu_put_buffer(f, (uint8_t *)block->idstr,
 | 
				
			||||||
 | 
					                        strlen(block->idstr));
 | 
				
			||||||
 | 
					        size += 1 + strlen(block->idstr);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ENCODING_FLAG_XBZRLE 0x1
 | 
					#define ENCODING_FLAG_XBZRLE 0x1
 | 
				
			||||||
| 
						 | 
					@ -321,11 +326,11 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Send XBZRLE based compressed page */
 | 
					    /* Send XBZRLE based compressed page */
 | 
				
			||||||
    save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
 | 
					    bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
 | 
				
			||||||
    qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
 | 
					    qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
 | 
				
			||||||
    qemu_put_be16(f, encoded_len);
 | 
					    qemu_put_be16(f, encoded_len);
 | 
				
			||||||
    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
 | 
					    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
 | 
				
			||||||
    bytes_sent = encoded_len + 1 + 2;
 | 
					    bytes_sent += encoded_len + 1 + 2;
 | 
				
			||||||
    acct_info.xbzrle_pages++;
 | 
					    acct_info.xbzrle_pages++;
 | 
				
			||||||
    acct_info.xbzrle_bytes += bytes_sent;
 | 
					    acct_info.xbzrle_bytes += bytes_sent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -457,9 +462,10 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (is_dup_page(p)) {
 | 
					            if (is_dup_page(p)) {
 | 
				
			||||||
                acct_info.dup_pages++;
 | 
					                acct_info.dup_pages++;
 | 
				
			||||||
                save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
 | 
					                bytes_sent = save_block_hdr(f, block, offset, cont,
 | 
				
			||||||
 | 
					                                            RAM_SAVE_FLAG_COMPRESS);
 | 
				
			||||||
                qemu_put_byte(f, *p);
 | 
					                qemu_put_byte(f, *p);
 | 
				
			||||||
                bytes_sent = 1;
 | 
					                bytes_sent += 1;
 | 
				
			||||||
            } else if (migrate_use_xbzrle()) {
 | 
					            } else if (migrate_use_xbzrle()) {
 | 
				
			||||||
                current_addr = block->offset + offset;
 | 
					                current_addr = block->offset + offset;
 | 
				
			||||||
                bytes_sent = save_xbzrle_page(f, p, current_addr, block,
 | 
					                bytes_sent = save_xbzrle_page(f, p, current_addr, block,
 | 
				
			||||||
| 
						 | 
					@ -471,9 +477,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* either we didn't send yet (we may have had XBZRLE overflow) */
 | 
					            /* either we didn't send yet (we may have had XBZRLE overflow) */
 | 
				
			||||||
            if (bytes_sent == -1) {
 | 
					            if (bytes_sent == -1) {
 | 
				
			||||||
                save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
 | 
					                bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
 | 
				
			||||||
                qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
 | 
					                qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
 | 
				
			||||||
                bytes_sent = TARGET_PAGE_SIZE;
 | 
					                bytes_sent += TARGET_PAGE_SIZE;
 | 
				
			||||||
                acct_info.norm_pages++;
 | 
					                acct_info.norm_pages++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue