From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796568305; b=EvEpWSWFd+6rHxKzXgQeDu+qZnKOyaQYIKXKiEw5A/R0/0W8mQooMJcCIE0SEcyWvm0G lG7FfXu6pDdeS9GsfkYmTH85CUpYJ0qpKu7JOF9L89XkQPbfE78ANnFV8ZshmDRaxilJ/ +WeZPlZkAvzQoePmGN4hrGXi1aXcFaAOSIMi9XUnii3uEB3lvUUPqc9O8zfJkuZmbB3PM 4oYkf7fX8IJ9vBAwPgRYcdQps26Yd+FbphwNfBEvhOOGa7r7fMqyII8NyaMx540WJwtGV MtsfkUX+KweksvyAItSFNAgyNUA1iahWoVtV50nnAjA+qnwveKQTFuePDF8H6BfRSBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796568305; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=Rw1muBkFfCV2fczlnnCOx6egxwRhutcP69ewaysRgXk=; b=DKWuI5We6UIMWRcezPidQYqJSOtoB9ohgMlMp1c5n2MV00XeFUWsDOs6rqlYEq66i/PP z+jVfGAbmgK+n1SRgPws2/w04Y3g+77fbY68uLIwlZ0LVFsGsZce4IVeVPZWJgp5VLPea i78cDeqZ4xdaOWQdv5PUVbo/l00VHLbbkUDTnx3js8+HrJ2BjQsov7TfwpNb9aeNKOqjY nm4rJhSQNaxyGCX1OuKC2AYWT59GW0OJXdbEdmlYkhgvjC1ir51dVzlRtb4AMzVbq1kBe I9bvSyqooZegcGDlOalu4zywGbSOItdLTbnnJ5IHzi3ptCJET8F/uZwbkgMjmxldh+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YIJaSkxs; arc=none smtp.remote-ip=74.125.82.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D869606A324 for ; Sun, 6 Dec 2026 14:45:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D869606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YIJaSkxs Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-38190551625so3061817eec.1 for ; Sun, 06 Dec 2026 06:45:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796568304; x=1797173104; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Rw1muBkFfCV2fczlnnCOx6egxwRhutcP69ewaysRgXk=; b=YIJaSkxs9YZoevnuDJhketDlpkNLfP4JFiT4mTdOUNo3W4ZJDGeHhMrFRHAFR79wdQ F+7odBzewCoxVOtivUPfd5v7WfBxt16zdEDWYhtVVJqpW2/3kNw79oTKSB4os+VWvuw0 X6Y3fM9w7flN8Uf12TbPxlVWV/AFIDum6HQTYHVJstz71G+0l2PQkazDBOBVveqgbEK+ ij7l0OuPnWpfF4qhnZnlRO95w3V1K81PKrzIKs5RWXJwAfQtuJmlobI2J5MnuC0ZJ1Ch KiOdhF3GV2kbvCiin0mAHfgxQiiWFuNQfAzVeM+WVIkj+gaTCo/6dZT/egstu94ltktF ssvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796568304; x=1797173104; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Rw1muBkFfCV2fczlnnCOx6egxwRhutcP69ewaysRgXk=; b=ioDUE6WhM9+x5mestQK8ALtHhV/VB4b2mZlopkNBW9rnTBZ88faYQIvrU2YyDV19cf Hro+Up3sM55i4u08LS/USa8/bnWO0Sn4CYEXriCDcRfAHmzuDlx6rYHXmOy6Xxqx6NhQ 3Dkmrjmk34OPZndlf9MQEQj5LHdNy+c8fX/6QqavfpQq5hytTIDrdymXdRW9jRZvi7ln SFBFy9s5YSo3YnImtLO4wVtOM1OxAcTEJDs7oY4fg9ovRXX3/1JIiXQy0pB9QATY/5c5 VwgvEBlklb415TADv+Ir8rkBqFXYI/nKUzbHz2HjwxoyuROJcw6kbn8AHqnjcZXCQSlb kiow== X-Forwarded-Encrypted: i=1; AL+hErHRVwt/09ezoh/nU/9J1QPq5CG2odqz0SBTY8Mw4ZlBdxNSpkU0MZGhY0ylYXkZeQKxfM6KbdDTaFlewks=@vger.kernel.org X-Gm-Message-State: AB4q+uHuNiMWbkHDpBbndcWI7/h/6uHrk+6GYSXTFxCNlytZafcYdD2G frj17SkXjFG1FelIzRX0ocKhtb4JarFfOPeKpdNsgw5glmgUdmfBDjce X-Gm-Gg: AZFdTZdFfmuslKwxwcMf/GimDdaHJiaM4A8YPiCDfKf8bJQaH9Xou1TE6ScRaJeWG5/ kxhbtI7/MUSyVaZTIUtwJHShFeFAqPBqzuBMbdcF7LwzZCf73/7mFdP269KPLWvUufDsGt9pHDS kF3Ud1WR2ciZ2fgm0TbVgvWVsQMDq0Xc/45hhDEpRtYiKwfAenSAkQUxe790pLroZrD4pRyzHAu HZ3RfpJHFu1cV72oO8ZOSzdmwJYyz8HoVITqL3YnxoJP+zFJJp9cIk1/B4FGJIF29pu2xTj8SXX cFgcEnaHL5nX6uZTlhIQrFY3rnef3lg8izk7ZX1ZbsQpunJoQ1NZkPGECXrbG8YvDQ1mF3HHEoS 6y7wQ0tCMvqslx16doh+QCaFAgwutegZYVyHh/OYKiogJ0iF91AmIH/3Cz3n32UauZPLc6KraME ddzaGesjK0CyW8riv0wvjgJ7zDPXkm23uhhsun9Y9KDFOQDjQ6SI/ZVhcjXelqbFujx5kUMh05D x1DcZsX6uR2yNnJM6BVkF2W242LYosZGgkLGmz5Y81w3yb9GMYA7iRgQitUWXQZDibXRELPsGAv rHJlwf7L+Xo6waiFz67W79wSxQhi5/zKActEuxqMUiwBtcUK7qi8om0gtsnpC6qEG4cT7lYOn+8 pnOD3Gj/Rqu3hw/ROh4q68hGC2+Z6j3kld6I+J7JDOf/FHRvDtba9eG0PEMKs3bfxVgUS0467JD Q9Pfvy7jm+yaI= X-Received: by 2002:a05:7301:d806:b0:386:e571:4bb4 with SMTP id 5a478bee46e88-3875215ef99mr7865775eec.13.1796568304239; Sun, 06 Dec 2026 06:45:04 -0800 (PST) Received: from SeungJong-Mac-mini.local ([210.117.237.143]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e1c55sm28623252eec.16.2026.12.06.06.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 06:45:03 -0800 (PST) From: SeungJong Ha Date: Sun, 06 Dec 2026 23:44:44 +0900 Subject: [PATCH RFC net-next 3/5] net_sched: change tx_queue_len on all tx queues or on none X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261206-tc1-txqlen-commit-v1-3-ec9f34dce973@gmail.com> References: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> In-Reply-To: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Jamal Hadi Salim , Jiri Pirko , Andrew Lunn , Willem de Bruijn , Jason Wang Cc: "Michael S. Tsirkin" , John Fastabend , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, SeungJong Ha X-Mailer: b4 0.15.2 dev_qdisc_change_tx_queue_len() resizes the qdisc of each tx queue in turn and stops at the first failure, leaving the earlier queues with the new length: /* TODO: revert changes on a partial failure */ Reverting would need new allocations again. Instead, split ->change_tx_queue_len() in three: ->prepare_tx_queue_len() allocates the new rings and may fail ->commit_tx_queue_len() swaps them in ->abort_tx_queue_len() frees them Only prepare can fail. All tx queues are prepared before any is changed. The allocations now happen before the device is deactivated, so a failure no longer stops the queues at all. All tx queues hold their new rings at the same time until the commit, so a change needs more memory at once than before. pfifo_fast is the only qdisc implementing these callbacks. The patch was written with Claude Code (Claude Opus 5.5). Signed-off-by: SeungJong Ha --- include/linux/skb_array.h | 14 ++---- include/net/sch_generic.h | 5 +- net/sched/sch_generic.c | 115 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 101 insertions(+), 33 deletions(-) diff --git a/include/linux/skb_array.h b/include/linux/skb_array.h index bf178238a308..91fd1fab87f6 100644 --- a/include/linux/skb_array.h +++ b/include/linux/skb_array.h @@ -199,18 +199,14 @@ static inline int skb_array_resize(struct skb_array *a, int size, gfp_t gfp) return ptr_ring_resize(&a->ring, size, gfp, __skb_array_destroy_skb); } -static inline int skb_array_resize_multiple_bh_noprof(struct skb_array **rings, - int nrings, - unsigned int size, - gfp_t gfp) +static inline void skb_array_swap_queues_bh(struct skb_array **rings, + void ***queues, int nrings, + unsigned int size) { BUILD_BUG_ON(offsetof(struct skb_array, ring)); - return ptr_ring_resize_multiple_bh_noprof((struct ptr_ring **)rings, - nrings, size, gfp, - __skb_array_destroy_skb); + ptr_ring_swap_queues_bh((struct ptr_ring **)rings, queues, nrings, + size, __skb_array_destroy_skb); } -#define skb_array_resize_multiple_bh(...) \ - alloc_hooks(skb_array_resize_multiple_bh_noprof(__VA_ARGS__)) static inline void skb_array_cleanup(struct skb_array *a) { diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 1acaadb3e2cf..8e0e774844c2 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -326,7 +326,10 @@ struct Qdisc_ops { struct nlattr *arg, struct netlink_ext_ack *extack); void (*attach)(struct Qdisc *sch); - int (*change_tx_queue_len)(struct Qdisc *, unsigned int); + int (*prepare_tx_queue_len)(struct Qdisc *sch, + unsigned int new_len); + void (*commit_tx_queue_len)(struct Qdisc *sch); + void (*abort_tx_queue_len)(struct Qdisc *sch); void (*change_real_num_tx)(struct Qdisc *sch, unsigned int new_real_tx); diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index d2e0d20f3ba1..c7eb4ef5411f 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -804,9 +804,12 @@ EXPORT_SYMBOL(sch_default_prio2band); /* * Private data for a pfifo_fast scheduler containing: * - rings for priority bands + * - new rings for a tx_queue_len change, between prepare and commit */ struct pfifo_fast_priv { struct skb_array q[PFIFO_FAST_BANDS]; + void ***pending; + unsigned int pending_len; }; static inline struct skb_array *band2list(struct pfifo_fast_priv *priv, @@ -983,21 +986,53 @@ static void pfifo_fast_destroy(struct Qdisc *sch) } } -static int pfifo_fast_change_tx_queue_len(struct Qdisc *sch, - unsigned int new_len) +static int pfifo_fast_prepare_tx_queue_len(struct Qdisc *sch, + unsigned int new_len) +{ + struct pfifo_fast_priv *priv = qdisc_priv(sch); + + /* A root qdisc is attached to every tx queue of the device. */ + if (priv->pending) + return 0; + + priv->pending = ptr_ring_alloc_queues(PFIFO_FAST_BANDS, new_len, + GFP_KERNEL); + if (!priv->pending) + return -ENOMEM; + + priv->pending_len = new_len; + return 0; +} + +static void pfifo_fast_commit_tx_queue_len(struct Qdisc *sch) { struct pfifo_fast_priv *priv = qdisc_priv(sch); struct skb_array *bands[PFIFO_FAST_BANDS]; int prio; + if (!priv->pending) + return; + for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) { struct skb_array *q = band2list(priv, prio); bands[prio] = q; } - return skb_array_resize_multiple_bh(bands, PFIFO_FAST_BANDS, new_len, - GFP_KERNEL); + skb_array_swap_queues_bh(bands, priv->pending, PFIFO_FAST_BANDS, + priv->pending_len); + priv->pending = NULL; +} + +static void pfifo_fast_abort_tx_queue_len(struct Qdisc *sch) +{ + struct pfifo_fast_priv *priv = qdisc_priv(sch); + + if (!priv->pending) + return; + + ptr_ring_free_queues(priv->pending, PFIFO_FAST_BANDS); + priv->pending = NULL; } struct Qdisc_ops pfifo_fast_ops __read_mostly = { @@ -1010,7 +1045,9 @@ struct Qdisc_ops pfifo_fast_ops __read_mostly = { .destroy = pfifo_fast_destroy, .reset = pfifo_fast_reset, .dump = pfifo_fast_dump, - .change_tx_queue_len = pfifo_fast_change_tx_queue_len, + .prepare_tx_queue_len = pfifo_fast_prepare_tx_queue_len, + .commit_tx_queue_len = pfifo_fast_commit_tx_queue_len, + .abort_tx_queue_len = pfifo_fast_abort_tx_queue_len, .owner = THIS_MODULE, .static_flags = TCQ_F_NOLOCK | TCQ_F_CPUSTATS, }; @@ -1464,17 +1501,6 @@ void dev_deactivate(struct net_device *dev, bool reset_needed) } EXPORT_SYMBOL(dev_deactivate); -static int qdisc_change_tx_queue_len(struct net_device *dev, - struct netdev_queue *dev_queue) -{ - struct Qdisc *qdisc = rtnl_dereference(dev_queue->qdisc_sleeping); - const struct Qdisc_ops *ops = qdisc->ops; - - if (ops->change_tx_queue_len) - return ops->change_tx_queue_len(qdisc, dev->tx_queue_len); - return 0; -} - void dev_qdisc_change_real_num_tx(struct net_device *dev, unsigned int new_real_tx) { @@ -1508,25 +1534,68 @@ void mq_change_real_num_tx(struct Qdisc *sch, unsigned int new_real_tx) } EXPORT_SYMBOL(mq_change_real_num_tx); -int dev_qdisc_change_tx_queue_len(struct net_device *dev) +static void dev_qdisc_abort_tx_queue_len(struct net_device *dev) +{ + struct Qdisc *qdisc; + unsigned int i; + + for (i = 0; i < dev->num_tx_queues; i++) { + qdisc = rtnl_dereference(dev->_tx[i].qdisc_sleeping); + if (qdisc->ops->abort_tx_queue_len) + qdisc->ops->abort_tx_queue_len(qdisc); + } +} + +/* Allocate everything a tx_queue_len change needs, or nothing. */ +static int dev_qdisc_prepare_tx_queue_len(struct net_device *dev, + unsigned int new_len) +{ + struct Qdisc *qdisc; + unsigned int i; + int ret; + + for (i = 0; i < dev->num_tx_queues; i++) { + qdisc = rtnl_dereference(dev->_tx[i].qdisc_sleeping); + if (!qdisc->ops->prepare_tx_queue_len) + continue; + + ret = qdisc->ops->prepare_tx_queue_len(qdisc, new_len); + if (ret) { + dev_qdisc_abort_tx_queue_len(dev); + return ret; + } + } + + return 0; +} + +static void dev_qdisc_commit_tx_queue_len(struct net_device *dev) { bool up = dev->flags & IFF_UP; + struct Qdisc *qdisc; unsigned int i; - int ret = 0; if (up) dev_deactivate(dev, false); for (i = 0; i < dev->num_tx_queues; i++) { - ret = qdisc_change_tx_queue_len(dev, &dev->_tx[i]); - - /* TODO: revert changes on a partial failure */ - if (ret) - break; + qdisc = rtnl_dereference(dev->_tx[i].qdisc_sleeping); + if (qdisc->ops->commit_tx_queue_len) + qdisc->ops->commit_tx_queue_len(qdisc); } if (up) dev_activate(dev); +} + +int dev_qdisc_change_tx_queue_len(struct net_device *dev) +{ + int ret; + + ret = dev_qdisc_prepare_tx_queue_len(dev, dev->tx_queue_len); + if (!ret) + dev_qdisc_commit_tx_queue_len(dev); + return ret; } -- 2.54.0