qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 2/3] aio: use g_slice_alloc() for AIOCB pooli


From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH v2 2/3] aio: use g_slice_alloc() for AIOCB pooling
Date: Mon, 12 Nov 2012 11:34:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0

Am 31.10.2012 16:34, schrieb Stefan Hajnoczi:
> 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.

Of course the real reason is that all fields are set anyway. We could
even express this fact more clearly in the code:

diff --git a/block.c b/block.c
index 854ebd6..6f5a0e7 100644
--- a/block.c
+++ b/block.c
@@ -3910,10 +3910,13 @@ void *qemu_aio_get(const AIOCBInfo *aiocb_info,
BlockDriverState *bs,
     BlockDriverAIOCB *acb;

     acb = g_slice_alloc(aiocb_info->aiocb_size);
-    acb->aiocb_info = aiocb_info;
-    acb->bs = bs;
-    acb->cb = cb;
-    acb->opaque = opaque;
+    *acb = (BlockDriverAIOCB) {
+        .aiocb_info = aiocb_info,
+        .bs         = bs,
+        .cb         = cb,
+        .opaque     = opaque,
+    };
+
     return acb;
 }

If you agree, I'll commit this on top of your series.

Kevin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]