Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp956199pxu; Wed, 2 Dec 2020 07:33:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9xHFGPMQZPc8VGiVCmYDEpbf0pTT1LP+S7JIiFMVutHorQbH+8pdkeQa5CVCCX3L6u86G X-Received: by 2002:a05:6402:310f:: with SMTP id dc15mr411189edb.225.1606923205318; Wed, 02 Dec 2020 07:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606923205; cv=none; d=google.com; s=arc-20160816; b=MybRP7nIn82fKBhyYbjBdJ4wTud2jrAztTEi6BDAFaSyDqpzsYx3PbAOzXZ2hUcRNV SQW4qxxLU9N5/o4Z5TKHyv+2eqfjDX7M/iLzJwZ0FL78aF1IDR9OFwcOk5Oq6urejaAi gU3ZTLP2Jxq9TseRgtZzoevAM8LZRJSuz4xwgfzFoNQU8VCx/651j/TyVy8Th0WLCNv2 SMqCCUz5D3AlajS30h1PK5UGDkftSGRlVCp4ZhBPhzU+yUCzK8cA/D+Xitr1WFjk1lba Mc60hLbijEsoCRMZZF/NszecrVwSfzxVkYmWKUvc7Rtp432iBLAsswU3ReizK44HIoUs 4eVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mwTSpTZUymq3kHcr9Nu1z8YQRX/L7YbJh3Ulw0Y/ks8=; b=Y0Wf0o4SHGPhLyAKd/0iSowqArkUZGZkXyrBIq5iPiz9I0x9+pX6oHZeW5G4pw19Cf kh3jYxqPOV9oRrqm1OX0Lo3pDiIXxW6G6Tp80iaStU/v2Xpw0mXCcrlhqtNMYytEgDfs Qp5j7XJqOD19P2+PGWgC0sFBjELxFlH2qWFT21+hhtYF3fchkK3SMITdDj/2GsKR+UBY ZrMJRheIxpt4WsdiPephUlcIgePgV/oLHIer5XaZEm+5s5jpnlff4keJEVaLWS6I5eu2 hSNQPPkfG7tTsHQoULLyAtE/jQGqaIU7a06bnZPxHdFv8Gvbb2R+KGl3o0OFojbdd3GH slmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AVpHvyVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si160792ejc.625.2020.12.02.07.33.01; Wed, 02 Dec 2020 07:33:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AVpHvyVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728295AbgLBPbG (ORCPT + 99 others); Wed, 2 Dec 2020 10:31:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbgLBPbF (ORCPT ); Wed, 2 Dec 2020 10:31:05 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4BCC0613D4; Wed, 2 Dec 2020 07:30:19 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id f17so1281173pge.6; Wed, 02 Dec 2020 07:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mwTSpTZUymq3kHcr9Nu1z8YQRX/L7YbJh3Ulw0Y/ks8=; b=AVpHvyVmPS6PvURO4TNoOS+xkJTKN4J89fiERyhK3zbr4LLuhBI90TR4TyRhgNACAY Ykk6JRil3aQUc5rijqCv+RvgYFGj03GjNyjq8SnzOaUxjFH5xFG+kCoDCoA2Hj2XchlG 4yAh/RR/8ziZiD/emSe42+Y4i3N20MwpcA1xpD1ZT8HDa6Dav8vCCJly79foL9XX0CoW SFGK6iKHavpRXdCMw8WZytNeSIlztaPPhMB8dnQjiBmfU2R3VSU6xjTVYH7W/pwr1VVT d0SiG6hmYmwqq86ENfOPaHqiEIiy/t9QZ0bXWqH34SdsR7wqFOIY+Y/c9PREceZpwuno CJyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mwTSpTZUymq3kHcr9Nu1z8YQRX/L7YbJh3Ulw0Y/ks8=; b=Rg+ZjXq+5sMtCtskEzEsz4x+jvJeyJjMVw1+AR3oaXGmnAJWySsjrpuhDVDeU0X135 B79meZvywkCwPwVT5Jf/VM3mJD3garX0HJIwjz7CCxZ20J0Gad0lDPRBLdnQ7hf/u1Zw 8pB4CvNANwmCy1qFuIkS6vsWOAGpDyOWRKR8yFBpTOsnKXQnGBlBy0J1P7VmEPfogvWJ UbOd/VTEi3M9zi+vqm9/DmhHG20oQJATYcEzU9yxtz00CD32cyoE8XT8xN1RoWAW8fSb XkhS6VTBNeDCpM9gGtqJC0ODokjUJ9S7TtXYpsk0F4T8yeKJnQ8+dVndQLJp+RHUOFIk f5GA== X-Gm-Message-State: AOAM531jLY9nPnQnipvEsbTym0T0A0YK8/cPPgVJotAI7ZxFM2nG0eH+ 4q65bkRPWivWYV22394fmcOfRz719wykk6oFAOI= X-Received: by 2002:a63:ee0f:: with SMTP id e15mr369788pgi.292.1606923018036; Wed, 02 Dec 2020 07:30:18 -0800 (PST) MIME-Version: 1.0 References: <508fef55188d4e1160747ead64c6dcda36735880.1606555939.git.xuanzhuo@linux.alibaba.com> In-Reply-To: <508fef55188d4e1160747ead64c6dcda36735880.1606555939.git.xuanzhuo@linux.alibaba.com> From: Magnus Karlsson Date: Wed, 2 Dec 2020 16:30:07 +0100 Message-ID: Subject: Re: [PATCH bpf V3 2/2] xsk: change the tx writeable condition To: Xuan Zhuo Cc: "Karlsson, Magnus" , Daniel Borkmann , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Jonathan Lemon , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , "open list:XDP SOCKETS (AF_XDP)" , "open list:XDP SOCKETS (AF_XDP)" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 1, 2020 at 2:59 PM Xuan Zhuo wrote: > > 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. And the Fixes label here should be: Fixes: 35fcde7f8deb ("xsk: support for Tx") > Signed-off-by: Xuan Zhuo > Acked-by: Magnus Karlsson > --- > net/xdp/xsk.c | 16 +++++++++++++--- > net/xdp/xsk_queue.h | 6 ++++++ > 2 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index 9bbfd8a..6250447 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -211,6 +211,14 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len, > return 0; > } > > +static bool xsk_tx_writeable(struct xdp_sock *xs) > +{ > + if (xskq_cons_present_entries(xs->tx) > xs->tx->nentries / 2) > + return false; > + > + return true; > +} > + > static bool xsk_is_bound(struct xdp_sock *xs) > { > if (READ_ONCE(xs->state) == XSK_BOUND) { > @@ -296,7 +304,8 @@ void xsk_tx_release(struct xsk_buff_pool *pool) > rcu_read_lock(); > list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { > __xskq_cons_release(xs->tx); > - xs->sk.sk_write_space(&xs->sk); > + if (xsk_tx_writeable(xs)) > + xs->sk.sk_write_space(&xs->sk); > } > rcu_read_unlock(); > } > @@ -436,7 +445,8 @@ static int xsk_generic_xmit(struct sock *sk) > > out: > if (sent_frame) > - sk->sk_write_space(sk); > + if (xsk_tx_writeable(xs)) > + sk->sk_write_space(sk); > > mutex_unlock(&xs->mutex); > return err; > @@ -493,7 +503,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock, > > if (xs->rx && !xskq_prod_is_empty(xs->rx)) > mask |= EPOLLIN | EPOLLRDNORM; > - if (xs->tx && !xskq_cons_is_full(xs->tx)) > + if (xs->tx && xsk_tx_writeable(xs)) > mask |= EPOLLOUT | EPOLLWRNORM; > > return mask; > diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h > index cdb9cf3..9e71b9f 100644 > --- a/net/xdp/xsk_queue.h > +++ b/net/xdp/xsk_queue.h > @@ -264,6 +264,12 @@ static inline bool xskq_cons_is_full(struct xsk_queue *q) > q->nentries; > } > > +static inline u32 xskq_cons_present_entries(struct xsk_queue *q) > +{ > + /* No barriers needed since data is not accessed */ > + return READ_ONCE(q->ring->producer) - READ_ONCE(q->ring->consumer); > +} > + > /* Functions for producers */ > > static inline bool xskq_prod_is_full(struct xsk_queue *q) > -- > 1.8.3.1 >