From patchwork Mon Jan 8 20:21:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10150549 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 2CCD56056F for ; Mon, 8 Jan 2018 20:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3811427EE2 for ; Mon, 8 Jan 2018 20:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CE8D28524; Mon, 8 Jan 2018 20:22:17 +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 1FD97289A3 for ; Mon, 8 Jan 2018 20:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757214AbeAHUVu (ORCPT ); Mon, 8 Jan 2018 15:21:50 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33847 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757228AbeAHUVs (ORCPT ); Mon, 8 Jan 2018 15:21:48 -0500 Received: by mail-pf0-f193.google.com with SMTP id e76so1992656pfk.1 for ; Mon, 08 Jan 2018 12:21:48 -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=n0xKEkkLXGewwMqZh8FLNsSrHFetSx1QTDKkeJRrPKQ=; b=jkl/fvj1+kZwFHFfv6bC642frGd20ixkRw4kGukqJO6IWMHGW8agJovn6xTkbsTUZD mFuXqYnEZe71gM2YWeDxBdA3G9PWBYCpX+FFHW2ucb9cdyBMd1y4APHM0YDk+etCsEd2 DXGw4sszKxr1A4DjAlP0ll1NDolzGASmIyXHacl7FlxYRtOBRYj1waVtyQWHoAzu/YwZ 0z50BJkoClc0Mj5xBjlKCEumP5ssdkKMSy9gjveeYkW0XS9A7o4R29ptZkes9pEMI23r ZCgck/GcNONNv+wicDYgdbWhrGidDONWzOwuALNbVFNeEyRpDyOLFF2pFMlPo7oZET1V yMMQ== 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=n0xKEkkLXGewwMqZh8FLNsSrHFetSx1QTDKkeJRrPKQ=; b=MKanBNXt+O3nXWL0QWoqGAq2YT5N0HFBLE3lsM1insCN0LXkFpX5w1dKVpbF77Mj3C wNsnb+1So1jMDwGVjqjPZS9yvAM3jSxPtjLAx9Wx2d0yXCOhGtCS/NbC6vGtdkRJrPzQ blZfHCfaN4TbE45Jj07SwXjVZ3MjYhrhQ3gHZbTDTTBTbDasuNDBwg02dA4446C0nMcf xvIR5rZUXXGXv98tFCILmc9Hop0qeWofgq1P/jsaxWMCcB821Z4ZdLOITyFXNuw8UkgD NcG35lN7VLi6c1Qsuh2i6uKzjSRzDujKjByMgwmPrZugBrwyUyarVpT3hO4TKCZE4zl1 HD2w== X-Gm-Message-State: AKGB3mLcWtKC8pEkUSJMvNWbCDXn2Rlxdl+3j5RsaSRBsT2ce6n0pTYg SPiu7b3QYfdD7z2UdRJ+4HIWkw== X-Google-Smtp-Source: ACJfBos0vuQ7u74xTY/xP8UDo8HKf+tYlBG1vxWI3YMqSPc9Bg07JO0a0z6OOIobvorre+dq0tgWHQ== X-Received: by 10.84.231.130 with SMTP id g2mr12854135plk.309.1515442907758; Mon, 08 Jan 2018 12:21:47 -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 o70sm28540227pfk.79.2018.01.08.12.21.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 12:21:47 -0800 (PST) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: axboe@fb.com, Michael Lyle Subject: [416 PATCH 07/13] bcache: allow quick writeback when backing idle Date: Mon, 8 Jan 2018 12:21:24 -0800 Message-Id: <20180108202130.31303-8-mlyle@lyle.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180108202130.31303-1-mlyle@lyle.org> References: <20180108202130.31303-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 Reviewed-by: Tang Junhui Acked-by: Coly Li --- 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 52b4ce24f9e2..ddd941056f3c 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 6e1d2fde43df..f82ffb2e9b9b 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -356,6 +356,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);