From: SeungJong Ha <engineer.jjhama@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Jiri Pirko <jiri@resnulli.us>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Jason Wang <jasowangio@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
John Fastabend <john.fastabend@gmail.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
SeungJong Ha <engineer.jjhama@gmail.com>
Subject: [PATCH RFC net-next 3/5] net_sched: change tx_queue_len on all tx queues or on none
Date: Sun, 06 Dec 2026 23:44:44 +0900 [thread overview]
Message-ID: <20261206-tc1-txqlen-commit-v1-3-ec9f34dce973@gmail.com> (raw)
In-Reply-To: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com>
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 <engineer.jjhama@gmail.com>
---
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
next prev parent reply other threads:[~2026-12-06 14:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 14:44 [PATCH RFC net-next 0/5] net: make tx_queue_len changes all-or-nothing SeungJong Ha
2026-12-06 14:44 ` [PATCH RFC net-next 1/5] ptr_ring: drop the unused gfp argument of __ptr_ring_swap_queue() SeungJong Ha
2026-12-06 14:44 ` [PATCH RFC net-next 2/5] ptr_ring: split ptr_ring_resize_multiple_bh() into alloc and swap SeungJong Ha
2026-12-06 14:44 ` SeungJong Ha [this message]
2026-12-06 14:44 ` [PATCH RFC net-next 4/5] net: resize tun and tap rings from rtnl_link_ops SeungJong Ha
2026-12-06 14:44 ` [PATCH RFC net-next 5/5] net: change tx_queue_len only after all allocations succeeded SeungJong Ha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206-tc1-txqlen-commit-v1-3-ec9f34dce973@gmail.com \
--to=engineer.jjhama@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox