Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2164975imm; Thu, 27 Sep 2018 08:24:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV60nSCl0VtmW2JZfCgGmnUZb9c/oE/XKHJaDi4Fg3KjFLUaTgIKn8HtU/dgzgyzntOn4+uN+ X-Received: by 2002:a63:10c:: with SMTP id 12-v6mr10711300pgb.62.1538061849268; Thu, 27 Sep 2018 08:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538061849; cv=none; d=google.com; s=arc-20160816; b=rWsS5buNdV3vKLdWopOV/6KnaMJqKAIeQoRdoMAxxDuXrxgE36LVQFkUZfQrdfmBCR M2F81EgsR3ew2kXsMOuUb+weiDUJUz5jrVLSt7z8SreJF4Yl3dtXlSVMroTpFrzKRc/6 3L1DZg3dYUsjZY5bSK0ZtwIwd/h2Dqj5h/GAeH7MIrJ0pwoQqhsT+e/4Ivb/3L4ZWtOT fNPoQgIbPf9hvYSd5ofXoRcIrnKUOACJGgZKldl8DHpvIu+GKuhCxqaGvsro50aSR0Ty JQe/Gp+hOx64kYx8ELu2V6znlLYGGx4lGQjH7TNrYwxUGIsGEKVzIWuQuCMzQgBggNn4 Foig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:references:to:subject; bh=/PwLaWcvbzX59gEl1ZiuW/uwNJ5jKqXT5r0eOGfjTkQ=; b=CwOMBFh4xwEjWwtAkpejmjEqALC3bhxoWDYiK4trJXFzT9wt//PG+5t9j106IsOdEX Nl/dMrKMuHYR8J3u4gKbxO6KMEvaZqC8fv398sRbZ8FJFerQvevkYskYFa2f/cpMK8y1 oZwV+08BygSObft++iw0UMxZPC0SygokY/EpUwTVPgwrewXj8xaPh8XjKQDFzFJ703MR iAgCqDLbzKBHus7mT244pbY14ukOWLNaMeAon1gHIfhHELXc+X+TGuQa5tuwsOM4rbLc FYa3iomBLY0z6CmFWHgdMXlFUHyoa+gwq5tzt3GxKhuqyLJ1zKhdMfM80En8K1cglYNg V+UQ== 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 l14-v6si2214580pgi.34.2018.09.27.08.23.53; Thu, 27 Sep 2018 08:24:09 -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; 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 S1728269AbeI0VmX (ORCPT + 99 others); Thu, 27 Sep 2018 17:42:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:55372 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727270AbeI0VmX (ORCPT ); Thu, 27 Sep 2018 17:42:23 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 682EAAFC2; Thu, 27 Sep 2018 15:23:34 +0000 (UTC) Subject: Re: [PATCH] bcache: add separate workqueue for journal_write to avoid deadlock To: guoju References: <1538055919-5757-1-git-send-email-fangguoju@gmail.com> Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org From: Coly Li Message-ID: Date: Thu, 27 Sep 2018 23:23:27 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <1538055919-5757-1-git-send-email-fangguoju@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/27/18 9:45 PM, guoju wrote: > 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 Nice catch, this fix is quite important. I will try to submit to Jens ASAP. Thanks. Coly Li > --- > 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;