mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size
@ 2023-05-16 13:54 Feng Liu
  2023-05-17  1:32 ` Xuan Zhuo
  2023-05-17  5:23 ` Jason Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Feng Liu @ 2023-05-16 13:54 UTC (permalink / raw)
  To: virtualization, netdev, linux-kernel
  Cc: Jason Wang, Michael S . Tsirkin, Xuan Zhuo, Bodong Wang,
	Feng Liu, Jiri Pirko

Improve the size of the virtio_pci_device structure, which is commonly
used to represent a virtio PCI device. A given virtio PCI device can
either of legacy type or modern type, with the
struct virtio_pci_legacy_device occupying 32 bytes and the
struct virtio_pci_modern_device occupying 88 bytes. Make them a union,
thereby save 32 bytes of memory as shown by the pahole tool. This
improvement is particularly beneficial when dealing with numerous
devices, as it helps conserve memory resources.

Before the modification, pahole tool reported the following:
struct virtio_pci_device {
[...]
        struct virtio_pci_legacy_device ldev;            /*   824    32 */
        /* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
        struct virtio_pci_modern_device mdev;            /*   856    88 */

        /* XXX last struct has 4 bytes of padding */
[...]
        /* size: 1056, cachelines: 17, members: 19 */
[...]
};

After the modification, pahole tool reported the following:
struct virtio_pci_device {
[...]
        union {
                struct virtio_pci_legacy_device ldev;    /*   824    32 */
                struct virtio_pci_modern_device mdev;    /*   824    88 */
        };                                               /*   824    88 */
[...]
	/* size: 1024, cachelines: 16, members: 18 */
[...]
};

Signed-off-by: Feng Liu <feliu@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 drivers/virtio/virtio_pci_common.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
index 23112d84218f..4b773bd7c58c 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -45,9 +45,10 @@ struct virtio_pci_vq_info {
 struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
-	struct virtio_pci_legacy_device ldev;
-	struct virtio_pci_modern_device mdev;
-
+	union {
+		struct virtio_pci_legacy_device ldev;
+		struct virtio_pci_modern_device mdev;
+	};
 	bool is_legacy;
 
 	/* Where to read and clear interrupt */
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size
  2023-05-16 13:54 [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size Feng Liu
@ 2023-05-17  1:32 ` Xuan Zhuo
  2023-05-17  5:23 ` Jason Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Xuan Zhuo @ 2023-05-17  1:32 UTC (permalink / raw)
  To: Feng Liu
  Cc: Jason Wang, Michael S . Tsirkin, Bodong Wang, Feng Liu,
	Jiri Pirko, virtualization, netdev, linux-kernel

On Tue, 16 May 2023 09:54:46 -0400, Feng Liu <feliu@nvidia.com> wrote:
> Improve the size of the virtio_pci_device structure, which is commonly
> used to represent a virtio PCI device. A given virtio PCI device can
> either of legacy type or modern type, with the
> struct virtio_pci_legacy_device occupying 32 bytes and the
> struct virtio_pci_modern_device occupying 88 bytes. Make them a union,
> thereby save 32 bytes of memory as shown by the pahole tool. This
> improvement is particularly beneficial when dealing with numerous
> devices, as it helps conserve memory resources.
>
> Before the modification, pahole tool reported the following:
> struct virtio_pci_device {
> [...]
>         struct virtio_pci_legacy_device ldev;            /*   824    32 */
>         /* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
>         struct virtio_pci_modern_device mdev;            /*   856    88 */
>
>         /* XXX last struct has 4 bytes of padding */
> [...]
>         /* size: 1056, cachelines: 17, members: 19 */
> [...]
> };
>
> After the modification, pahole tool reported the following:
> struct virtio_pci_device {
> [...]
>         union {
>                 struct virtio_pci_legacy_device ldev;    /*   824    32 */
>                 struct virtio_pci_modern_device mdev;    /*   824    88 */
>         };                                               /*   824    88 */
> [...]
> 	/* size: 1024, cachelines: 16, members: 18 */
> [...]
> };
>
> Signed-off-by: Feng Liu <feliu@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

Thanks.

> ---
>  drivers/virtio/virtio_pci_common.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
> index 23112d84218f..4b773bd7c58c 100644
> --- a/drivers/virtio/virtio_pci_common.h
> +++ b/drivers/virtio/virtio_pci_common.h
> @@ -45,9 +45,10 @@ struct virtio_pci_vq_info {
>  struct virtio_pci_device {
>  	struct virtio_device vdev;
>  	struct pci_dev *pci_dev;
> -	struct virtio_pci_legacy_device ldev;
> -	struct virtio_pci_modern_device mdev;
> -
> +	union {
> +		struct virtio_pci_legacy_device ldev;
> +		struct virtio_pci_modern_device mdev;
> +	};
>  	bool is_legacy;
>
>  	/* Where to read and clear interrupt */
> --
> 2.37.1 (Apple Git-137.1)
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size
  2023-05-16 13:54 [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size Feng Liu
  2023-05-17  1:32 ` Xuan Zhuo
@ 2023-05-17  5:23 ` Jason Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Wang @ 2023-05-17  5:23 UTC (permalink / raw)
  To: Feng Liu
  Cc: virtualization, netdev, linux-kernel, Michael S . Tsirkin,
	Xuan Zhuo, Bodong Wang, Jiri Pirko

On Tue, May 16, 2023 at 9:55 PM Feng Liu <feliu@nvidia.com> wrote:
>
> Improve the size of the virtio_pci_device structure, which is commonly
> used to represent a virtio PCI device. A given virtio PCI device can
> either of legacy type or modern type, with the
> struct virtio_pci_legacy_device occupying 32 bytes and the
> struct virtio_pci_modern_device occupying 88 bytes. Make them a union,
> thereby save 32 bytes of memory as shown by the pahole tool. This
> improvement is particularly beneficial when dealing with numerous
> devices, as it helps conserve memory resources.
>
> Before the modification, pahole tool reported the following:
> struct virtio_pci_device {
> [...]
>         struct virtio_pci_legacy_device ldev;            /*   824    32 */
>         /* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
>         struct virtio_pci_modern_device mdev;            /*   856    88 */
>
>         /* XXX last struct has 4 bytes of padding */
> [...]
>         /* size: 1056, cachelines: 17, members: 19 */
> [...]
> };
>
> After the modification, pahole tool reported the following:
> struct virtio_pci_device {
> [...]
>         union {
>                 struct virtio_pci_legacy_device ldev;    /*   824    32 */
>                 struct virtio_pci_modern_device mdev;    /*   824    88 */
>         };                                               /*   824    88 */
> [...]
>         /* size: 1024, cachelines: 16, members: 18 */
> [...]
> };
>
> Signed-off-by: Feng Liu <feliu@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  drivers/virtio/virtio_pci_common.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
> index 23112d84218f..4b773bd7c58c 100644
> --- a/drivers/virtio/virtio_pci_common.h
> +++ b/drivers/virtio/virtio_pci_common.h
> @@ -45,9 +45,10 @@ struct virtio_pci_vq_info {
>  struct virtio_pci_device {
>         struct virtio_device vdev;
>         struct pci_dev *pci_dev;
> -       struct virtio_pci_legacy_device ldev;
> -       struct virtio_pci_modern_device mdev;
> -
> +       union {
> +               struct virtio_pci_legacy_device ldev;
> +               struct virtio_pci_modern_device mdev;
> +       };
>         bool is_legacy;
>
>         /* Where to read and clear interrupt */
> --
> 2.37.1 (Apple Git-137.1)
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-17  5:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 13:54 [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size Feng Liu
2023-05-17  1:32 ` Xuan Zhuo
2023-05-17  5:23 ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®