From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 13/15] nbd: use g_slice_new() instead of a freelist
Date: Fri, 3 May 2013 13:52:50 +0200 [thread overview]
Message-ID: <1367581972-4208-14-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1367581972-4208-1-git-send-email-stefanha@redhat.com>
Use GLib's efficient slice allocator instead of open-coding the request
freelist. This patch simplifies the NBDRequest code.
Now we qemu_blockalign() the req->data buffer each time but the next
patch switches from a fixed size buffer to a dynamic size anyway.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
nbd.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/nbd.c b/nbd.c
index 85187ff..761f4ec 100644
--- a/nbd.c
+++ b/nbd.c
@@ -98,7 +98,6 @@ struct NBDExport {
off_t size;
uint32_t nbdflags;
QTAILQ_HEAD(, NBDClient) clients;
- QSIMPLEQ_HEAD(, NBDRequest) requests;
QTAILQ_ENTRY(NBDExport) next;
};
@@ -850,13 +849,8 @@ static NBDRequest *nbd_request_get(NBDClient *client)
assert(client->nb_requests <= MAX_NBD_REQUESTS - 1);
client->nb_requests++;
- if (QSIMPLEQ_EMPTY(&exp->requests)) {
- req = g_malloc0(sizeof(NBDRequest));
- req->data = qemu_blockalign(exp->bs, NBD_BUFFER_SIZE);
- } else {
- req = QSIMPLEQ_FIRST(&exp->requests);
- QSIMPLEQ_REMOVE_HEAD(&exp->requests, entry);
- }
+ req = g_slice_new0(NBDRequest);
+ req->data = qemu_blockalign(exp->bs, NBD_BUFFER_SIZE);
nbd_client_get(client);
req->client = client;
return req;
@@ -865,7 +859,10 @@ static NBDRequest *nbd_request_get(NBDClient *client)
static void nbd_request_put(NBDRequest *req)
{
NBDClient *client = req->client;
- QSIMPLEQ_INSERT_HEAD(&client->exp->requests, req, entry);
+
+ qemu_vfree(req->data);
+ g_slice_free(NBDRequest, req);
+
if (client->nb_requests-- == MAX_NBD_REQUESTS) {
qemu_notify_event();
}
@@ -877,7 +874,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
void (*close)(NBDExport *))
{
NBDExport *exp = g_malloc0(sizeof(NBDExport));
- QSIMPLEQ_INIT(&exp->requests);
exp->refcount = 1;
QTAILQ_INIT(&exp->clients);
exp->bs = bs;
@@ -953,13 +949,6 @@ void nbd_export_put(NBDExport *exp)
exp->close(exp);
}
- while (!QSIMPLEQ_EMPTY(&exp->requests)) {
- NBDRequest *first = QSIMPLEQ_FIRST(&exp->requests);
- QSIMPLEQ_REMOVE_HEAD(&exp->requests, entry);
- qemu_vfree(first->data);
- g_free(first);
- }
-
g_free(exp);
}
}
--
1.8.1.4
next prev parent reply other threads:[~2013-05-03 11:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-03 11:52 [Qemu-devel] [PULL 00/15] Block patches Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 01/15] qemu: add castagnoli crc32c checksum algorithm Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 02/15] block: vhdx header for the QEMU support of VHDX images Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 03/15] block: initial VHDX driver support framework - supports open and probe Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 04/15] block: add read-only support to VHDX image format Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 05/15] blockdev: Replace "undefined error" in qmp_block_resize Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 06/15] vmdk: named return code Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 07/15] vmdk: add support for “zeroed‐grain” GTE Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 08/15] vmdk: Add option to create zeroed-grain image Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 09/15] vmdk: change magic number to macro Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 10/15] vmdk: store fields of VmdkMetaData in cpu endian Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 11/15] vmdk: add bdrv_co_write_zeroes Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 12/15] qemu-iotests: Filter out vmdk creation options Stefan Hajnoczi
2013-05-03 11:52 ` Stefan Hajnoczi [this message]
2013-05-03 11:52 ` [Qemu-devel] [PATCH 14/15] nbd: support large NBD requests Stefan Hajnoczi
2013-05-03 11:52 ` [Qemu-devel] [PATCH 15/15] qemu-iotests: Filter out 'adapter_type' Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1367581972-4208-14-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).