@samitouri / QOSamiQemu / commits / a5225ba9ee

migration/savevm: use stack-allocated bitmap in configuration_validate_capabilities

configuration_validate_capabilities() allocates a bitmap on the heap to track source capabilities via bitmap_new()/g_free(). Since MIGRATION_CAPABILITY__MAX is a small compile-time constant (< 64), a heap allocation for a bitmap this small is wasteful: it adds malloc/free overhead and a potential cache miss for a transient 8-byte allocation. Replace with DECLARE_BITMAP() on the stack and bitmap_zero() to initialize. This eliminates the heap round-trip entirely. Signed-off-by: Bin Guo <guobin@linux.alibaba.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Link: https://lore.kernel.org/r/20260518110112.21395-5-guobin@linux.alibaba.com Signed-off-by: Peter Xu <peterx@redhat.com>

Bin Guo committed May 18, 2026 at 19:01 UTC a5225ba9ee54f414b4f4907f46f645a135bb9e16
1 file changed +2 -3
migration/savevm.c
+2 -3
@@ -347,10 +347,10 @@ static bool configuration_validate_capabilities(SaveState *state)
347 {
348 bool ret = true;
349 MigrationState *s = migrate_get_current();
350 - unsigned long *source_caps_bm;
350 + DECLARE_BITMAP(source_caps_bm, MIGRATION_CAPABILITY__MAX);
351 int i;
352
353 - source_caps_bm = bitmap_new(MIGRATION_CAPABILITY__MAX);
353 + bitmap_zero(source_caps_bm, MIGRATION_CAPABILITY__MAX);
354 for (i = 0; i < state->caps_count; i++) {
355 MigrationCapability capability = state->capabilities[i];
356 set_bit(capability, source_caps_bm);
@@ -373,7 +373,6 @@ static bool configuration_validate_capabilities(SaveState *state)
373 }
374 }
375
376 - g_free(source_caps_bm);
376 return ret;
377 }
378