Skip to content

Commit d092738

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 present 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 f585daa commit d092738

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

net/xdp/xsk.c

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

214+
static bool xsk_tx_writeable(struct xdp_sock *xs)
215+
{
216+
if (xskq_cons_present_entries(xs->tx) > xs->tx->nentries / 2)
217+
return false;
218+
219+
return true;
220+
}
221+
214222
static bool xsk_is_bound(struct xdp_sock *xs)
215223
{
216224
if (READ_ONCE(xs->state) == XSK_BOUND) {
@@ -296,7 +304,8 @@ void xsk_tx_release(struct xsk_buff_pool *pool)
296304
rcu_read_lock();
297305
list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) {
298306
__xskq_cons_release(xs->tx);
299-
xs->sk.sk_write_space(&xs->sk);
307+
if (xsk_tx_writeable(xs))
308+
xs->sk.sk_write_space(&xs->sk);
300309
}
301310
rcu_read_unlock();
302311
}
@@ -436,7 +445,8 @@ static int xsk_generic_xmit(struct sock *sk)
436445

437446
out:
438447
if (sent_frame)
439-
sk->sk_write_space(sk);
448+
if (xsk_tx_writeable(xs))
449+
sk->sk_write_space(sk);
440450

441451
mutex_unlock(&xs->mutex);
442452
return err;
@@ -493,7 +503,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
493503

494504
if (xs->rx && !xskq_prod_is_empty(xs->rx))
495505
mask |= EPOLLIN | EPOLLRDNORM;
496-
if (xs->tx && !xskq_cons_is_full(xs->tx))
506+
if (xs->tx && xsk_tx_writeable(xs))
497507
mask |= EPOLLOUT | EPOLLWRNORM;
498508

499509
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_present_entries(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)