Skip to content

Commit cc7ca17

Browse files
fengidrikernel-patches-bot
authored andcommitted
xsk: change the tx writeable condition
Modify the tx writeable condition from the queue is not full to the number of remaining tx queues is less than the half of the total number of queues. Because the tx queue not full is a very short time, this will cause a large number of EPOLLOUT events, and cause a large number of process wake up. Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
1 parent fcb818f commit cc7ca17

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

net/xdp/xsk.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len,
211211
return 0;
212212
}
213213

214+
static bool xsk_writeable(struct xdp_sock *xs)
215+
{
216+
if (!xs->tx)
217+
return false;
218+
219+
if (xskq_cons_left(xs->tx) > xs->tx->nentries / 2)
220+
return false;
221+
222+
return true;
223+
}
224+
214225
static bool xsk_is_bound(struct xdp_sock *xs)
215226
{
216227
if (READ_ONCE(xs->state) == XSK_BOUND) {
@@ -296,7 +307,8 @@ void xsk_tx_release(struct xsk_buff_pool *pool)
296307
rcu_read_lock();
297308
list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) {
298309
__xskq_cons_release(xs->tx);
299-
xs->sk.sk_write_space(&xs->sk);
310+
if (xsk_writeable(xs))
311+
xs->sk.sk_write_space(&xs->sk);
300312
}
301313
rcu_read_unlock();
302314
}
@@ -442,7 +454,8 @@ static int xsk_generic_xmit(struct sock *sk)
442454

443455
out:
444456
if (sent_frame)
445-
sk->sk_write_space(sk);
457+
if (xsk_writeable(xs))
458+
sk->sk_write_space(sk);
446459

447460
mutex_unlock(&xs->mutex);
448461
return err;
@@ -499,7 +512,8 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
499512

500513
if (xs->rx && !xskq_prod_is_empty(xs->rx))
501514
mask |= EPOLLIN | EPOLLRDNORM;
502-
if (xs->tx && !xskq_cons_is_full(xs->tx))
515+
516+
if (xsk_writeable(xs))
503517
mask |= EPOLLOUT | EPOLLWRNORM;
504518

505519
return mask;

net/xdp/xsk_queue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ static inline bool xskq_cons_is_full(struct xsk_queue *q)
264264
q->nentries;
265265
}
266266

267+
static inline __u64 xskq_cons_left(struct xsk_queue *q)
268+
{
269+
/* No barriers needed since data is not accessed */
270+
return READ_ONCE(q->ring->producer) - READ_ONCE(q->ring->consumer);
271+
}
272+
267273
/* Functions for producers */
268274

269275
static inline bool xskq_prod_is_full(struct xsk_queue *q)

0 commit comments

Comments
 (0)