Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3002274imu; Sun, 9 Dec 2018 14:49:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/VijtvSnwV1PYggaDzT4HqnKCXJ5747jQ0vuJgCICpb9JBBacF73RXzfB6ybzKEOccIsgqN X-Received: by 2002:a17:902:4d46:: with SMTP id o6mr9489511plh.302.1544395758888; Sun, 09 Dec 2018 14:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544395758; cv=none; d=google.com; s=arc-20160816; b=uqf1rFgLQtoScNHWgCOKcybw2zsdBvaz3+1thJCRFTYQ+Sla7GNm+/1hcCSRsQZsOo J4R9OGmvALt2zliLn+6XS3+NNeDVeAGpjpP/ecA/GhB467oR4uXP8FwsUtyL/kwEK4pP NETtILXHK3dlnJelEGX8gHnHlITf+dTKpnZtrf2WURWQNXc/YHhTqE5fMVqnXAwHdcFR 70Tue/wlWBStelyv0TScmKh0fIR8KRrxyEEMz5uGNGrOqDgpJVlOWg2W2hTwF2nfZ5Zx bYn202XeKxmKhGy1NXcazv5o857mEyB3IQp4MApvdczsxtS8sUJyPeHZrnkTneMXlEK8 +rrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=nqXxWmQptjUK8JCPxHnRaAmVnuwA4kmwqn0u6s/s2m4=; b=oTeCGxVqIg7xmEFo5NMhHBA40mtCxj2YqnlU8jBNykXO35ST++/4h6nZ1v6d7EfbSD hKP8M8b1NzxHttEsD8jE4tFmgHDsqoLu1b2Ihtpo45wg5Y6jH98Su/VS8OdGwuaNGCb+ S3OmegZyWsvptAJOi/Z9sS7JtzU8VHySWG93zsYQSA1rmLsMVTsxHcekSFSz/njFU9vV Z7n+nPeMn0DNqwmoYpyEGREJJ5Wa27vzaCncl5PN+p3wgF1znvbtTSYJmEKtZFxhBvcX qbwSbd0P4K7Fl9SSMRZbkAI3diGLCzeMJGkTZ71NdgQo0hc5bclKvaGRB7AGnGRqt+mu 0RVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si8796122pfa.150.2018.12.09.14.49.03; Sun, 09 Dec 2018 14:49:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727263AbeLIWBo (ORCPT + 99 others); Sun, 9 Dec 2018 17:01:44 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35938 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726675AbeLIVzd (ORCPT ); Sun, 9 Dec 2018 16:55:33 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72w-0002pr-Ox; Sun, 09 Dec 2018 21:55:31 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72j-0003bw-F5; Sun, 09 Dec 2018 21:55:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Coly Li" , "Guoju Fang" , "Jens Axboe" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 269/328] bcache: add separate workqueue for journal_write to avoid deadlock In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Guoju Fang commit 0f843e65d9eef4936929bb036c5f771fb261eea4 upstream. After write SSD completed, bcache schedules journal_write work to system_wq, which is a public workqueue in system, without WQ_MEM_RECLAIM flag. system_wq is also a bound wq, and there may be no idle kworker on current processor. Creating a new kworker may unfortunately need to reclaim memory first, by shrinking cache and slab used by vfs, which depends on bcache device. That's a deadlock. This patch create a new workqueue for journal_write with WQ_MEM_RECLAIM flag. It's rescuer thread will work to avoid the deadlock. Signed-off-by: Guoju Fang Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Ben Hutchings --- drivers/md/bcache/bcache.h | 1 + drivers/md/bcache/journal.c | 6 +++--- drivers/md/bcache/super.c | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -898,6 +898,7 @@ void bch_prio_write(struct cache *); void bch_write_bdev_super(struct cached_dev *, struct closure *); extern struct workqueue_struct *bcache_wq; +extern struct workqueue_struct *bch_journal_wq; extern const char * const bch_cache_modes[]; extern struct mutex bch_register_lock; extern struct list_head bch_cache_sets; --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c @@ -454,7 +454,7 @@ static void do_journal_discard(struct ca closure_get(&ca->set->cl); INIT_WORK(&ja->discard_work, journal_discard_work); - schedule_work(&ja->discard_work); + queue_work(bch_journal_wq, &ja->discard_work); } } @@ -559,7 +559,7 @@ static void journal_write_done(struct cl : &j->w[0]; __closure_wake_up(&w->wait); - continue_at_nobarrier(cl, journal_write, system_wq); + continue_at_nobarrier(cl, journal_write, bch_journal_wq); } static void journal_write_unlock(struct closure *cl) @@ -592,7 +592,7 @@ static void journal_write_unlocked(struc spin_unlock(&c->journal.lock); btree_flush_write(c); - continue_at(cl, journal_write, system_wq); + continue_at(cl, journal_write, bch_journal_wq); return; } --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -56,6 +56,7 @@ static int bcache_major; static DEFINE_IDA(bcache_minor); static wait_queue_head_t unregister_wait; struct workqueue_struct *bcache_wq; +struct workqueue_struct *bch_journal_wq; #define BTREE_MAX_PAGES (256 * 1024 / PAGE_SIZE) @@ -2112,6 +2113,9 @@ static void bcache_exit(void) kobject_put(bcache_kobj); if (bcache_wq) destroy_workqueue(bcache_wq); + if (bch_journal_wq) + destroy_workqueue(bch_journal_wq); + if (bcache_major) unregister_blkdev(bcache_major, "bcache"); unregister_reboot_notifier(&reboot); @@ -2142,6 +2146,10 @@ static int __init bcache_init(void) if (!bcache_wq) goto err; + bch_journal_wq = alloc_workqueue("bch_journal", WQ_MEM_RECLAIM, 0); + if (!bch_journal_wq) + goto err; + bcache_kobj = kobject_create_and_add("bcache", fs_kobj); if (!bcache_kobj) goto err;