Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1179164rda; Mon, 23 Oct 2023 05:15:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsP/LO4PxqU6LHIf0k+RxHmCd0MTjtCQ3wrF2duZomcotIRaR8kj2xL4RMSMtX3Ffr+rxE X-Received: by 2002:a05:6a00:170d:b0:690:3b59:cc7a with SMTP id h13-20020a056a00170d00b006903b59cc7amr10862353pfc.23.1698063353944; Mon, 23 Oct 2023 05:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698063353; cv=none; d=google.com; s=arc-20160816; b=g9g3Geqoggf3V18j1S5DPgaqlzs7GRIUgrFfDh+Z3mayCcYMiOT+E3mLlg39ZSnuzC uZzLwaLt5EQpueYE0CAA8rHm3Xm+aDgUUCIHBB/QIEBAmzFXnRZrRe02tXgUrIR5aAct 54I5ar8nEIQQHc6HzsAcFq7Ug02KQkmxC7muJ9OOYDPTJ7oKpo9qToyx6FP2EBywzDg8 0fFpU6FlY21oYThshbxvvT6QkZ/89ZhzOF3v/BinibAoXjfn/ZLEzMNzdRv963SF2zf7 X+IDNp8t2d/7iE9r01s119LrrJYAJCQv/yqjQfDL6Rk/lIxmlmkLFtDfl7NEu4+NtESO Y7kg== 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=Day2LqITeqqQW3ubQWwhseOl/p+ZLKwUgz19cu93VSU=; fh=tywo+hBrtWN+PebR31QRA0AfpeQOTeFD2coCqRo6Zk0=; b=k1GmclcMiClffRMsdZhjPjnqSO+8V2W97i7bYJYHqIsJjfxkdDlOTj7JZlZVbPWb9U pcIJyper6h5LWrUzuWOdlCBKJ1Fww8bAMOyMS1AqcKof0DKILQcPcy3yI6a+CAZkx0jn oQMm26I+SZI93RAdhjTl9rWVL/xXGPKXT+DZaBn03Yu2MMIr8FPejIbqb4y4QTg15N69 ppRkFxByWAZ6VlloeclAMqDb0SLAuYuBsZY+ZPRu557uoz+SpYGNP8uXI2750HjgZWq7 pQ38oKlbATR+m1cyQmyKcS56H0OzYBhonJva6h289baN7/uhnnCHs1NetK10pLegOlKN Dfdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Sxv7rNCf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id fc23-20020a056a002e1700b006bf1f9bb8besi5899631pfb.365.2023.10.23.05.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 05:15:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Sxv7rNCf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B42438084634; Mon, 23 Oct 2023 05:15:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjJWMPZ (ORCPT + 99 others); Mon, 23 Oct 2023 08:15:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjJWMPX (ORCPT ); Mon, 23 Oct 2023 08:15:23 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B50EFF9; Mon, 23 Oct 2023 05:15:20 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-637aaaf27f1so3823596d6.0; Mon, 23 Oct 2023 05:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698063320; x=1698668120; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Day2LqITeqqQW3ubQWwhseOl/p+ZLKwUgz19cu93VSU=; b=Sxv7rNCfq2eafYNM31bCc7WnMe54201eXGTTd1Z+VBzTsO4w7utdcONore4Y2TM82T E/0b0Jnb2C7e8p5VpV3x+aMdW66DvGem2uvG1cNFD6LKq34cXADeJjyA/Va80Q4bakTI rP/XWrd2yt3RUTBwffKBEFcKopIFyrikwGo8ADnTLwnzwqrQkJXnIdZ+101ug26rI5xb LtkZDQSDxSmLm4hdiDkYl4t8pel1aU334xEmnSDct5/uSEJUXfcNA0Y7gZ8AyADCq/pN X4B/mhVRfqdQnw8SWpyDHuUGmY6t1J7t+tCfa1Q1cGGcv3qC8H+2DAukaThpgza01W2V 7TZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698063320; x=1698668120; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Day2LqITeqqQW3ubQWwhseOl/p+ZLKwUgz19cu93VSU=; b=Z3E79Yrqh/hn4kyhPLD3aNp0MSgqVOp96GOVdNVQmIRBW4e2rWKaeUupfCi42TQsIB vkQhEweEv/0RHZhiIOMfQpV4nF0Fxz5He1nP2jgz8XgKvzc3xKyOKzVbp5QraUm+Viu2 HR2U1/9kB9NQAQpofxMDt9F/oTyImtlPtBmzWLBDeRgYqcK4o0hT6cbdVcuxLBj5kF14 6sbSxgApfy9BA0/Zh0NmfBEyFvUSJvpAX7uYNFG5yygSKAzvG5Q8u8kb5vW9MUt6d5TP /DzzveEtuKYZdhjSnsZPHFFXTS5uZ29Ucqgj0C0hhXs2Vv5XVv0bUxVYmin5ziCcC/4t gQbQ== X-Gm-Message-State: AOJu0Yx6ngGMRleyEHjM9GTXo83tpFvH9vF+4z1zYwst/Jv0TKfPHPFn bFF8PGyStR7gD8CoA8t3IgJEWXTYGfu/tatyIP0= X-Received: by 2002:a05:6214:d0e:b0:668:e12a:1d1c with SMTP id 14-20020a0562140d0e00b00668e12a1d1cmr9271368qvh.3.1698063319769; Mon, 23 Oct 2023 05:15:19 -0700 (PDT) MIME-Version: 1.0 References: <20231023115255.76934-1-huangjie.albert@bytedance.com> In-Reply-To: <20231023115255.76934-1-huangjie.albert@bytedance.com> From: Magnus Karlsson Date: Mon, 23 Oct 2023 14:15:08 +0200 Message-ID: Subject: Re: [PATCH v3 net-next] xsk: avoid starving the xsk further down the list To: Albert Huang Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 05:15:38 -0700 (PDT) On Mon, 23 Oct 2023 at 13:53, Albert Huang wrote: > > In the previous implementation, when multiple xsk sockets were > associated with a single xsk_buff_pool, a situation could arise > where the xsk_tx_list maintained data at the front for one xsk > socket while starving the xsk sockets at the back of the list. > This could result in issues such as the inability to transmit packets, > increased latency, and jitter. To address this problem, we introduced we introduced -> introduce > a new variable called tx_budget_cache, which limits each xsk to transmit > a maximum of MAX_PER_SOCKET_BUDGET tx descriptors. This allocation ensures > equitable opportunities for subsequent xsk sockets to send tx descriptors. > The value of MAX_PER_SOCKET_BUDGET is temporarily set to TX_BATCH_SIZE(32). It is not temporary I hope ;-). Just say "The value of MAX_PER_SOCKET_BUDGET is set to 32." > > Signed-off-by: Albert Huang > --- > include/net/xdp_sock.h | 5 +++++ > net/xdp/xsk.c | 19 +++++++++++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h > index 69b472604b86..08cbdf6fca85 100644 > --- a/include/net/xdp_sock.h > +++ b/include/net/xdp_sock.h > @@ -63,6 +63,11 @@ struct xdp_sock { > > struct xsk_queue *tx ____cacheline_aligned_in_smp; > struct list_head tx_list; > + /* Record the actual number of times xsk has transmitted a tx > + * descriptor, with a maximum limit not exceeding MAX_PER_SOCKET_BUDGET > + */ > + u32 tx_budget_cache; Since this is not a cache, I would prefer a name like tx_budget_spent. Reflects more what the purpose is of this variable. Do not forget to change this in the commit message too. > + > /* Protects generic receive. */ > spinlock_t rx_lock; > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index f5e96e0d6e01..fd0d54b7c046 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -33,6 +33,7 @@ > #include "xsk.h" > > #define TX_BATCH_SIZE 32 > +#define MAX_PER_SOCKET_BUDGET (TX_BATCH_SIZE) > > static DEFINE_PER_CPU(struct list_head, xskmap_flush_list); > > @@ -413,16 +414,25 @@ EXPORT_SYMBOL(xsk_tx_release); > > bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) > { > + bool xsk_cache_full = false; Same comment here, it is not a cache. How about just budget_exhausted? No need for the xsk_ since this is a local variable. > struct xdp_sock *xs; > > rcu_read_lock(); > +again: > list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { > + if (xs->tx_budget_cache >= MAX_PER_SOCKET_BUDGET) { > + xsk_cache_full = true; > + continue; > + } > + > if (!xskq_cons_peek_desc(xs->tx, desc, pool)) { > if (xskq_has_descs(xs->tx)) > xskq_cons_release(xs->tx); > continue; > } > > + xs->tx_budget_cache++; > + > /* This is the backpressure mechanism for the Tx path. > * Reserve space in the completion queue and only proceed > * if there is space in it. This avoids having to implement > @@ -436,6 +446,14 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) > return true; > } > > + if (xsk_cache_full) { > + list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { > + xs->tx_budget_cache = 0; > + } No need for the {} here since there is only a single line in the loop. Please remove them. > + xsk_cache_full = false; > + goto again; > + } > + > out: > rcu_read_unlock(); > return false; > @@ -1230,6 +1248,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) > xs->zc = xs->umem->zc; > xs->sg = !!(xs->umem->flags & XDP_UMEM_SG_FLAG); > xs->queue_id = qid; > + xs->tx_budget_cache = 0; This is not needed. The struct is zeroed at allocation. > xp_add_xsk(xs->pool, xs); > > out_unlock: > -- > 2.20.1 > >