diff mbox series

[RFC,2/2] ramlist: Resize dirty bitmap blocks after remove ramblock

Message ID 20201120085157.7136-3-zhukeqian1@huawei.com (mailing list archive)
State New, archived
Headers show
Series bugfix: Decrease dirty bitmap blocks after we remove ramblock | expand

Commit Message

zhukeqian Nov. 20, 2020, 8:51 a.m. UTC
Use the new "dirty_bitmap_resize" interface to reduce dirty bitmap
blocks after we remove a ramblock from ramlist.

Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
---
 softmmu/physmem.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index f6ff78378e..2a17e0a89a 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -2131,6 +2131,8 @@  static void reclaim_ramblock(RAMBlock *block)
 
 void qemu_ram_free(RAMBlock *block)
 {
+    ram_addr_t old_ram_size, new_ram_size;
+
     if (!block) {
         return;
     }
@@ -2140,12 +2142,18 @@  void qemu_ram_free(RAMBlock *block)
     }
 
     qemu_mutex_lock_ramlist();
+
+    old_ram_size = last_ram_page();
     QLIST_REMOVE_RCU(block, next);
+    new_ram_size = last_ram_page();
+    dirty_bitmap_resize(old_ram_size, new_ram_size);
+
     ram_list.mru_block = NULL;
     /* Write list before version */
     smp_wmb();
     ram_list.version++;
     call_rcu(block, reclaim_ramblock, rcu);
+
     qemu_mutex_unlock_ramlist();
 }