qemu-kvm: clear only essential parts of VirtIOBlockReq on object allocation - RESUBMIT
PATCH 1/1 qemu-kvm: clear only essential parts of VirtIOBlockReq on object allocation - RESUBMIT
This patch reduces the size of memory being cleared on every virtio-blk IO.
Improve number of IOPS when using avirtio-blk device.
On every virtio-blk IO command passed to QEMU, virtio_blk_alloc_request() allocates and clears (with qemu_mallocz()) a VirtIOBlockReq object. The sizeof(VirtIOBlockReq) equals 41040 bytes on my x86-64 machine. By moving the 'elem' variable to the end of VirtIOBlockReq and clearing only upto the address of the 'elem.in_addr' field, the memset() call now clears only 80 bytes.
---
hw/virtio-blk.c +0 -0
@@ -79,12 +79,13 @@ static inline void virtio_identify_template(struct
virtio_blk_config *bc)
typedef struct VirtIOBlockReq
{
VirtIOBlock *dev;
- VirtQueueElement elem;
struct virtio_blk_inhdr *in;
struct virtio_blk_outhdr *out;
struct virtio_scsi_inhdr *scsi;
QEMUIOVector qiov;
struct VirtIOBlockReq *next;+ /* Members that need clearing, must be added prior to elem */
+ VirtQueueElement elem;
} VirtIOBlockReq;
static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
@@ -139,7 +140,8 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s) {
- VirtIOBlockReq *req = qemu_mallocz(sizeof(*req));
+ VirtIOBlockReq *req = qemu_malloc(sizeof(*req));
+ memset(req, 0, offsetof(VirtIOBlockReq, elem.in_addr[0]));
req->dev = s;
return req;}
Quoted 20 lines · Saul Tamari
This patch reduces the size of memory being cleared on every virtio-blk IO.
Improve number of IOPS when using avirtio-blk device.
On every virtio-blk IO command passed to QEMU,
virtio_blk_alloc_request()allocates and clears (withqemu_mallocz()) a VirtIOBlockReq object. The sizeof(VirtIOBlockReq) equals 41040 bytes on my x86-64 machine. By moving the 'elem' variable to the end of VirtIOBlockReq and clearing only upto the address of the 'elem.in_addr' field, thememset()call now clears only 80 bytes.Signed-off-by Saul Tamari <[email protected]>---
hw/virtio-blk.c +0
-0
hw/virtio-blk.c static inline void virtio_identify_template(struct · line 80
Quoted 2 lines
hw/virtio-blk.c +0
-0@@ -79,12 +79,13 @@ static inline void virtio_identify_template(struct virtio_blk_config *bc)
This patch is whitespace damaged by your mailer.
Regards,
Anthony Liguori
ok,
Below is the patch. This time resent with mutt and hopefully without whitespace changes.
--------------------------------------------------------------------
This patch reduces the amount of memory being cleared on every virtio-blk IO operation.
Improve number of IOPS when using avirtio-blk device.
On every virtio-blk IO command passed to QEMU, virtio_blk_alloc_request() allocates and clears (with qemu_mallocz()) a VirtIOBlockReq object. The sizeof(VirtIOBlockReq) equals 41040 bytes on my x86-64 machine. By moving the 'elem' variable to the end of VirtIOBlockReq and clearing only upto the address of the 'elem.in_addr' field, the memset() call now clears only 80 bytes.
-------------------------------------------------
hw/virtio-blk.c +4 -2
@@ -79,12 +79,13 @@ static inline void virtio_identify_template(struct virtio_blk_config *bc)typedef struct VirtIOBlockReq {VirtIOBlock *dev; -VirtQueueElement elem;struct virtio_blk_inhdr *in;struct virtio_blk_outhdr *out;struct virtio_scsi_inhdr *scsi;QEMUIOVector qiov;struct VirtIOBlockReq *next; +/* Members that need clearing, must be added prior to elem */ +VirtQueueElement elem; }VirtIOBlockReq ;static void virtio_blk_req_complete (VirtIOBlockReq *req,int status)
@@ -139,7 +140,8 @@ static void virtio_blk_flush_complete(void *opaque, int ret)static VirtIOBlockReq *virtio_blk_alloc_request (VirtIOBlock *s) { -VirtIOBlockReq *req =qemu_mallocz (sizeof (*req)); +VirtIOBlockReq *req =qemu_malloc (sizeof (*req)); + memset(req, 0, offsetof(VirtIOBlockReq, elem.in_addr[0])); req->dev = s;return req; }