2023-06-18 11:48:19

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH] HID: Reorder fields in 'struct hid_input'

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 <[email protected]>
---
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



2023-08-14 09:32:31

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: Reorder fields in 'struct hid_input'

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.

--
Jiri Kosina
SUSE Labs