diff options
author | Tejun Heo <tj@kernel.org> | 2018-05-23 13:56:32 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-05-23 17:28:50 -0400 |
commit | f183464684190bacbfb14623bd3e4e51b7575b4c (patch) | |
tree | 4141affe6a532a73d8072feaa0f5d3b7b07131de /mm/backing-dev.c | |
parent | 6df133a1495f8c497d0f53005296ef5421752620 (diff) |
bdi: Move cgroup bdi_writeback to a dedicated low concurrency workqueue
From 0aa2e9b921d6db71150633ff290199554f0842a8 Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj@kernel.org>
Date: Wed, 23 May 2018 10:29:00 -0700
cgwb_release() punts the actual release to cgwb_release_workfn() on
system_wq. Depending on the number of cgroups or block devices, there
can be a lot of cgwb_release_workfn() in flight at the same time.
We're periodically seeing close to 256 kworkers getting stuck with the
following stack trace and overtime the entire system gets stuck.
[<ffffffff810ee40c>] _synchronize_rcu_expedited.constprop.72+0x2fc/0x330
[<ffffffff810ee634>] synchronize_rcu_expedited+0x24/0x30
[<ffffffff811ccf23>] bdi_unregister+0x53/0x290
[<ffffffff811cd1e9>] release_bdi+0x89/0xc0
[<ffffffff811cd645>] wb_exit+0x85/0xa0
[<ffffffff811cdc84>] cgwb_release_workfn+0x54/0xb0
[<ffffffff810a68d0>] process_one_work+0x150/0x410
[<ffffffff810a71fd>] worker_thread+0x6d/0x520
[<ffffffff810ad3dc>] kthread+0x12c/0x160
[<ffffffff81969019>] ret_from_fork+0x29/0x40
[<ffffffffffffffff>] 0xffffffffffffffff
The events leading to the lockup are...
1. A lot of cgwb_release_workfn() is queued at the same time and all
system_wq kworkers are assigned to execute them.
2. They all end up calling synchronize_rcu_expedited(). One of them
wins and tries to perform the expedited synchronization.
3. However, that invovles queueing rcu_exp_work to system_wq and
waiting for it. Because #1 is holding all available kworkers on
system_wq, rcu_exp_work can't be executed. cgwb_release_workfn()
is waiting for synchronize_rcu_expedited() which in turn is waiting
for cgwb_release_workfn() to free up some of the kworkers.
We shouldn't be scheduling hundreds of cgwb_release_workfn() at the
same time. There's nothing to be gained from that. This patch
updates cgwb release path to use a dedicated percpu workqueue with
@max_active of 1.
While this resolves the problem at hand, it might be a good idea to
isolate rcu_exp_work to its own workqueue too as it can be used from
various paths and is prone to this sort of indirect A-A deadlocks.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'mm/backing-dev.c')
-rw-r--r-- | mm/backing-dev.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 7441bd93b732..8fe3ebd6ac00 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c | |||
@@ -412,6 +412,7 @@ static void wb_exit(struct bdi_writeback *wb) | |||
412 | * protected. | 412 | * protected. |
413 | */ | 413 | */ |
414 | static DEFINE_SPINLOCK(cgwb_lock); | 414 | static DEFINE_SPINLOCK(cgwb_lock); |
415 | static struct workqueue_struct *cgwb_release_wq; | ||
415 | 416 | ||
416 | /** | 417 | /** |
417 | * wb_congested_get_create - get or create a wb_congested | 418 | * wb_congested_get_create - get or create a wb_congested |
@@ -522,7 +523,7 @@ static void cgwb_release(struct percpu_ref *refcnt) | |||
522 | { | 523 | { |
523 | struct bdi_writeback *wb = container_of(refcnt, struct bdi_writeback, | 524 | struct bdi_writeback *wb = container_of(refcnt, struct bdi_writeback, |
524 | refcnt); | 525 | refcnt); |
525 | schedule_work(&wb->release_work); | 526 | queue_work(cgwb_release_wq, &wb->release_work); |
526 | } | 527 | } |
527 | 528 | ||
528 | static void cgwb_kill(struct bdi_writeback *wb) | 529 | static void cgwb_kill(struct bdi_writeback *wb) |
@@ -784,6 +785,21 @@ static void cgwb_bdi_register(struct backing_dev_info *bdi) | |||
784 | spin_unlock_irq(&cgwb_lock); | 785 | spin_unlock_irq(&cgwb_lock); |
785 | } | 786 | } |
786 | 787 | ||
788 | static int __init cgwb_init(void) | ||
789 | { | ||
790 | /* | ||
791 | * There can be many concurrent release work items overwhelming | ||
792 | * system_wq. Put them in a separate wq and limit concurrency. | ||
793 | * There's no point in executing many of these in parallel. | ||
794 | */ | ||
795 | cgwb_release_wq = alloc_workqueue("cgwb_release", 0, 1); | ||
796 | if (!cgwb_release_wq) | ||
797 | return -ENOMEM; | ||
798 | |||
799 | return 0; | ||
800 | } | ||
801 | subsys_initcall(cgwb_init); | ||
802 | |||
787 | #else /* CONFIG_CGROUP_WRITEBACK */ | 803 | #else /* CONFIG_CGROUP_WRITEBACK */ |
788 | 804 | ||
789 | static int cgwb_bdi_init(struct backing_dev_info *bdi) | 805 | static int cgwb_bdi_init(struct backing_dev_info *bdi) |