Workqueue: net: replace use of system_wq and add WQ_PERCPU to alloc_workqueue users
Subsystems (17)
cover Workqueue: net: replace use of system_wq and add WQ_PERCPU to alloc_workqueue users
Hello!
Below is a summary of a discussion about the Workqueue API and cpu isolation considerations. Details and more information are available here:
"workqueue: Always use wq_select_unbound_cpu() for WORK_CPU_UNBOUND."
https://lore.kernel.org/all/[email protected]/
=== Current situation: problems ===
Let's consider a nohz_full system with isolated CPUs: wq_unbound_cpumask is set to the housekeeping CPUs, for !WQ_UNBOUND the local CPU is selected.
This leads to different scenarios if a work item is scheduled on an isolated CPU where "delay" value is 0 or greater then 0:
schedule_delayed_work(, 0);
This will be handled by __queue_work() that will queue the work item on the current local (isolated) CPU, while:
schedule_delayed_work(, 1);
Will move the timer on an housekeeping CPU, and schedule the work there.
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
=== Plan and future plans ===
This patchset is the first stone on a refactoring needed in order to address the points aforementioned; it will have a positive impact also on the cpu isolation, in the long term, moving away percpu workqueue in favor to an unbound model.
These are the main steps:
1) API refactoring (that this patch is introducing)
- Make more clear and uniform the system wq names, both per-cpu and
unbound. This to avoid any possible confusion on what should be used.
- Introduction of WQ_PERCPU: this flag is the complement of WQ_UNBOUND,
introduced in this patchset and used on all the callers that are not currently using WQ_UNBOUND.
WQ_UNBOUND will be removed in a future release cycle.
Most users don't need to be per-cpu, because they don't have locality requirements, because of that, a next future step will be make "unbound" the default behavior.
2) Check who really needs to be per-cpu
- Remove the WQ_PERCPU flag when is not strictly required.
3) Add a new API (prefer local cpu)
- There are users that don't require a local execution, like mentioned
above; despite that, local execution yeld to performance gain.
This new API will prefer the local execution, without requiring it.
=== Introduced Changes by this patchset ===
1) [P 1] replace use of system_wq with system_percpu_wq (under net)
system_wq is a per-CPU workqueue, but his name is not clear. system_unbound_wq is to be used when locality is not required.
Because of that, system_wq has been renamed in system_percpu_wq in the net subsystm (details in the next section).
2) [P 2] add WQ_PERCPU to alloc_workqueue() users (under net)
Every alloc_workqueue() caller should use one among WQ_PERCPU or WQ_UNBOUND. This is actually enforced warning if both or none of them are present at the same time.
These patches introduce WQ_PERCPU in the net subsystem (details in the next section).
WQ_UNBOUND will be removed in a next release cycle.
=== For net Maintainers ===
If you agree with these changes, one option is pull the preparation changes from Tejun's wq branch [1].
As an alternative, the patches can be routed through a wq branch.
The preparation changes are described in the present cover letter, under the "main steps" section. The changes done in summary are:
- add system_percpu_wq and system_dfl_wq, for now without replace the older wq(s) (system_unbound_wq and system_wq).
- add WQ_PERCPU flag, currently without removing WQ_UNBOUND; it will be removed in a future release cycle.
You can find the aforementioned changes reading:
("Workqueue: add WQ_PERCPU, system_dfl_wq and system_percpu_wq")
https://lore.kernel.org/all/[email protected]/
- [1] git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git WQ_PERCPU
Thanks!
Marco Crivellari (2):
Workqueue: net: replace use of system_wq with system_percpu_wq Workqueue: net: WQ_PERCPU added to alloc_workqueue users
net/bridge/br_cfm.c | 6 +++--- net/bridge/br_mrp.c | 8 ++++---- net/ceph/messenger.c | 3 ++- net/ceph/mon_client.c | 2 +- net/core/skmsg.c | 2 +- net/core/sock_diag.c | 2 +- net/devlink/core.c | 2 +- net/ipv4/inet_fragment.c | 2 +- net/netfilter/nf_conntrack_ecache.c | 2 +- net/openvswitch/dp_notify.c | 2 +- net/rds/ib_rdma.c | 3 ++- net/rfkill/input.c | 2 +- net/rxrpc/rxperf.c | 2 +- net/smc/af_smc.c | 6 +++--- net/smc/smc_core.c | 4 ++-- net/tls/tls_device.c | 2 +- net/vmw_vsock/af_vsock.c | 2 +- net/vmw_vsock/virtio_transport.c | 2 +- net/vmw_vsock/vsock_loopback.c | 2 +- 19 files changed, 29 insertions(+), 27 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/2 Workqueue: net: replace use of system_wq with system_percpu_wq
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
system_wq is a per-CPU worqueue, yet nothing in its name tells about that CPU affinity constraint, which is very often not required by users. Make it clear by adding a system_percpu_wq to all the network subsystem.
The old wq will be kept for a few release cylces.
--- net/bridge/br_cfm.c | 6 +++--- net/bridge/br_mrp.c | 8 ++++---- net/ceph/mon_client.c | 2 +- net/core/skmsg.c | 2 +- net/devlink/core.c | 2 +- net/ipv4/inet_fragment.c | 2 +- net/netfilter/nf_conntrack_ecache.c | 2 +- net/openvswitch/dp_notify.c | 2 +- net/rfkill/input.c | 2 +- net/smc/smc_core.c | 2 +- net/vmw_vsock/af_vsock.c | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-)
net/bridge/br_cfm.c +3 -3
@@ -134,7 +134,7 @@ static void ccm_rx_timer_start(struct br_cfm_peer_mep *peer_mep)* of the configured CC 'expected_interval' * in order to detect CCM defect after 3.25 interval. */ -queue_delayed_work (system_wq, &peer_mep->ccm_rx_dwork, +queue_delayed_work (system_percpu_wq, &peer_mep->ccm_rx_dwork,usecs_to_jiffies (interval_us /4 )); }
@@ -285,7 +285,7 @@ static void ccm_tx_work_expired(struct work_struct *work)ccm_frame_tx (skb); interval_us =interval_to_us (mep->cc_config.exp_interval); -queue_delayed_work (system_wq, &mep->ccm_tx_dwork, +queue_delayed_work (system_percpu_wq, &mep->ccm_tx_dwork,usecs_to_jiffies (interval_us)); }
@@ -809,7 +809,7 @@ int br_cfm_cc_ccm_tx(struct net_bridge *br, const u32 instance,* to send first frame immediately */ mep->ccm_tx_end = jiffies +usecs_to_jiffies (tx_info->period *1000000 ); -queue_delayed_work (system_wq, &mep->ccm_tx_dwork,0 ); +queue_delayed_work (system_percpu_wq, &mep->ccm_tx_dwork,0 ); save: mep->cc_ccm_tx_info = *tx_info;
net/bridge/br_mrp.c +4 -4
@@ -341,7 +341,7 @@ static void br_mrp_test_work_expired(struct work_struct *work) out:rcu_read_unlock (); -queue_delayed_work (system_wq, &mrp->test_work, +queue_delayed_work (system_percpu_wq, &mrp->test_work,usecs_to_jiffies (mrp->test_interval)); }
@@ -418,7 +418,7 @@ static void br_mrp_in_test_work_expired(struct work_struct *work) out:rcu_read_unlock (); -queue_delayed_work (system_wq, &mrp->in_test_work, +queue_delayed_work (system_percpu_wq, &mrp->in_test_work,usecs_to_jiffies (mrp->in_test_interval)); }
@@ -725,7 +725,7 @@ int br_mrp_start_test(struct net_bridge *br, mrp->test_max_miss = test->max_miss; mrp->test_monitor = test->monitor; mrp->test_count_miss =0 ; -queue_delayed_work (system_wq, &mrp->test_work, +queue_delayed_work (system_percpu_wq, &mrp->test_work,usecs_to_jiffies (test->interval));return 0 ;
@@ -865,7 +865,7 @@ int br_mrp_start_in_test(struct net_bridge *br, mrp->in_test_end = jiffies +usecs_to_jiffies (in_test->period); mrp->in_test_max_miss = in_test->max_miss; mrp->in_test_count_miss =0 ; -queue_delayed_work (system_wq, &mrp->in_test_work, +queue_delayed_work (system_percpu_wq, &mrp->in_test_work,usecs_to_jiffies (in_test->interval));return 0 ;
net/ceph/mon_client.c +1 -1
@@ -314,7 +314,7 @@ static void __schedule_delayed(struct ceph_mon_client *monc) delay =CEPH_MONC_PING_INTERVAL ;dout ("__schedule_delayed after %lu\n" , delay); -mod_delayed_work (system_wq, &monc->delayed_work, +mod_delayed_work (system_percpu_wq, &monc->delayed_work,round_jiffies_relative (delay)); }
net/core/skmsg.c +1 -1
@@ -855,7 +855,7 @@ void sk_psock_drop(struct sock *sk, struct sk_psock *psock)sk_psock_stop (psock);INIT_RCU_WORK (&psock->rwork, sk_psock_destroy); -queue_rcu_work (system_wq, &psock->rwork); +queue_rcu_work (system_percpu_wq, &psock->rwork); }EXPORT_SYMBOL_GPL (sk_psock_drop);
net/devlink/core.c +1 -1
@@ -320,7 +320,7 @@ static void devlink_release(struct work_struct *work)void devlink_put (struct devlink *devlink) {if (refcount_dec_and_test (&devlink->refcount)) -queue_rcu_work (system_wq, &devlink->rwork); +queue_rcu_work (system_percpu_wq, &devlink->rwork); }struct devlink *devlinks_xa_find_get (struct net *net,unsigned long *indexp)
net/ipv4/inet_fragment.c +1 -1
@@ -183,7 +183,7 @@ static void fqdir_work_fn(struct work_struct *work)rhashtable_free_and_destroy (&fqdir->rhashtable, inet_frags_free_cb,NULL );if (llist_add (&fqdir->free_list, &fqdir_free_list)) -queue_delayed_work (system_wq, &fqdir_free_work,HZ ); +queue_delayed_work (system_percpu_wq, &fqdir_free_work,HZ ); }int fqdir_init (struct fqdir **fqdirp,struct inet_frags *f,struct net *net)
net/netfilter/nf_conntrack_ecache.c +1 -1
@@ -301,7 +301,7 @@ void nf_conntrack_ecache_work(struct net *net, enum nf_ct_ecache_state state) net->ct.ecache_dwork_pending = true; }else if (state ==NFCT_ECACHE_DESTROY_SENT ) {if (!hlist_nulls_empty (&cnet->ecache.dying_list)) -mod_delayed_work (system_wq, &cnet->ecache.dwork,0 ); +mod_delayed_work (system_percpu_wq, &cnet->ecache.dwork,0 );else net->ct.ecache_dwork_pending = false; }
net/openvswitch/dp_notify.c +1 -1
@@ -75,7 +75,7 @@ static int dp_device_event(struct notifier_block *unused, unsigned long event,/* schedule vport destroy, dev_put and genl notification */ ovs_net =net_generic (dev_net (dev), ovs_net_id); -queue_work (system_wq, &ovs_net->dp_notify_work); +queue_work (system_percpu_wq, &ovs_net->dp_notify_work); }return NOTIFY_DONE ;
net/rfkill/input.c +1 -1
@@ -159,7 +159,7 @@ static void rfkill_schedule_global_op(enum rfkill_sched_op op) rfkill_op_pending = true;if (op ==RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active ()) {/* bypass the limiter for EPO */ -mod_delayed_work (system_wq, &rfkill_op_work,0 ); +mod_delayed_work (system_percpu_wq, &rfkill_op_work,0 ); rfkill_last_scheduled = jiffies; }else rfkill_schedule_ratelimited ();
net/smc/smc_core.c +1 -1
@@ -85,7 +85,7 @@ static void smc_lgr_schedule_free_work(struct smc_link_group *lgr)* otherwise there is a risk of out-of-sync link groups. */ if (!lgr->freeing) { -mod_delayed_work (system_wq, &lgr->free_work, +mod_delayed_work (system_percpu_wq, &lgr->free_work, (!lgr->is_smcd && lgr->role ==SMC_CLNT ) ?SMC_LGR_FREE_DELAY_CLNT :SMC_LGR_FREE_DELAY_SERV );
net/vmw_vsock/af_vsock.c +1 -1
@@ -1569,7 +1569,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr,* reschedule it, then ungrab the socket refcount to * keep it balanced. */ -if (mod_delayed_work (system_wq, &vsk->connect_work, +if (mod_delayed_work (system_percpu_wq, &vsk->connect_work, timeout))sock_put (sk);
Signature · 1 line
2.50.1
PATCH 2/2 Workqueue: net: WQ_PERCPU added to alloc_workqueue users
In reply to Marco CrivellariCurrently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This patch adds a new WQ_PERCPU flag at the network subsystem, to explicitly request the use of the per-CPU behavior. Both flags coexist for one release cycle to allow callers to transition their calls.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
All existing users have been updated accordingly.
--- net/ceph/messenger.c | 3 ++- net/core/sock_diag.c | 2 +- net/rds/ib_rdma.c | 3 ++- net/rxrpc/rxperf.c | 2 +- net/smc/af_smc.c | 6 +++--- net/smc/smc_core.c | 2 +- net/tls/tls_device.c | 2 +- net/vmw_vsock/virtio_transport.c | 2 +- net/vmw_vsock/vsock_loopback.c | 2 +- 9 files changed, 13 insertions(+), 11 deletions(-)
net/ceph/messenger.c +2 -1
@@ -252,7 +252,8 @@ int __init ceph_msgr_init(void)* The number of active work items is limited by the number of * connections, so leave @max_active at default. */ - ceph_msgr_wq =alloc_workqueue ("ceph-msgr" ,WQ_MEM_RECLAIM ,0 ); + ceph_msgr_wq =alloc_workqueue ("ceph-msgr" , +WQ_MEM_RECLAIM |WQ_PERCPU ,0 );if (ceph_msgr_wq)return 0 ;
net/core/sock_diag.c +1 -1
@@ -350,7 +350,7 @@ static struct pernet_operations diag_net_ops = {static int __init sock_diag_init (void ) { - broadcast_wq =alloc_workqueue ("sock_diag_events" ,0 ,0 ); + broadcast_wq =alloc_workqueue ("sock_diag_events" ,WQ_PERCPU ,0 );BUG_ON (!broadcast_wq);return register_pernet_subsys (&diag_net_ops); }
net/rds/ib_rdma.c +2 -1
@@ -672,7 +672,8 @@ struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev,int rds_ib_mr_init (void ) { - rds_ib_mr_wq =alloc_workqueue ("rds_mr_flushd" ,WQ_MEM_RECLAIM ,0 ); + rds_ib_mr_wq =alloc_workqueue ("rds_mr_flushd" , +WQ_MEM_RECLAIM |WQ_PERCPU ,0 );if (!rds_ib_mr_wq)return -ENOMEM ;return 0 ;
net/rxrpc/rxperf.c +1 -1
@@ -584,7 +584,7 @@ static int __init rxperf_init(void)pr_info ("Server registering\n" ); - rxperf_workqueue =alloc_workqueue ("rxperf" ,0 ,0 ); + rxperf_workqueue =alloc_workqueue ("rxperf" ,WQ_PERCPU ,0 );if (!rxperf_workqueue) goto error_workqueue;
net/smc/af_smc.c +3 -3
@@ -3518,15 +3518,15 @@ static int __init smc_init(void) rc = -ENOMEM ; - smc_tcp_ls_wq =alloc_workqueue ("smc_tcp_ls_wq" ,0 ,0 ); + smc_tcp_ls_wq =alloc_workqueue ("smc_tcp_ls_wq" ,WQ_PERCPU ,0 );if (!smc_tcp_ls_wq) goto out_pnet; - smc_hs_wq =alloc_workqueue ("smc_hs_wq" ,0 ,0 ); + smc_hs_wq =alloc_workqueue ("smc_hs_wq" ,WQ_PERCPU ,0 );if (!smc_hs_wq) goto out_alloc_tcp_ls_wq; - smc_close_wq =alloc_workqueue ("smc_close_wq" ,0 ,0 ); + smc_close_wq =alloc_workqueue ("smc_close_wq" ,WQ_PERCPU ,0 );if (!smc_close_wq) goto out_alloc_hs_wq;
net/smc/smc_core.c +1 -1
@@ -896,7 +896,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini) rc =SMC_CLC_DECL_MEM ; goto ism_put_vlan; } - lgr->tx_wq =alloc_workqueue ("smc_tx_wq-%*phN" ,0 ,0 , + lgr->tx_wq =alloc_workqueue ("smc_tx_wq-%*phN" ,WQ_PERCPU ,0 ,SMC_LGR_ID_SIZE , &lgr->id);if (!lgr->tx_wq) { rc = -ENOMEM ;
net/tls/tls_device.c +1 -1
@@ -1410,7 +1410,7 @@ int __init tls_device_init(void)if (!dummy_page)return -ENOMEM ; - destruct_wq =alloc_workqueue ("ktls_device_destruct" ,0 ,0 ); + destruct_wq =alloc_workqueue ("ktls_device_destruct" ,WQ_PERCPU ,0 );if (!destruct_wq) { err = -ENOMEM ; goto err_free_dummy;
net/vmw_vsock/virtio_transport.c +1 -1
@@ -916,7 +916,7 @@ static int __init virtio_vsock_init(void) {int ret; - virtio_vsock_workqueue =alloc_workqueue ("virtio_vsock" ,0 ,0 ); + virtio_vsock_workqueue =alloc_workqueue ("virtio_vsock" ,WQ_PERCPU ,0 );if (!virtio_vsock_workqueue)return -ENOMEM ;
net/vmw_vsock/vsock_loopback.c +1 -1
@@ -139,7 +139,7 @@ static int __init vsock_loopback_init(void)struct vsock_loopback *vsock = &the_vsock_loopback;int ret; - vsock->workqueue =alloc_workqueue ("vsock-loopback" ,0 ,0 ); + vsock->workqueue =alloc_workqueue ("vsock-loopback" ,WQ_PERCPU ,0 );if (!vsock->workqueue)return -ENOMEM ;
Signature · 1 line
2.50.1