Skip to content

Commit 8ef4e27

Browse files
magnus-karlssonborkmann
authored andcommitted
xsk: Rearrange internal structs for better performance
Rearrange the xdp_sock, xdp_umem and xsk_buff_pool structures so that they get smaller and align better to the cache lines. In the previous commits of this patch set, these structs have been reordered with the focus on functionality and simplicity, not performance. This patch improves throughput performance by around 3%. Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Björn Töpel <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 921b686 commit 8ef4e27

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

include/net/xdp_sock.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ struct xdp_umem {
2323
u32 headroom;
2424
u32 chunk_size;
2525
u32 chunks;
26+
u32 npgs;
2627
struct user_struct *user;
2728
refcount_t users;
28-
struct page **pgs;
29-
u32 npgs;
3029
u8 flags;
31-
int id;
3230
bool zc;
31+
struct page **pgs;
32+
int id;
3333
struct list_head xsk_dma_list;
3434
};
3535

@@ -42,7 +42,7 @@ struct xsk_map {
4242
struct xdp_sock {
4343
/* struct sock must be the first member of struct xdp_sock */
4444
struct sock sk;
45-
struct xsk_queue *rx;
45+
struct xsk_queue *rx ____cacheline_aligned_in_smp;
4646
struct net_device *dev;
4747
struct xdp_umem *umem;
4848
struct list_head flush_node;
@@ -54,8 +54,7 @@ struct xdp_sock {
5454
XSK_BOUND,
5555
XSK_UNBOUND,
5656
} state;
57-
/* Protects multiple processes in the control path */
58-
struct mutex mutex;
57+
5958
struct xsk_queue *tx ____cacheline_aligned_in_smp;
6059
struct list_head tx_list;
6160
/* Mutual exclusion of NAPI TX thread and sendmsg error paths
@@ -72,6 +71,8 @@ struct xdp_sock {
7271
struct list_head map_list;
7372
/* Protects map_list */
7473
spinlock_t map_list_lock;
74+
/* Protects multiple processes in the control path */
75+
struct mutex mutex;
7576
struct xsk_queue *fq_tmp; /* Only as tmp storage before bind */
7677
struct xsk_queue *cq_tmp; /* Only as tmp storage before bind */
7778
};

include/net/xsk_buff_pool.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,22 @@ struct xsk_dma_map {
3939
};
4040

4141
struct xsk_buff_pool {
42-
struct xsk_queue *fq;
43-
struct xsk_queue *cq;
42+
/* Members only used in the control path first. */
43+
struct device *dev;
44+
struct net_device *netdev;
45+
struct list_head xsk_tx_list;
46+
/* Protects modifications to the xsk_tx_list */
47+
spinlock_t xsk_tx_list_lock;
48+
refcount_t users;
49+
struct xdp_umem *umem;
50+
struct work_struct work;
4451
struct list_head free_list;
52+
u32 heads_cnt;
53+
u16 queue_id;
54+
55+
/* Data path members as close to free_heads at the end as possible. */
56+
struct xsk_queue *fq ____cacheline_aligned_in_smp;
57+
struct xsk_queue *cq;
4558
/* For performance reasons, each buff pool has its own array of dma_pages
4659
* even when they are identical.
4760
*/
@@ -51,25 +64,15 @@ struct xsk_buff_pool {
5164
u64 addrs_cnt;
5265
u32 free_list_cnt;
5366
u32 dma_pages_cnt;
54-
u32 heads_cnt;
5567
u32 free_heads_cnt;
5668
u32 headroom;
5769
u32 chunk_size;
5870
u32 frame_len;
59-
u16 queue_id;
6071
u8 cached_need_wakeup;
6172
bool uses_need_wakeup;
6273
bool dma_need_sync;
6374
bool unaligned;
64-
struct xdp_umem *umem;
6575
void *addrs;
66-
struct device *dev;
67-
struct net_device *netdev;
68-
struct list_head xsk_tx_list;
69-
/* Protects modifications to the xsk_tx_list */
70-
spinlock_t xsk_tx_list_lock;
71-
refcount_t users;
72-
struct work_struct work;
7376
struct xdp_buff_xsk *free_heads[];
7477
};
7578

0 commit comments

Comments
 (0)