Skip to content

Commit 9115e8c

Browse files
edumazetdavem330
authored andcommitted
net: reorganize struct sock for better data locality
Group fields used in TX path, and keep some cache lines mostly read to permit sharing among cpus. Gained two 4 bytes holes on 64bit arches. Added a place holder for tcp tsq_flags, next to sk_wmem_alloc to speed up tcp_wfree() in the following patch. I have not added ____cacheline_aligned_in_smp, this might be done later. I prefer doing this once inet and tcp/udp sockets reorg is also done. Tested with both TCP and UDP. UDP receiver performance under flood increased by ~20 % : Accessing sk_filter/sk_wq/sk_napi_id no longer stalls because sk_drops was moved away from a critical cache line, now mostly read and shared. /* --- cacheline 4 boundary (256 bytes) --- */ unsigned int sk_napi_id; /* 0x100 0x4 */ int sk_rcvbuf; /* 0x104 0x4 */ struct sk_filter * sk_filter; /* 0x108 0x8 */ union { struct socket_wq * sk_wq; /* 0x8 */ struct socket_wq * sk_wq_raw; /* 0x8 */ }; /* 0x110 0x8 */ struct xfrm_policy * sk_policy[2]; /* 0x118 0x10 */ struct dst_entry * sk_rx_dst; /* 0x128 0x8 */ struct dst_entry * sk_dst_cache; /* 0x130 0x8 */ atomic_t sk_omem_alloc; /* 0x138 0x4 */ int sk_sndbuf; /* 0x13c 0x4 */ /* --- cacheline 5 boundary (320 bytes) --- */ int sk_wmem_queued; /* 0x140 0x4 */ atomic_t sk_wmem_alloc; /* 0x144 0x4 */ long unsigned int sk_tsq_flags; /* 0x148 0x8 */ struct sk_buff * sk_send_head; /* 0x150 0x8 */ struct sk_buff_head sk_write_queue; /* 0x158 0x18 */ __s32 sk_peek_off; /* 0x170 0x4 */ int sk_write_pending; /* 0x174 0x4 */ long int sk_sndtimeo; /* 0x178 0x8 */ Signed-off-by: Eric Dumazet <[email protected]> Tested-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 12a59ab commit 9115e8c

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

include/net/sock.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ struct sock {
343343
#define sk_rxhash __sk_common.skc_rxhash
344344

345345
socket_lock_t sk_lock;
346+
atomic_t sk_drops;
347+
int sk_rcvlowat;
348+
struct sk_buff_head sk_error_queue;
346349
struct sk_buff_head sk_receive_queue;
347350
/*
348351
* The backlog queue is special, it is always used with
@@ -359,14 +362,13 @@ struct sock {
359362
struct sk_buff *tail;
360363
} sk_backlog;
361364
#define sk_rmem_alloc sk_backlog.rmem_alloc
362-
int sk_forward_alloc;
363365

364-
__u32 sk_txhash;
366+
int sk_forward_alloc;
365367
#ifdef CONFIG_NET_RX_BUSY_POLL
366-
unsigned int sk_napi_id;
367368
unsigned int sk_ll_usec;
369+
/* ===== mostly read cache line ===== */
370+
unsigned int sk_napi_id;
368371
#endif
369-
atomic_t sk_drops;
370372
int sk_rcvbuf;
371373

372374
struct sk_filter __rcu *sk_filter;
@@ -379,11 +381,30 @@ struct sock {
379381
#endif
380382
struct dst_entry *sk_rx_dst;
381383
struct dst_entry __rcu *sk_dst_cache;
382-
/* Note: 32bit hole on 64bit arches */
383-
atomic_t sk_wmem_alloc;
384384
atomic_t sk_omem_alloc;
385385
int sk_sndbuf;
386+
387+
/* ===== cache line for TX ===== */
388+
int sk_wmem_queued;
389+
atomic_t sk_wmem_alloc;
390+
unsigned long sk_tsq_flags;
391+
struct sk_buff *sk_send_head;
386392
struct sk_buff_head sk_write_queue;
393+
__s32 sk_peek_off;
394+
int sk_write_pending;
395+
long sk_sndtimeo;
396+
struct timer_list sk_timer;
397+
__u32 sk_priority;
398+
__u32 sk_mark;
399+
u32 sk_pacing_rate; /* bytes per second */
400+
u32 sk_max_pacing_rate;
401+
struct page_frag sk_frag;
402+
netdev_features_t sk_route_caps;
403+
netdev_features_t sk_route_nocaps;
404+
int sk_gso_type;
405+
unsigned int sk_gso_max_size;
406+
gfp_t sk_allocation;
407+
__u32 sk_txhash;
387408

388409
/*
389410
* Because of non atomicity rules, all
@@ -414,42 +435,24 @@ struct sock {
414435
#define SK_PROTOCOL_MAX U8_MAX
415436
kmemcheck_bitfield_end(flags);
416437

417-
int sk_wmem_queued;
418-
gfp_t sk_allocation;
419-
u32 sk_pacing_rate; /* bytes per second */
420-
u32 sk_max_pacing_rate;
421-
netdev_features_t sk_route_caps;
422-
netdev_features_t sk_route_nocaps;
423-
int sk_gso_type;
424-
unsigned int sk_gso_max_size;
425438
u16 sk_gso_max_segs;
426-
int sk_rcvlowat;
427439
unsigned long sk_lingertime;
428-
struct sk_buff_head sk_error_queue;
429440
struct proto *sk_prot_creator;
430441
rwlock_t sk_callback_lock;
431442
int sk_err,
432443
sk_err_soft;
433444
u32 sk_ack_backlog;
434445
u32 sk_max_ack_backlog;
435-
__u32 sk_priority;
436-
__u32 sk_mark;
437446
kuid_t sk_uid;
438447
struct pid *sk_peer_pid;
439448
const struct cred *sk_peer_cred;
440449
long sk_rcvtimeo;
441-
long sk_sndtimeo;
442-
struct timer_list sk_timer;
443450
ktime_t sk_stamp;
444451
u16 sk_tsflags;
445452
u8 sk_shutdown;
446453
u32 sk_tskey;
447454
struct socket *sk_socket;
448455
void *sk_user_data;
449-
struct page_frag sk_frag;
450-
struct sk_buff *sk_send_head;
451-
__s32 sk_peek_off;
452-
int sk_write_pending;
453456
#ifdef CONFIG_SECURITY
454457
void *sk_security;
455458
#endif

0 commit comments

Comments
 (0)