Skip to contentSkip to conversation

migration/ram: Fix memory leak when using x-ignore-shared

PATCH In review Nikolay Borisov 2 participants 3 messages Sep 16, 2022 – Sep 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration/ram: Fix memory leak when using x-ignore-shared

During ram initialization for migration dirty/clear bitmaps are allocated for all migratable blocks, irrespective of their shared status. However, during ram migration cleanup those bitmaps are freed only for those blocks which aren't shared, in case x-ignore-shared capability is used. This leads to a situation where the bitmaps aren't freed for such blocks.

Fix this by switching the cleanup code to also free bitmaps for all migratable blocks.

---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index dc1de9ddbc68..2e40166d2f9e 100644
@@ -2678,7 +2678,7 @@ static void ram_save_cleanup(void *opaque)
         }
     }
 
-    RAMBLOCK_FOREACH_NOT_IGNORED(block) {
+    RAMBLOCK_FOREACH_MIGRATABLE(block) {
         g_free(block->clear_bmap);
         block->clear_bmap = NULL;
         g_free(block->bmap);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · * Nikolay Borisov ([email protected]) wrote:

During ram initialization for migration dirty/clear bitmaps are allocated for all migratable blocks, irrespective of their shared status. However, during ram migration cleanup those bitmaps are freed only for those blocks which aren't shared, in case x-ignore-shared capability is used. This leads to a situation where the bitmaps aren't freed for such blocks.

Can you show me where you're seeing the allocation based on MIGRATABLE? I'm looking at ram_list_init_bitmaps:

        RAMBLOCK_FOREACH_NOT_IGNORED(block) {
            block->bmap = bitmap_new(pages);
....
            block->clear_bmap = bitmap_new(clear_bmap_size(pages, shift));

So that's based on NOT_IGNORED.

Dave

Quoted 24 lines

Fix this by switching the cleanup code to also free bitmaps for all migratable blocks.

---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index dc1de9ddbc68..2e40166d2f9e 100644
@@ -2678,7 +2678,7 @@ static void ram_save_cleanup(void *opaque)
         }
     }
 
-    RAMBLOCK_FOREACH_NOT_IGNORED(block) {
+    RAMBLOCK_FOREACH_MIGRATABLE(block) {
         g_free(block->clear_bmap);
         block->clear_bmap = NULL;
         g_free(block->bmap);
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#2 lore raw
Quoted 12 lines · Dr. David Alan Gilbert
Quoted 6 lines · * Nikolay Borisov ([email protected]) wrote:

During ram initialization for migration dirty/clear bitmaps are allocated for all migratable blocks, irrespective of their shared status. However, during ram migration cleanup those bitmaps are freed only for those blocks which aren't shared, in case x-ignore-shared capability is used. This leads to a situation where the bitmaps aren't freed for such blocks.

Can you show me where you're seeing the allocation based on MIGRATABLE? I'm looking at ram_list_init_bitmaps:

Quoted 7 lines
         RAMBLOCK_FOREACH_NOT_IGNORED(block) {
             block->bmap = bitmap_new(pages);
....
             block->clear_bmap = bitmap_new(clear_bmap_size(pages, shift));

So that's based on NOT_IGNORED.

Huhz, you are perfectly right and I assume I got confused by the RAMBLOCK_FOREACH_MIGRATABLE in ram_save_setup as opposed to the code in ram_list_init_bitmaps. Apologies for the noise...

Quoted 27 lines

Dave

Quoted 24 lines

Fix this by switching the cleanup code to also free bitmaps for all migratable blocks.

---
  migration/ram.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index dc1de9ddbc68..2e40166d2f9e 100644
@@ -2678,7 +2678,7 @@ static void ram_save_cleanup(void *opaque)
          }
      }
 
-    RAMBLOCK_FOREACH_NOT_IGNORED(block) {
+    RAMBLOCK_FOREACH_MIGRATABLE(block) {
          g_free(block->clear_bmap);
          block->clear_bmap = NULL;
          g_free(block->bmap);
Signature · 1 line
2.34.1