Commit 8ef4e27e authored by Magnus Karlsson's avatar Magnus Karlsson Committed by Daniel Borkmann

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: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Link: https://lore.kernel.org/bpf/1598603189-32145-10-git-send-email-magnus.karlsson@intel.com
parent 921b6869
...@@ -23,13 +23,13 @@ struct xdp_umem { ...@@ -23,13 +23,13 @@ struct xdp_umem {
u32 headroom; u32 headroom;
u32 chunk_size; u32 chunk_size;
u32 chunks; u32 chunks;
u32 npgs;
struct user_struct *user; struct user_struct *user;
refcount_t users; refcount_t users;
struct page **pgs;
u32 npgs;
u8 flags; u8 flags;
int id;
bool zc; bool zc;
struct page **pgs;
int id;
struct list_head xsk_dma_list; struct list_head xsk_dma_list;
}; };
...@@ -42,7 +42,7 @@ struct xsk_map { ...@@ -42,7 +42,7 @@ struct xsk_map {
struct xdp_sock { struct xdp_sock {
/* struct sock must be the first member of struct xdp_sock */ /* struct sock must be the first member of struct xdp_sock */
struct sock sk; struct sock sk;
struct xsk_queue *rx; struct xsk_queue *rx ____cacheline_aligned_in_smp;
struct net_device *dev; struct net_device *dev;
struct xdp_umem *umem; struct xdp_umem *umem;
struct list_head flush_node; struct list_head flush_node;
...@@ -54,8 +54,7 @@ struct xdp_sock { ...@@ -54,8 +54,7 @@ struct xdp_sock {
XSK_BOUND, XSK_BOUND,
XSK_UNBOUND, XSK_UNBOUND,
} state; } state;
/* Protects multiple processes in the control path */
struct mutex mutex;
struct xsk_queue *tx ____cacheline_aligned_in_smp; struct xsk_queue *tx ____cacheline_aligned_in_smp;
struct list_head tx_list; struct list_head tx_list;
/* Mutual exclusion of NAPI TX thread and sendmsg error paths /* Mutual exclusion of NAPI TX thread and sendmsg error paths
...@@ -72,6 +71,8 @@ struct xdp_sock { ...@@ -72,6 +71,8 @@ struct xdp_sock {
struct list_head map_list; struct list_head map_list;
/* Protects map_list */ /* Protects map_list */
spinlock_t map_list_lock; spinlock_t map_list_lock;
/* Protects multiple processes in the control path */
struct mutex mutex;
struct xsk_queue *fq_tmp; /* Only as tmp storage before bind */ struct xsk_queue *fq_tmp; /* Only as tmp storage before bind */
struct xsk_queue *cq_tmp; /* Only as tmp storage before bind */ struct xsk_queue *cq_tmp; /* Only as tmp storage before bind */
}; };
......
...@@ -39,9 +39,22 @@ struct xsk_dma_map { ...@@ -39,9 +39,22 @@ struct xsk_dma_map {
}; };
struct xsk_buff_pool { struct xsk_buff_pool {
struct xsk_queue *fq; /* Members only used in the control path first. */
struct xsk_queue *cq; struct device *dev;
struct net_device *netdev;
struct list_head xsk_tx_list;
/* Protects modifications to the xsk_tx_list */
spinlock_t xsk_tx_list_lock;
refcount_t users;
struct xdp_umem *umem;
struct work_struct work;
struct list_head free_list; struct list_head free_list;
u32 heads_cnt;
u16 queue_id;
/* Data path members as close to free_heads at the end as possible. */
struct xsk_queue *fq ____cacheline_aligned_in_smp;
struct xsk_queue *cq;
/* For performance reasons, each buff pool has its own array of dma_pages /* For performance reasons, each buff pool has its own array of dma_pages
* even when they are identical. * even when they are identical.
*/ */
...@@ -51,25 +64,15 @@ struct xsk_buff_pool { ...@@ -51,25 +64,15 @@ struct xsk_buff_pool {
u64 addrs_cnt; u64 addrs_cnt;
u32 free_list_cnt; u32 free_list_cnt;
u32 dma_pages_cnt; u32 dma_pages_cnt;
u32 heads_cnt;
u32 free_heads_cnt; u32 free_heads_cnt;
u32 headroom; u32 headroom;
u32 chunk_size; u32 chunk_size;
u32 frame_len; u32 frame_len;
u16 queue_id;
u8 cached_need_wakeup; u8 cached_need_wakeup;
bool uses_need_wakeup; bool uses_need_wakeup;
bool dma_need_sync; bool dma_need_sync;
bool unaligned; bool unaligned;
struct xdp_umem *umem;
void *addrs; void *addrs;
struct device *dev;
struct net_device *netdev;
struct list_head xsk_tx_list;
/* Protects modifications to the xsk_tx_list */
spinlock_t xsk_tx_list_lock;
refcount_t users;
struct work_struct work;
struct xdp_buff_xsk *free_heads[]; struct xdp_buff_xsk *free_heads[];
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment