diff mbox series

HID: Reorder fields in 'struct hid_input'

Message ID 9accb4ebd1247e2f2acc77dd053f67e60bf8d283.1687079502.git.christophe.jaillet@wanadoo.fr
State Accepted
Commit 574d06ceb88fb735a7d88c22e6531f4849aada51
Headers show
Series HID: Reorder fields in 'struct hid_input' | expand

Commit Message

Christophe JAILLET June 18, 2023, 9:11 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 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@wanadoo.fr>
---
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(-)

Comments

Jiri Kosina Aug. 14, 2023, 9:21 a.m. UTC | #1
On Sun, 18 Jun 2023, Christophe JAILLET wrote:

> 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.

Applied, thanks.
diff mbox series

Patch

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 {