[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/26] aio: use g_slice_alloc() for AIOCB pooling
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 08/26] aio: use g_slice_alloc() for AIOCB pooling |
Date: |
Wed, 14 Nov 2012 19:47:09 +0100 |
From: Stefan Hajnoczi <address@hidden>
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: Stefan Hajnoczi <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 15 ++++-----------
qemu-aio.h | 2 --
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/block.c b/block.c
index da1fdca..ea0f7d8 100644
--- a/block.c
+++ b/block.c
@@ -3909,13 +3909,8 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
{
BlockDriverAIOCB *acb;
- if (pool->free_aiocb) {
- acb = pool->free_aiocb;
- pool->free_aiocb = acb->next;
- } else {
- acb = g_malloc0(pool->aiocb_size);
- acb->pool = pool;
- }
+ acb = g_slice_alloc(pool->aiocb_size);
+ acb->pool = pool;
acb->bs = bs;
acb->cb = cb;
acb->opaque = opaque;
@@ -3924,10 +3919,8 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
void qemu_aio_release(void *p)
{
- BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
- AIOPool *pool = acb->pool;
- acb->next = pool->free_aiocb;
- pool->free_aiocb = acb;
+ BlockDriverAIOCB *acb = p;
+ g_slice_free1(acb->pool->aiocb_size, acb);
}
/**************************************************************/
diff --git a/qemu-aio.h b/qemu-aio.h
index 111b0b3..b29c509 100644
--- a/qemu-aio.h
+++ b/qemu-aio.h
@@ -24,7 +24,6 @@ typedef void BlockDriverCompletionFunc(void *opaque, int ret);
typedef struct AIOPool {
void (*cancel)(BlockDriverAIOCB *acb);
size_t aiocb_size;
- BlockDriverAIOCB *free_aiocb;
} AIOPool;
struct BlockDriverAIOCB {
@@ -32,7 +31,6 @@ struct BlockDriverAIOCB {
BlockDriverState *bs;
BlockDriverCompletionFunc *cb;
void *opaque;
- BlockDriverAIOCB *next;
};
void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
--
1.7.6.5
- [Qemu-devel] [PULL 00/26] Block patches, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 01/26] qemu: Document GlusterFS block driver usage, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 02/26] qcow2: Fix refcount table size calculation, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 03/26] qemu-iotests: qcow2: Test growing large refcount table, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 04/26] MAINTAINERS: add Stefan Hajnoczi as block and virtio-blk co-maintainer, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 05/26] block: Workaround for older versions of MinGW gcc, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 06/26] tests: allow qemu-iotests to be run against nbd backend, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 07/26] aio: switch aiocb_size type int -> size_t, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 08/26] aio: use g_slice_alloc() for AIOCB pooling,
Kevin Wolf <=
- [Qemu-devel] [PATCH 10/26] fdc: Remove status0 parameter from fdctrl_set_fifo(), Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 09/26] aio: rename AIOPool to AIOCBInfo, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 12/26] fdc-test: insert media before fuzzing registers, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 13/26] fdc-test: add tests for non-DMA READ command, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 14/26] fdc: use status0 field instead of a local variable, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 18/26] fdc-test: Check READ ID, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 17/26] fdc: fix false FD_SR0_SEEK, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 16/26] fdc: fix FD_SR0_SEEK for initial seek on DMA transfers, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 24/26] vmdk: Fix data corruption bug in WRITE and READ handling, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 21/26] fdc: remove double affectation of FD_MSR_CMDBUSY flag, Kevin Wolf, 2012/11/14