Skip to content
  • Stefan Hajnoczi's avatar
    aio: use g_slice_alloc() for AIOCB pooling · d37c975f
    Stefan Hajnoczi authored
    
    
    AIO control blocks are frequently acquired and released because each aio
    request involves at least one AIOCB.  Therefore, we pool them to avoid
    heap allocation overhead.
    
    The problem with the freelist approach in AIOPool is thread-safety.  If
    we want BlockDriverStates to associate with AioContexts that execute in
    multiple threads, then a global freelist becomes a problem.
    
    This patch drops the freelist and instead uses g_slice_alloc() which is
    tuned for per-thread fixed-size object pools.  qemu_aio_get() and
    qemu_aio_release() are now thread-safe.
    
    Note that the change from g_malloc0() to g_slice_alloc() should be safe
    since the freelist reuse case doesn't zero the AIOCB either.
    
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    d37c975f