[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220406114807.1803-1-lianglixue@greatwall.com.cn>
Date: Wed, 6 Apr 2022 11:48:07 +0000
From: lianglixue <lixue.liang5086@...il.com>
To: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com
Cc: edumazet@...gle.com, pablo@...filter.org, rsanger@...d.net.nz,
yajun.deng@...ux.dev, jiapeng.chong@...ux.alibaba.com,
netdev@...r.kernel.org, lianglixue <lianglixue@...atwall.com.cn>
Subject: [PATCH] af_packet: fix efficiency issues in packet_read_pending
In packet_read_pengding, even if the pending_refcnt of the first CPU
is not 0, the pending_refcnt of all CPUs will be traversed,
and the long delay of cross-cpu access in NUMA significantly reduces
the performance of packet sending; especially in tpacket_destruct_skb.
When pending_refcnt is not 0, it returns without counting the number of
all pending packets, which significantly reduces the traversal time.
Signed-off-by: lianglixue <lianglixue@...atwall.com.cn>
---
net/packet/af_packet.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c39c09899fd0..c04f49e44a33 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1210,17 +1210,18 @@ static void packet_dec_pending(struct packet_ring_buffer *rb)
static unsigned int packet_read_pending(const struct packet_ring_buffer *rb)
{
- unsigned int refcnt = 0;
int cpu;
/* We don't use pending refcount in rx_ring. */
if (rb->pending_refcnt == NULL)
return 0;
- for_each_possible_cpu(cpu)
- refcnt += *per_cpu_ptr(rb->pending_refcnt, cpu);
+ for_each_possible_cpu(cpu) {
+ if (*per_cpu_ptr(rb->pending_refcnt, cpu) != 0)
+ return 1;
+ }
- return refcnt;
+ return 0;
}
static int packet_alloc_pending(struct packet_sock *po)
--
2.27.0
Powered by blists - more mailing lists