Skip to content

Commit

Permalink
block: switch from g_slice allocator to malloc
Browse files Browse the repository at this point in the history
Simplify memory allocation by sticking with a single API.  GSlice
is not that fast anyway (tcmalloc/jemalloc are better).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
bonzini authored and stefanhaRH committed Oct 12, 2015
1 parent a9718ef commit c84b319
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions block/io.c
Expand Up @@ -2218,7 +2218,7 @@ void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs,
{
BlockAIOCB *acb;

acb = g_slice_alloc(aiocb_info->aiocb_size);
acb = g_malloc(aiocb_info->aiocb_size);
acb->aiocb_info = aiocb_info;
acb->bs = bs;
acb->cb = cb;
Expand All @@ -2238,7 +2238,7 @@ void qemu_aio_unref(void *p)
BlockAIOCB *acb = p;
assert(acb->refcnt > 0);
if (--acb->refcnt == 0) {
g_slice_free1(acb->aiocb_info->aiocb_size, acb);
g_free(acb);
}
}

Expand Down
4 changes: 2 additions & 2 deletions block/mirror.c
Expand Up @@ -113,7 +113,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
}

qemu_iovec_destroy(&op->qiov);
g_slice_free(MirrorOp, op);
g_free(op);

if (s->waiting_for_io) {
qemu_coroutine_enter(s->common.co, NULL);
Expand Down Expand Up @@ -264,7 +264,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
} while (delay_ns == 0 && next_sector < end);

/* Allocate a MirrorOp that is used as an AIO callback. */
op = g_slice_new(MirrorOp);
op = g_new(MirrorOp, 1);
op->s = s;
op->sector_num = sector_num;
op->nb_sectors = nb_sectors;
Expand Down
8 changes: 4 additions & 4 deletions block/raw-posix.c
Expand Up @@ -1259,15 +1259,15 @@ static int aio_worker(void *arg)
break;
}

g_slice_free(RawPosixAIOData, aiocb);
g_free(aiocb);
return ret;
}

static int paio_submit_co(BlockDriverState *bs, int fd,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
int type)
{
RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
RawPosixAIOData *acb = g_new(RawPosixAIOData, 1);
ThreadPool *pool;

acb->bs = bs;
Expand All @@ -1292,7 +1292,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockCompletionFunc *cb, void *opaque, int type)
{
RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
RawPosixAIOData *acb = g_new(RawPosixAIOData, 1);
ThreadPool *pool;

acb->bs = bs;
Expand Down Expand Up @@ -2237,7 +2237,7 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs,
if (fd_open(bs) < 0)
return NULL;

acb = g_slice_new(RawPosixAIOData);
acb = g_new(RawPosixAIOData, 1);
acb->bs = bs;
acb->aio_type = QEMU_AIO_IOCTL;
acb->aio_fildes = s->fd;
Expand Down
4 changes: 2 additions & 2 deletions block/raw-win32.c
Expand Up @@ -135,15 +135,15 @@ static int aio_worker(void *arg)
break;
}

g_slice_free(RawWin32AIOData, aiocb);
g_free(aiocb);
return ret;
}

static BlockAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockCompletionFunc *cb, void *opaque, int type)
{
RawWin32AIOData *acb = g_slice_new(RawWin32AIOData);
RawWin32AIOData *acb = g_new(RawWin32AIOData, 1);
ThreadPool *pool;

acb->bs = bs;
Expand Down
4 changes: 2 additions & 2 deletions hw/block/virtio-blk.c
Expand Up @@ -30,7 +30,7 @@

VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
{
VirtIOBlockReq *req = g_slice_new(VirtIOBlockReq);
VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
req->dev = s;
req->qiov.size = 0;
req->in_len = 0;
Expand All @@ -42,7 +42,7 @@ VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
void virtio_blk_free_request(VirtIOBlockReq *req)
{
if (req) {
g_slice_free(VirtIOBlockReq, req);
g_free(req);
}
}

Expand Down

0 comments on commit c84b319

Please sign in to comment.