Bin Guo <[email protected]> writes:

> 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 <[email protected]>
> ---
>  migration/savevm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/migration/savevm.c b/migration/savevm.c
> index d1dd696c17..23adaf9dd9 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -347,10 +347,10 @@ static bool 
> configuration_validate_capabilities(SaveState *state)
>  {
>      bool ret = true;
>      MigrationState *s = migrate_get_current();
> -    unsigned long *source_caps_bm;
> +    DECLARE_BITMAP(source_caps_bm, MIGRATION_CAPABILITY__MAX);
>      int i;
>  
> -    source_caps_bm = bitmap_new(MIGRATION_CAPABILITY__MAX);
> +    bitmap_zero(source_caps_bm, MIGRATION_CAPABILITY__MAX);
>      for (i = 0; i < state->caps_count; i++) {
>          MigrationCapability capability = state->capabilities[i];
>          set_bit(capability, source_caps_bm);
> @@ -373,7 +373,6 @@ static bool configuration_validate_capabilities(SaveState 
> *state)
>          }
>      }
>  
> -    g_free(source_caps_bm);
>      return ret;
>  }

Reviewed-by: Fabiano Rosas <[email protected]>

Reply via email to