Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1766426rda; Tue, 24 Oct 2023 02:36:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgdwxQt9Q3KsV+b9avn4DL6UiJLUzWZiha9estoMC2LobhBFYTs7ZwS1ivnSr3iX2ORBAs X-Received: by 2002:a17:902:ecc6:b0:1ca:72f9:2547 with SMTP id a6-20020a170902ecc600b001ca72f92547mr9314933plh.66.1698140188376; Tue, 24 Oct 2023 02:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698140188; cv=none; d=google.com; s=arc-20160816; b=dwo/Ebf/5CDgjGShkptHTN3PtoCO3Kz3CC2Fr1f9P7EDn+MlU/f4AkyEcHrknylgfO bHEQjRKKmw/eAh30MwI20ycn1ybRHQb2VOaqhvNduoxEPwNBQk22iuD/U0acJUHFNaoU nZ3n4wciE/LCKKHZJkLyT6b0IuFmRzljh6E9FEpBs3my5F3FHslw0BYHvZoxdNgZ2lUh kDTdDSquCkNWob1UYoQR7nYFiW+1EIEzS7lQQkU50klGZGIkTuCe3tl5Txo64B+M8wnn JDW2HtCOZl075U/KuLHzVR1+fkkTNdsP5/3d4lZLjIPawnctxeLzsMO+fG9SBGuoCLhK otcA== 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=hnpIQUPDm6Zq9acYBDFChtR53+u4G5h2VpvaQkr0GYM=; fh=tywo+hBrtWN+PebR31QRA0AfpeQOTeFD2coCqRo6Zk0=; b=Lt4Tnr//dIhM1gvEM68AwE8Ry1uN1oV/+6IOfD6DZmq5jiJYDwrFTfBCzfXS7PZL1N 3WgRCU51CTA2xBtXhpby9G5+AE82h4o/+zceqSspJ+b8no4wQ7p+oDxNHEPLtskLthMa TvsPVPd5soOXiYrJGQ7GRc6SH2d6EqGDWyUl59iE1bfjDcBUBKF8VhADLFkAs7YnWNwz 2pJx3EjIE4gFLwU3ddzeKCJxyRRLKv8dIQEJBtytazlnQeCaXCAIRYsUtLmdmv/u53MO gzGNobxu0Z56TjLmWWPNYrkn+Tlm6luFlqjuTuuww4IlRFp0r99u3PFeKkD6SyEUmlxO KwtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=frfKjSUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id d6-20020a170903230600b001c75866c987si8265006plh.584.2023.10.24.02.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:36:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=frfKjSUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id C56088034A9C; Tue, 24 Oct 2023 02:35:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234186AbjJXJej (ORCPT + 99 others); Tue, 24 Oct 2023 05:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234509AbjJXJeF (ORCPT ); Tue, 24 Oct 2023 05:34:05 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46817268B; Tue, 24 Oct 2023 02:33:45 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-66d32cc3957so10279286d6.0; Tue, 24 Oct 2023 02:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698140024; x=1698744824; 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=hnpIQUPDm6Zq9acYBDFChtR53+u4G5h2VpvaQkr0GYM=; b=frfKjSUqUdTV5sRBaJz3JxpC2w6xamMceVamFKuM8LzSN87o1yuW2ZQf52RmocKYr0 c0vX0PZW1DtIZpPPicxk4o1LEmcM/fiybITqugE2f6Qxl4OG/KQVo4HEuAyCbMUaK+WP hduOhOIE4mI5ftzYym+e9L18WFt6FlEVs7p6k2FfHQgWuJRn9/rLom9dSdXZ639175xb PjaLi0I61BHrzUXGtKVP0edfgocgV99ZY7JVWeU5WCWwCEat2sXfWf0D851L0KW9kQdf /mo8ea0BY1RYWaEhAXrP/FgLMj1jhdni1BuPVyvJqFIFCQXtqqPDGTNyZk4liiWm/WmV +RyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698140024; x=1698744824; 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=hnpIQUPDm6Zq9acYBDFChtR53+u4G5h2VpvaQkr0GYM=; b=J3HBmVxhDPePwFUYroUvaI++noXalaPwStkW8oYtHD8OlgVreVl7qrGXMhsEOjSfOp G5WYBnoEKsAba/sjF2jVabryFAAV3QPeXaRkAm1qkoemExlWtKGHROJU5dmwWYgyHzLo 58kVsk+YwZxqbaQ5l3c6j8PRM4rKu9ltPH94ZKK6RyxLTHW7h8Wlcu8dK4MVGIVCZtoC T55TqUv37v+CR0fIOGNOO7au9sbDN8aj4ASx1D4igAUzI6QjEzG+PeI0ZFhHiLRZZ2so 8YpOFoqx7x3I5a5oSyKbBxqeG8O9uHiIC88WLf0InqyxQ2W7hhep9+be+ugZdgJ8oOpt BK0g== X-Gm-Message-State: AOJu0YzGKaOkJirNPqliDDWgmWJwOaWLrDpqIaSTn6K7o4RA0CmGNZ+r npcDdfPfQEk1Yndm2J1hS3kzizAuNv0yS5Zvuys= X-Received: by 2002:a05:6214:2dc8:b0:65d:486:25c6 with SMTP id nc8-20020a0562142dc800b0065d048625c6mr12536219qvb.3.1698140024285; Tue, 24 Oct 2023 02:33:44 -0700 (PDT) MIME-Version: 1.0 References: <20231023125732.82261-1-huangjie.albert@bytedance.com> In-Reply-To: <20231023125732.82261-1-huangjie.albert@bytedance.com> From: Magnus Karlsson Date: Tue, 24 Oct 2023 11:33:33 +0200 Message-ID: Subject: Re: [PATCH v4 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:35:06 -0700 (PDT) On Mon, 23 Oct 2023 at 14:57, 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 introduce > a new variable called tx_budget_spent, 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 set to 32. Thank you Albert for implementing this feature! Acked-by: Magnus Karlsson > Signed-off-by: Albert Huang > --- > include/net/xdp_sock.h | 7 +++++++ > net/xdp/xsk.c | 18 ++++++++++++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h > index 69b472604b86..de6819e50d54 100644 > --- a/include/net/xdp_sock.h > +++ b/include/net/xdp_sock.h > @@ -63,6 +63,13 @@ struct xdp_sock { > > struct xsk_queue *tx ____cacheline_aligned_in_smp; > struct list_head tx_list; > + /* record the number of tx descriptors sent by this xsk and > + * when it exceeds MAX_PER_SOCKET_BUDGET, an opportunity needs > + * to be given to other xsks for sending tx descriptors, thereby > + * preventing other XSKs from being starved. > + */ > + u32 tx_budget_spent; > + > /* Protects generic receive. */ > spinlock_t rx_lock; > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index f5e96e0d6e01..65c32b85c326 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 budget_exhausted = false; > struct xdp_sock *xs; > > rcu_read_lock(); > +again: > list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { > + if (xs->tx_budget_spent >= MAX_PER_SOCKET_BUDGET) { > + budget_exhausted = 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_spent++; > + > /* 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 (budget_exhausted) { > + list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) > + xs->tx_budget_spent = 0; > + > + budget_exhausted = false; > + goto again; > + } > + > out: > rcu_read_unlock(); > return false; > -- > 2.20.1 > >