* [PATCH] virtio: Reorder fields in 'struct virtqueue'
@ 2023-02-18 8:10 Christophe JAILLET
2023-02-18 17:51 ` Peter Lafreniere
2023-03-08 14:07 ` Stefano Garzarella
0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-02-18 8:10 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, virtualization
Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct virtqueue'
from 72 to 68 bytes.
It saves a few bytes of memory.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole
Before:
======
struct virtqueue {
struct list_head list; /* 0 16 */
void (*callback)(struct virtqueue *); /* 16 8 */
const char * name; /* 24 8 */
struct virtio_device * vdev; /* 32 8 */
unsigned int index; /* 40 4 */
unsigned int num_free; /* 44 4 */
unsigned int num_max; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
void * priv; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
bool reset; /* 64 1 */
/* size: 72, cachelines: 2, members: 9 */
/* sum members: 61, holes: 1, sum holes: 4 */
/* padding: 7 */
/* last cacheline: 8 bytes */
};
After:
=====
struct virtqueue {
struct list_head list; /* 0 16 */
void (*callback)(struct virtqueue *); /* 16 8 */
const char * name; /* 24 8 */
struct virtio_device * vdev; /* 32 8 */
unsigned int index; /* 40 4 */
unsigned int num_free; /* 44 4 */
unsigned int num_max; /* 48 4 */
bool reset; /* 52 1 */
/* XXX 3 bytes hole, try to pack */
void * priv; /* 56 8 */
/* size: 64, cachelines: 1, members: 9 */
/* sum members: 61, holes: 1, sum holes: 3 */
};
---
include/linux/virtio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 6ac2655500dc..9439ae898310 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -35,8 +35,8 @@ struct virtqueue {
unsigned int index;
unsigned int num_free;
unsigned int num_max;
- void *priv;
bool reset;
+ void *priv;
};
int virtqueue_add_outbuf(struct virtqueue *vq,
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Reorder fields in 'struct virtqueue'
2023-02-18 8:10 [PATCH] virtio: Reorder fields in 'struct virtqueue' Christophe JAILLET
@ 2023-02-18 17:51 ` Peter Lafreniere
2023-03-08 14:07 ` Stefano Garzarella
1 sibling, 0 replies; 3+ messages in thread
From: Peter Lafreniere @ 2023-02-18 17:51 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Michael S. Tsirkin, Jason Wang, linux-kernel, kernel-janitors,
virtualization
On Saturday, February 18th, 2023 at 03:10, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
>
>
> Group some variables based on their sizes to reduce hole and avoid padding.
> On x86_64, this shrinks the size of 'struct virtqueue'
> from 72 to 68 bytes.
>
> It saves a few bytes of memory.
>
> Signed-off-by: Christophe JAILLET christophe.jaillet@wanadoo.fr
>
> ---
> Using pahole
>
> Before:
> ======
> struct virtqueue {
> struct list_head list; /* 0 16 */
> void (*callback)(struct virtqueue ); / 16 8 /
> const char * name; / 24 8 /
> struct virtio_device * vdev; / 32 8 /
> unsigned int index; / 40 4 /
> unsigned int num_free; / 44 4 /
> unsigned int num_max; / 48 4 /
>
> / XXX 4 bytes hole, try to pack /
>
> void * priv; / 56 8 /
> / --- cacheline 1 boundary (64 bytes) --- /
> bool reset; / 64 1 /
>
> / size: 72, cachelines: 2, members: 9 /
> / sum members: 61, holes: 1, sum holes: 4 /
> / padding: 7 /
> / last cacheline: 8 bytes /
> };
>
> After:
> =====
> struct virtqueue {
> struct list_head list; / 0 16 */
> void (*callback)(struct virtqueue ); / 16 8 /
> const char * name; / 24 8 /
> struct virtio_device * vdev; / 32 8 /
> unsigned int index; / 40 4 /
> unsigned int num_free; / 44 4 /
> unsigned int num_max; / 48 4 /
> bool reset; / 52 1 /
>
> / XXX 3 bytes hole, try to pack /
>
> void * priv; / 56 8 /
>
> / size: 64, cachelines: 1, members: 9 /
> / sum members: 61, holes: 1, sum holes: 3 */
> };
> ---
> include/linux/virtio.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index 6ac2655500dc..9439ae898310 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -35,8 +35,8 @@ struct virtqueue {
> unsigned int index;
> unsigned int num_free;
> unsigned int num_max;
> - void *priv;
> bool reset;
> + void *priv;
> };
>
> int virtqueue_add_outbuf(struct virtqueue *vq,
> --
> 2.34.1
This will shrink the struct size on 32 bit archs too.
Acked-by: Peter Lafreniere <peter@n8pjl.ca>
- Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Reorder fields in 'struct virtqueue'
2023-02-18 8:10 [PATCH] virtio: Reorder fields in 'struct virtqueue' Christophe JAILLET
2023-02-18 17:51 ` Peter Lafreniere
@ 2023-03-08 14:07 ` Stefano Garzarella
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Garzarella @ 2023-03-08 14:07 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Michael S. Tsirkin, Jason Wang, linux-kernel, kernel-janitors,
virtualization
On Sat, Feb 18, 2023 at 09:10:31AM +0100, Christophe JAILLET wrote:
>Group some variables based on their sizes to reduce hole and avoid padding.
>On x86_64, this shrinks the size of 'struct virtqueue'
>from 72 to 68 bytes.
>
>It saves a few bytes of memory.
>
>Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>---
LGTM!
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>Using pahole
>
>Before:
>======
>struct virtqueue {
> struct list_head list; /* 0 16 */
> void (*callback)(struct virtqueue *); /* 16 8 */
> const char * name; /* 24 8 */
> struct virtio_device * vdev; /* 32 8 */
> unsigned int index; /* 40 4 */
> unsigned int num_free; /* 44 4 */
> unsigned int num_max; /* 48 4 */
>
> /* XXX 4 bytes hole, try to pack */
>
> void * priv; /* 56 8 */
> /* --- cacheline 1 boundary (64 bytes) --- */
> bool reset; /* 64 1 */
>
> /* size: 72, cachelines: 2, members: 9 */
> /* sum members: 61, holes: 1, sum holes: 4 */
> /* padding: 7 */
> /* last cacheline: 8 bytes */
>};
>
>After:
>=====
>struct virtqueue {
> struct list_head list; /* 0 16 */
> void (*callback)(struct virtqueue *); /* 16 8 */
> const char * name; /* 24 8 */
> struct virtio_device * vdev; /* 32 8 */
> unsigned int index; /* 40 4 */
> unsigned int num_free; /* 44 4 */
> unsigned int num_max; /* 48 4 */
> bool reset; /* 52 1 */
>
> /* XXX 3 bytes hole, try to pack */
>
> void * priv; /* 56 8 */
>
> /* size: 64, cachelines: 1, members: 9 */
> /* sum members: 61, holes: 1, sum holes: 3 */
>};
>---
> include/linux/virtio.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/include/linux/virtio.h b/include/linux/virtio.h
>index 6ac2655500dc..9439ae898310 100644
>--- a/include/linux/virtio.h
>+++ b/include/linux/virtio.h
>@@ -35,8 +35,8 @@ struct virtqueue {
> unsigned int index;
> unsigned int num_free;
> unsigned int num_max;
>- void *priv;
> bool reset;
>+ void *priv;
> };
>
> int virtqueue_add_outbuf(struct virtqueue *vq,
>--
>2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-08 14:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 8:10 [PATCH] virtio: Reorder fields in 'struct virtqueue' Christophe JAILLET
2023-02-18 17:51 ` Peter Lafreniere
2023-03-08 14:07 ` Stefano Garzarella
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).