virtio_pci: Optimize virtio_pci_device structure size
Subsystems (3)
PATCH 1/1 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 */
[...]
};
--- drivers/virtio/virtio_pci_common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/virtio/virtio_pci_common.h +4 -3
@@ -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 */
Signature · 1 line
2.37.1 (Apple Git-137.1)
Quoted 30 lines · Feng Liu
Improve the size of the
virtio_pci_devicestructure, 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
structvirtio_pci_legacy_deviceoccupying 32 bytes and the structvirtio_pci_modern_deviceoccupying 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:
structvirtio_pci_device{
[...]
structvirtio_pci_legacy_deviceldev; /* 824 32 */
/* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
structvirtio_pci_modern_devicemdev; /* 856 88 *//* XXX last struct has 4 bytes of padding */
[...]/* size: 1056, cachelines: 17, members: 19 */[...]
};After the modification, pahole tool reported the following:
structvirtio_pci_device{
[...]
union {
structvirtio_pci_legacy_deviceldev; /* 824 32 */
structvirtio_pci_modern_devicemdev; /* 824 88 */
}; /* 824 88 */
[...]
Quoted 6 lines
/* size: 1024, cachelines: 16, members: 18 */[...]
};Signed-off-by Feng Liu <[email protected]>Reviewed-by Jiri Pirko <[email protected]>
Thanks.
Quoted 25 lines
--- drivers/virtio/virtio_pci_common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.h +4
-4@@ -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)
Quoted 31 lines · Feng Liu
Improve the size of the
virtio_pci_devicestructure, 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
structvirtio_pci_legacy_deviceoccupying 32 bytes and the structvirtio_pci_modern_deviceoccupying 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:
structvirtio_pci_device{
[...]
structvirtio_pci_legacy_deviceldev; /* 824 32 */
/* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
structvirtio_pci_modern_devicemdev; /* 856 88 *//* XXX last struct has 4 bytes of padding */
[...]/* size: 1056, cachelines: 17, members: 19 */[...]
};After the modification, pahole tool reported the following:
structvirtio_pci_device{
[...]
union {
structvirtio_pci_legacy_deviceldev; /* 824 32 */
structvirtio_pci_modern_devicemdev; /* 824 88 */
}; /* 824 88 */
[...]
Quoted 6 lines
/* size: 1024, cachelines: 16, members: 18 */[...]
};Signed-off-by Feng Liu <[email protected]>Reviewed-by Jiri Pirko <[email protected]>
Thanks
Quoted 25 lines
--- drivers/virtio/virtio_pci_common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/virtio/virtio_pci_common.h +4
-4@@ -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)