]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
virtio_pci: Optimize virtio_pci_device structure size
authorFeng Liu <feliu@nvidia.com>
Tue, 16 May 2023 13:54:46 +0000 (09:54 -0400)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 27 Jun 2023 14:47:08 +0000 (10:47 -0400)
commit4f0fc22534e3d81ebd470e899fed3c0dbb4aeb56
tree83986a3e0a74b003fe6ec4ad44686dba1bfae541
parent77b894f220cbd04301b3d941df8247106e67f8e4
virtio_pci: Optimize virtio_pci_device structure size

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>
Message-Id: <20230516135446.16266-1-feliu@nvidia.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
drivers/virtio/virtio_pci_common.h