Thread (2 messages) 2 messages, 2 authors, 2023-08-14

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

STALE1148d

From: Christophe JAILLET <hidden>
Date: 2023-06-18 09:12:26
Also in: kernel-janitors, lkml
Subsystem: hid core layer, the rest · Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds

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 <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help