Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2054359imm; Thu, 27 Sep 2018 06:46:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV63GJ/Z9QfnbrkNa7JC0zv20tv8CkQN5APwqPHi71NBaBcUS8uT9HtclCZosUXKNhiF0Vg8J X-Received: by 2002:a63:fe02:: with SMTP id p2-v6mr10611040pgh.148.1538056008251; Thu, 27 Sep 2018 06:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538056008; cv=none; d=google.com; s=arc-20160816; b=QnwuKG4XpwU5Jbreg2iXiC+OEI6RI/3KhSjWQguXyfCGAjWGYDfy2/Wdfb9z8WZzGw jaJOLXjq9OaULiYxyvjiYdlnpNr1zRaYkcU8cxNk49LZKnHgrWG59hvke/V+LCvGa2+4 FcOCP3xTiOWvM4bm+T9S52tiq3D1OYu9yS+Rgk3YbiuJOQJKyqMIGH7BvUKtYhPZgYqz u42jqADVHS6lcMiokn+Nm/dfOZ7F8DfJNIHypBny6RXtkOmZ2UTI3YAdPXffUNcUlcXZ X+Ia64X3kaDi5gJDx8S8GZFf3/dTW2JzWb/XzUUMteZxxUTfM77VoFaG/uPbXPOOYHQn H2vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=4phDb1xWxQiiR8jky/VREeoibO5x9Y96ECC8F1IMjuA=; b=WrvF+wjZPsV7bkhE7AkftGuzmMPyhiXmBCQED86zqcrdAelFPvuIsrBnhdiGpX8wuG 7BOub2eQq8/XNBo4UNqtW/nkwVHzNR0qw/M/ZVoqVsgsL7B6SMJhnfCk75BXFNwhXb06 xfITmP4yRvo/wjN+Gt321fc8sw8gP9GQEKoeGQi9n/+K+3xj/zgLfqEcbFEhClLlE2+5 oidk7Lr6xKOs2Ro8YaKzYYNMPK7FTmJkbuFhZWTM8Nq42MxW6NSKJ/o1DhBlvv+ID3Uc HwRD7kWJLXGOEUtP/c2NCvW0DkVFwxQtIW/HuWyc/obj0aLHYn1K/l+UWu1CIdXvJkBJ PRmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vazNJLqM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2-v6si1997520pgk.452.2018.09.27.06.46.31; Thu, 27 Sep 2018 06:46:48 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vazNJLqM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727355AbeI0UEk (ORCPT + 99 others); Thu, 27 Sep 2018 16:04:40 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44796 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbeI0UEk (ORCPT ); Thu, 27 Sep 2018 16:04:40 -0400 Received: by mail-pg1-f196.google.com with SMTP id g2-v6so1995070pgu.11; Thu, 27 Sep 2018 06:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=4phDb1xWxQiiR8jky/VREeoibO5x9Y96ECC8F1IMjuA=; b=vazNJLqMAoLx/XSRRv0Kuv0cP8eXa7U24Qbf0VWlQiza9YEgat7A2MD24r0dqE5FPr FDatFsSsVeBhv/KWyuc0lWhaZ4+OYy4OuklhsLL4nQczqD84jxt7Lc2nBStsV2+A45Wo adeKM7Fm3atR0+y3hhYYTi8G4BVL+EpgEDU0eXduF6IR9vrYUJWxQtPaNBfD5BaJZO30 /etCL3ReMZcxB+9mYe+lUDza90P49n2J6xHO+qykBpHJ5v1GEnrIXIRdlTL86VsqyGAH 3lPBI0m89gGYvSk4s8mGCijlxkoA5kcGYFhQfUsUds1EcDTudQeKSS4qOoyhDnTi9jkF ZOxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4phDb1xWxQiiR8jky/VREeoibO5x9Y96ECC8F1IMjuA=; b=KUs6Kiahmiyw2gnXjdqF8PfQFjNy6PP8t0kCLIhL4PWcSa3TwmRbbTKdTb01V6vIcp O+iYU6r+uqzeg+RF9G3qsY1B9Mh5Cz/Qv4Vl8d94ht6pu7odEa3EV3MJHnCfXx2xlI7E 7VbYN4x+ltXEA+czl0A3ez96nUxkvNzVuVLOgDSOJBDA+czbChTnwF0jubDypTllsujD HLgPA0mj2o9Nd76uKm/l11vw86HFwNoQgfPIekljYr/b8hAvKZpXIZTuE+A1/ex0skIP UdCk912Sq7fiJHh51IKZ7U1IZ+B7Nmm8CILh2OfFxyrktMmoNdcvEF4ZELWOI9lef8bW tYhQ== X-Gm-Message-State: ABuFfoiIUy8MHNXFhOVwJJSCg//MyXK5EgZJn3mNgi+kOPkZxtEsvRkv oLytOayyjytfJ+Y/V2cZ4mDmZMPRpVPieQ== X-Received: by 2002:a65:4849:: with SMTP id i9-v6mr10200135pgs.350.1538055979569; Thu, 27 Sep 2018 06:46:19 -0700 (PDT) Received: from localhost.localdomain.localdomain ([113.88.12.25]) by smtp.gmail.com with ESMTPSA id z5-v6sm3137049pfh.83.2018.09.27.06.46.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 06:46:18 -0700 (PDT) From: guoju To: colyli@suse.de, kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org Cc: guoju Subject: [PATCH] bcache: add separate workqueue for journal_write to avoid deadlock Date: Thu, 27 Sep 2018 21:45:19 +0800 Message-Id: <1538055919-5757-1-git-send-email-fangguoju@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After write SSD completed, bcache schedule journal_write work to system_wq, that 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 --- 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(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 83504dd..954dad2 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -965,6 +965,7 @@ bool bch_alloc_sectors(struct cache_set *c, struct bkey *k, void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent); extern struct workqueue_struct *bcache_wq; +extern struct workqueue_struct *bch_journal_wq; extern struct mutex bch_register_lock; extern struct list_head bch_cache_sets; diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c index 6116bbf..522c742 100644 --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c @@ -485,7 +485,7 @@ static void do_journal_discard(struct cache *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); } } @@ -592,7 +592,7 @@ static void journal_write_done(struct closure *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) @@ -627,7 +627,7 @@ static void journal_write_unlocked(struct closure *cl) 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; } diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 3ede144..64715a8 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -47,6 +47,7 @@ static DEFINE_IDA(bcache_device_idx); 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) /* limitation of partitions number on single bcache device */ @@ -2344,6 +2345,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); @@ -2373,6 +2377,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; -- 1.8.3.1