Skip to content

Commit 6b229cf

Browse files
Eric Dumazetdavem330
authored andcommitted
udp: add batching to udp_rmem_release()
If udp_recvmsg() constantly releases sk_rmem_alloc for every read packet, it gives opportunity for producers to immediately grab spinlocks and desperatly try adding another packet, causing false sharing. We can add a simple heuristic to give the signal by batches of ~25 % of the queue capacity. This patch considerably increases performance under flood by about 50 %, since the thread draining the queue is no longer slowed by false sharing. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c84d949 commit 6b229cf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/linux/udp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ struct udp_sock {
7979
int (*gro_complete)(struct sock *sk,
8080
struct sk_buff *skb,
8181
int nhoff);
82+
83+
/* This field is dirtied by udp_recvmsg() */
84+
int forward_deficit;
8285
};
8386

8487
static inline struct udp_sock *udp_sk(const struct sock *sk)

net/ipv4/udp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,20 @@ int udp_sendpage(struct sock *sk, struct page *page, int offset,
11771177
/* fully reclaim rmem/fwd memory allocated for skb */
11781178
static void udp_rmem_release(struct sock *sk, int size, int partial)
11791179
{
1180+
struct udp_sock *up = udp_sk(sk);
11801181
int amt;
11811182

1183+
if (likely(partial)) {
1184+
up->forward_deficit += size;
1185+
size = up->forward_deficit;
1186+
if (size < (sk->sk_rcvbuf >> 2) &&
1187+
!skb_queue_empty(&sk->sk_receive_queue))
1188+
return;
1189+
} else {
1190+
size += up->forward_deficit;
1191+
}
1192+
up->forward_deficit = 0;
1193+
11821194
atomic_sub(size, &sk->sk_rmem_alloc);
11831195
sk->sk_forward_alloc += size;
11841196
amt = (sk->sk_forward_alloc - partial) & ~(SK_MEM_QUANTUM - 1);

0 commit comments

Comments
 (0)