[PATCH] HID: Reorder fields in 'struct hid_input'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct hid_input'
from 72 to 64 bytes.

It saves a few bytes of memory and is more cache-line friendly.

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

Before:
======
struct hid_input {
	struct list_head           list;                 /*     0    16 */
	struct hid_report *        report;               /*    16     8 */
	struct input_dev *         input;                /*    24     8 */
	const char  *              name;                 /*    32     8 */
	bool                       registered;           /*    40     1 */

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

	struct list_head           reports;              /*    48    16 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	unsigned int               application;          /*    64     4 */

	/* size: 72, cachelines: 2, members: 7 */
	/* sum members: 61, holes: 1, sum holes: 7 */
	/* padding: 4 */
	/* last cacheline: 8 bytes */
};


After:
=====
struct hid_input {
	struct list_head           list;                 /*     0    16 */
	struct hid_report *        report;               /*    16     8 */
	struct input_dev *         input;                /*    24     8 */
	const char  *              name;                 /*    32     8 */
	struct list_head           reports;              /*    40    16 */
	unsigned int               application;          /*    56     4 */
	bool                       registered;           /*    60     1 */

	/* size: 64, cachelines: 1, members: 7 */
	/* padding: 3 */
};
---
 include/linux/hid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/hid.h b/include/linux/hid.h
index 5be5e671c263..d29c5de96a40 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -555,9 +555,9 @@ struct hid_input {
 	struct hid_report *report;
 	struct input_dev *input;
 	const char *name;
-	bool registered;
 	struct list_head reports;	/* the list of reports */
 	unsigned int application;	/* application usage for this input */
+	bool registered;
 };
 
 enum hid_type {
-- 
2.34.1




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux