Patchworkβ qemu-kvm: clear only essential parts of VirtIOBlockReq on object allocation

login
register
about
Submitter Saul Tamari
Date 2009-11-04 17:41:07
Message ID <41be791c0911040941y3548de23v20959cf1c1300875@mail.gmail.com>
Download mbox | patch
Permalink /patch/57736/
State New
Headers show

Comments

Saul Tamari - 2009-11-04 17:41:07
This patch reduces the size of memory being cleared on every virtio-blk IO.

On every virtio-blk IO 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.


Signed-off-by: Saul Tamari <st...@gmail.com>
---

 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
@@ -139,7 +139,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, (size_t)&(((VirtIOBlockReq*)0)->elem.in_addr[0]));
     req->dev = s;
     return req;
 }
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Avi Kivity - 2009-11-08 13:07:29
On 11/04/2009 07:41 PM, Saul Tamari wrote:
> This patch reduces the size of memory being cleared on every virtio-blk IO.
>
> On every virtio-blk IO 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.
>
>
> Signed-off-by: Saul Tamari<st...@gmail.com>
>    

Use the full email in signoffs.

> @@ -79,12 +79,12 @@ 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;
> +    VirtQueueElement elem;
>   } VirtIOBlockReq;
>    

Needs a comment to indicate new members must be before 'elem' if they 
need to be cleared.

>   static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
> @@ -139,7 +139,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, (size_t)&(((VirtIOBlockReq*)0)->elem.in_addr[0]));
>    

Please use offsetof() instead of open-coding it.

Submit to qemu-devel@nongnu.org since this came from upstream.
Saul Tamari - 2009-11-09 16:35:08
On Sun, Nov 8, 2009 at 3:07 PM, Avi Kivity <avi@redhat.com> wrote:
[snip]

Thanks for the comments. I'll soon resubmit the corrected patch.

I don't understand what the comment below means.
> Submit to qemu-devel@nongnu.org since this came from upstream.


Thanks,
Saul
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2630b99..fd44371 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -79,12 +79,12 @@  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;
+    VirtQueueElement elem;
 } VirtIOBlockReq;