Skip to content

Commit ebf05c7

Browse files
committed
tty: shrink the size of struct tty_struct by 40 bytes
It's been a long time since anyone has looked at what struct tty_struct looks like in memory, turns out there was a ton of holes. So move things around a bit, change one variable (closing) from being an int to a bool (it is only being tested for 0/1), and we end up saving 40 bytes per structure overall on x86-64 systems. Before this patch: /* size: 696, cachelines: 11, members: 37 */ /* sum members: 665, holes: 8, sum holes: 31 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 4 */ /* last cacheline: 56 bytes */ After this change: /* size: 656, cachelines: 11, members: 37 */ /* sum members: 654, holes: 1, sum holes: 2 */ /* forced alignments: 2 */ /* last cacheline: 16 bytes */ Cc: Jiri Slaby <[email protected]> Link: https://lore.kernel.org/r/2023082519-cobbler-unholy-8d1f@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a84853c commit ebf05c7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

include/linux/tty.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,14 @@ struct tty_operations;
192192
*/
193193
struct tty_struct {
194194
struct kref kref;
195+
int index;
195196
struct device *dev;
196197
struct tty_driver *driver;
198+
struct tty_port *port;
197199
const struct tty_operations *ops;
198-
int index;
199200

200-
struct ld_semaphore ldisc_sem;
201201
struct tty_ldisc *ldisc;
202+
struct ld_semaphore ldisc_sem;
202203

203204
struct mutex atomic_write_lock;
204205
struct mutex legacy_mutex;
@@ -209,6 +210,7 @@ struct tty_struct {
209210
char name[64];
210211
unsigned long flags;
211212
int count;
213+
unsigned int receive_room;
212214
struct winsize winsize;
213215

214216
struct {
@@ -219,16 +221,16 @@ struct tty_struct {
219221
} __aligned(sizeof(unsigned long)) flow;
220222

221223
struct {
222-
spinlock_t lock;
223224
struct pid *pgrp;
224225
struct pid *session;
226+
spinlock_t lock;
225227
unsigned char pktstatus;
226228
bool packet;
227229
unsigned long unused[0];
228230
} __aligned(sizeof(unsigned long)) ctrl;
229231

230232
bool hw_stopped;
231-
unsigned int receive_room;
233+
bool closing;
232234
int flow_change;
233235

234236
struct tty_struct *link;
@@ -239,15 +241,13 @@ struct tty_struct {
239241
void *disc_data;
240242
void *driver_data;
241243
spinlock_t files_lock;
244+
int write_cnt;
245+
unsigned char *write_buf;
246+
242247
struct list_head tty_files;
243248

244249
#define N_TTY_BUF_SIZE 4096
245-
246-
int closing;
247-
unsigned char *write_buf;
248-
int write_cnt;
249250
struct work_struct SAK_work;
250-
struct tty_port *port;
251251
} __randomize_layout;
252252

253253
/* Each of a tty's open files has private_data pointing to tty_file_private */

0 commit comments

Comments
 (0)