From patchwork Fri Jun 30 20:43:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Wheeler X-Patchwork-Id: 9820451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E19D60224 for ; Fri, 30 Jun 2017 20:44:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02D82271BC for ; Fri, 30 Jun 2017 20:44:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC0E228437; Fri, 30 Jun 2017 20:44:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92907271BC for ; Fri, 30 Jun 2017 20:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752929AbdF3UoL (ORCPT ); Fri, 30 Jun 2017 16:44:11 -0400 Received: from mx.ewheeler.net ([66.155.3.69]:43906 "EHLO mail.ewheeler.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752849AbdF3Un5 (ORCPT ); Fri, 30 Jun 2017 16:43:57 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.ewheeler.net (Postfix) with ESMTP id 6EEA4A0C4C; Fri, 30 Jun 2017 20:43:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at ewheeler.net Received: from mail.ewheeler.net ([127.0.0.1]) by localhost (mail.ewheeler.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id FCGuXX3R5JEC; Fri, 30 Jun 2017 20:43:56 +0000 (UTC) Received: from el7-dev.ewi (c-24-20-122-25.hsd1.or.comcast.net [24.20.122.25]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.ewheeler.net (Postfix) with ESMTPSA id 709F9A0C45; Fri, 30 Jun 2017 20:43:55 +0000 (UTC) From: bcache@lists.ewheeler.net To: linux-block@vger.kernel.org Cc: linux-bcache@vger.kernel.org, hch@infradead.org, axboe@kernel.dk, Tang Junhui Subject: [PATCH 12/19] bcache: update bucket_in_use periodically Date: Fri, 30 Jun 2017 13:43:01 -0700 Message-Id: <1498855388-16990-12-git-send-email-bcache@lists.ewheeler.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1498855388-16990-1-git-send-email-bcache@lists.ewheeler.net> References: <20170629134510.GA32385@infradead.org> <1498855388-16990-1-git-send-email-bcache@lists.ewheeler.net> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tang Junhui bucket_in_use is updated in gc thread which triggered by invalidating or writing sectors_to_gc dirty data, It's been too long, Therefore, when we use it to compare with the threshold, it is often not timely, which leads to inaccurate judgment and often results in bucket depletion. Signed-off-by: Tang Junhui --- drivers/md/bcache/btree.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 866dcf7..77aa20b 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -90,6 +90,8 @@ #define MAX_NEED_GC 64 #define MAX_SAVE_PRIO 72 +#define GC_THREAD_TIMEOUT_MS (30 * 1000) + #define PTR_DIRTY_BIT (((uint64_t) 1 << 36)) #define PTR_HASH(c, k) \ @@ -1760,6 +1762,23 @@ static void bch_btree_gc(struct cache_set *c) bch_moving_gc(c); } +void bch_update_bucket_in_use(struct cache_set *c) +{ + struct cache *ca; + struct bucket *b; + unsigned i; + size_t available = 0; + + for_each_cache(ca, c, i) { + for_each_bucket(b, ca) { + if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE) + available++; + } + } + + c->gc_stats.in_use = (c->nbuckets - available) * 100 / c->nbuckets; +} + static bool gc_should_run(struct cache_set *c) { struct cache *ca; @@ -1778,10 +1797,16 @@ static bool gc_should_run(struct cache_set *c) static int bch_gc_thread(void *arg) { struct cache_set *c = arg; + long ret; + unsigned long timeout = msecs_to_jiffies(GC_THREAD_TIMEOUT_MS); while (1) { - wait_event_interruptible(c->gc_wait, - kthread_should_stop() || gc_should_run(c)); + ret = wait_event_interruptible_timeout(c->gc_wait, + kthread_should_stop() || gc_should_run(c), timeout); + if (!ret) { + bch_update_bucket_in_use(c); + continue; + } if (kthread_should_stop()) break;