From patchwork Thu Dec 28 00:47:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10134341 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 0734E605B4 for ; Thu, 28 Dec 2017 00:48:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE1A52CE1C for ; Thu, 28 Dec 2017 00:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E303E2CFCC; Thu, 28 Dec 2017 00:48:14 +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,DKIM_SIGNED, DKIM_VALID,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 807502CE1C for ; Thu, 28 Dec 2017 00:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752782AbdL1AsN (ORCPT ); Wed, 27 Dec 2017 19:48:13 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:42217 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752052AbdL1AsM (ORCPT ); Wed, 27 Dec 2017 19:48:12 -0500 Received: by mail-pl0-f68.google.com with SMTP id bd8so20251081plb.9 for ; Wed, 27 Dec 2017 16:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tMDUgYJfEFTqe/qA3SgZVf6gRsQ4x/gaQ1O8uqYzff0=; b=fOPSroSR0JH2iNf+5BsBifElDMtcu9Urc0FKDd2lhi+N4UWDOfkZnZvNSYuHb1rre8 bhGvGzWlz6jtkgRfhow5tMqe37gcDMshph+n9EvDd+l/qF3iz3ScNBSfOalNrI1lq/fw wt6p9oDzGmxSkgnRvP31yAjjIjC5bjwfcYAJ8FRkpL9sJYj1YLSLoLnE/wGuCAaXlGqx yl3tq8ZMK1LxqmmhAGdOnNRQFmuqSpgCmXwgEJPQrD43r8L8fBYy3UbyjSJ7ohhqgeH8 TkoCHLlHhSlLgsVO+kl5ufIuBnjqnWrtBRAxSWx4lD0TIqD771gfuyflltQB4m2b2EN+ I8qg== 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:in-reply-to :references; bh=tMDUgYJfEFTqe/qA3SgZVf6gRsQ4x/gaQ1O8uqYzff0=; b=aoxTfCLOE5W7aBJrR3FybTp75y21lRyXHL1GbBihtdSQggPvLZxORmD4crHhFj+S3b ZTSFfo6yO4+bBK9/a5/ku+AaqM1vuJwAZueAErbQTi7dP+p5RwJlFyKPGnlP5Ffe7BkJ 9dMEYFz6kDGIm1CAPlOwB6lN3698B87FlC2REosVdYNEAT0S5jdrQDB17xgXbiSAOA3r zLHSd+idE9aHCqsYRK0wQ3HTmG0V7ZeOADSzQZ4V5ZwtTcbTfdp38ZAwnxQIsN0Exd7B Fu0MNLFWueFObX7HNM8RTBTOfIlHrRVEQCg7LMEosgLhSQELa74n3QIpzK0HOypF1TjJ WGjg== X-Gm-Message-State: AKGB3mIebTFTV8QmUtLi8WPLULF0iaAZ4cR81d0GH7mRD3nbAoIocoy7 IttaG3Xi7EaGD7uheVKMGbfZCQ== X-Google-Smtp-Source: ACJfBougSOMTDt+nFr9Rh82OHIKtXabJbeW2qUj3lhHCae00t304ZhCvS9f5ZGiySWrDslPBtDlTWw== X-Received: by 10.84.217.72 with SMTP id e8mr4797015plj.168.1514422092233; Wed, 27 Dec 2017 16:48:12 -0800 (PST) Received: from midnight.lan (2600-6c52-6200-383d-a0f8-4aea-fac9-9f39.dhcp6.chtrptr.net. [2600:6c52:6200:383d:a0f8:4aea:fac9:9f39]) by smtp.gmail.com with ESMTPSA id y5sm68236061pfa.128.2017.12.27.16.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2017 16:48:11 -0800 (PST) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: Michael Lyle Subject: [for-416 PATCH 3/3] bcache: allow quick writeback when backing idle Date: Wed, 27 Dec 2017 16:47:44 -0800 Message-Id: <20171228004744.3522-3-mlyle@lyle.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171228004744.3522-1-mlyle@lyle.org> References: <20171228004744.3522-1-mlyle@lyle.org> 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 If the control system would wait for at least half a second, and there's been no reqs hitting the backing disk for awhile: use an alternate mode where we have at most one contiguous set of writebacks in flight at a time. (But don't otherwise delay). If front-end IO appears, it will still be quick, as it will only have to contend with one real operation in flight. But otherwise, we'll be sending data to the backing disk as quickly as it can accept it (with one op at a time). Signed-off-by: Michael Lyle --- drivers/md/bcache/bcache.h | 7 +++++++ drivers/md/bcache/request.c | 1 + drivers/md/bcache/writeback.c | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 3be0fcc19b1f..5f7b0b2513cc 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -320,6 +320,13 @@ struct cached_dev { */ atomic_t has_dirty; + /* + * Set to zero by things that touch the backing volume-- except + * writeback. Incremented by writeback. Used to determine when to + * accelerate idle writeback. + */ + atomic_t backing_idle; + struct bch_ratelimit writeback_rate; struct delayed_work writeback_rate_update; diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index d1faaba6b93f..3b4defbdcbbd 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -996,6 +996,7 @@ static blk_qc_t cached_dev_make_request(struct request_queue *q, struct cached_dev *dc = container_of(d, struct cached_dev, disk); int rw = bio_data_dir(bio); + atomic_set(&dc->backing_idle, 0); generic_start_io_acct(q, rw, bio_sectors(bio), &d->disk->part0); bio_set_dev(bio, dc->bdev); diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 4084586d5991..bf309a480335 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -383,6 +383,27 @@ static void read_dirty(struct cached_dev *dc) delay = writeback_delay(dc, size); + /* If the control system would wait for at least half a + * second, and there's been no reqs hitting the backing disk + * for awhile: use an alternate mode where we have at most + * one contiguous set of writebacks in flight at a time. If + * someone wants to do IO it will be quick, as it will only + * have to contend with one operation in flight, and we'll + * be round-tripping data to the backing disk as quickly as + * it can accept it. + */ + if (delay >= HZ / 2) { + /* 3 means at least 1.5 seconds, up to 7.5 if we + * have slowed way down. + */ + if (atomic_inc_return(&dc->backing_idle) >= 3) { + /* Wait for current I/Os to finish */ + closure_sync(&cl); + /* And immediately launch a new set. */ + delay = 0; + } + } + while (!kthread_should_stop() && delay) { schedule_timeout_interruptible(delay); delay = writeback_delay(dc, 0);