ACPI: video: Reorder fields in 'struct acpi_video_device'

Message ID 6b868520dac20434296b6282496d3234fae01115.1676631473.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series ACPI: video: Reorder fields in 'struct acpi_video_device' |

Commit Message

Christophe JAILLET Feb. 17, 2023, 10:59 a.m. UTC
  Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct acpi_video_device'
from 264 to 256 bytes.

This size is much better when the struct is kmalloc()'ed.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole

Before:
======
struct acpi_video_device {
	long unsigned int          device_id;            /*     0     8 */
	struct acpi_video_device_flags flags;            /*     8     1 */
	struct acpi_video_device_cap cap;                /*     9     1 */

	/* XXX 6 bytes hole, try to pack */

	struct list_head           entry;                /*    16    16 */
	struct delayed_work        switch_brightness_work; /*    32   184 */

	/* XXX last struct has 4 bytes of padding */

	/* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */
	int                        switch_brightness_event; /*   216     4 */

	/* XXX 4 bytes hole, try to pack */

	struct acpi_video_bus *    video;                /*   224     8 */
	struct acpi_device *       dev;                  /*   232     8 */
	struct acpi_video_device_brightness * brightness; /*   240     8 */
	struct backlight_device *  backlight;            /*   248     8 */
	/* --- cacheline 4 boundary (256 bytes) --- */
	struct thermal_cooling_device * cooling_dev;     /*   256     8 */

	/* size: 264, cachelines: 5, members: 11 */
	/* sum members: 254, holes: 2, sum holes: 10 */
	/* paddings: 1, sum paddings: 4 */
	/* last cacheline: 8 bytes */
};


After:
=====
struct acpi_video_device {
	long unsigned int          device_id;            /*     0     8 */
	struct list_head           entry;                /*     8    16 */
	struct acpi_video_device_flags flags;            /*    24     1 */
	struct acpi_video_device_cap cap;                /*    25     1 */

	/* XXX 2 bytes hole, try to pack */

	int                        switch_brightness_event; /*    28     4 */
	struct delayed_work        switch_brightness_work; /*    32   184 */

	/* XXX last struct has 4 bytes of padding */

	/* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */
	struct acpi_video_bus *    video;                /*   216     8 */
	struct acpi_device *       dev;                  /*   224     8 */
	struct acpi_video_device_brightness * brightness; /*   232     8 */
	struct backlight_device *  backlight;            /*   240     8 */
	struct thermal_cooling_device * cooling_dev;     /*   248     8 */

	/* size: 256, cachelines: 4, members: 11 */
	/* sum members: 254, holes: 1, sum holes: 2 */
	/* paddings: 1, sum paddings: 4 */
};
---
 drivers/acpi/acpi_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 97b711e57bff..1118dd7dbf6c 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -202,11 +202,11 @@  struct acpi_video_device_cap {
 
 struct acpi_video_device {
 	unsigned long device_id;
+	struct list_head entry;
 	struct acpi_video_device_flags flags;
 	struct acpi_video_device_cap cap;
-	struct list_head entry;
-	struct delayed_work switch_brightness_work;
 	int switch_brightness_event;
+	struct delayed_work switch_brightness_work;
 	struct acpi_video_bus *video;
 	struct acpi_device *dev;
 	struct acpi_video_device_brightness *brightness;