From patchwork Thu Jan 4 11:08:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Qi X-Patchwork-Id: 10144471 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 6BD1F60594 for ; Thu, 4 Jan 2018 11:08:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E30A2811A for ; Thu, 4 Jan 2018 11:08:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4273D2846F; Thu, 4 Jan 2018 11:08:53 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 43B652811A for ; Thu, 4 Jan 2018 11:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752605AbeADLIt (ORCPT ); Thu, 4 Jan 2018 06:08:49 -0500 Received: from mail-oi0-f67.google.com ([209.85.218.67]:37429 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752159AbeADLIs (ORCPT ); Thu, 4 Jan 2018 06:08:48 -0500 Received: by mail-oi0-f67.google.com with SMTP id y75so797357oie.4 for ; Thu, 04 Jan 2018 03:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=GPZQPGZiAbVq5u0oOiWtygp0ALfmK6EurLYIqT9Ij18=; b=PGZW/80UAjU3cYtgqM8u9SSWtU+V/63DSU6lLB6WmxFODZ3wFlwaIsRVVZ06njqZUR RCJjAALGeQvI1RshWUcM2Anl52l1ZgSS1QUcaa5DnpPFybzDW/o3+HeaTs0R9BBQeXAt xyIsKWGBjYir6gSWBDonuNtTDYnd0Nw3MIjM+0YsIWcwsTJWAbq4c/dDT64eGzI4xiBj EpP5FMwxp55djoJwbEwt8fqsSJU5WzHaZ+9z44wU6XmddcU8iqAgo1FF0GlXc/djqz2H 9vLcB6i//5ho4SgeEAk66gGl1942MMC87+AdaL/ADmbs0Kq3tawb0wg21yqnPRq5wAyf RtKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=GPZQPGZiAbVq5u0oOiWtygp0ALfmK6EurLYIqT9Ij18=; b=HnZUar/guofLJ9G3nKcqhpQADlYeYfytvghvm+x40iTs8kbhiuQFaBzMtdQvOu9HYN u1xPQyeqZkSlp9fyOF+9Ht+fjQc9NZfOB4R5ItcA7hRQtHUEdmeuadQ1P1dZH5Hp6cd+ EUsGKMm+RD37eReMGQJXhUFEmf+SyKtJHxMWDD8hSBfwDK/AAOKkvucM888Gmxt902Bs ZmrVAha4E790x323ghyojYj1JDqJ+4gYop93LJSfuvP5PURa+On9m3Y2OOueXJSC5JC3 v+8G9gxCqsUshJ/reeE7sDBIqwKwRuYuFI7FrDiCawTnlS7JIradqdyPjSilC/7tB7KG D3/Q== X-Gm-Message-State: AKGB3mIHxV4t7v5USd1udeYybAUZ1PSKm1TOAU2lxT4wHP6MSiPxa2GZ 21MxSuSWkh5UyR+rci8ovDOOTkBW X-Google-Smtp-Source: ACJfBosDQW4jmsy7nkmTAnGxorCrjzrX/rhxRqXni5+lHKiB33d3c5WwR33fFNce7qCCH126Wwwzrg== X-Received: by 10.202.102.145 with SMTP id m17mr2142688oik.202.1515064128096; Thu, 04 Jan 2018 03:08:48 -0800 (PST) Received: from JosephdeMacBook-Pro.local ([205.204.117.3]) by smtp.gmail.com with ESMTPSA id t90sm1418125ota.73.2018.01.04.03.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jan 2018 03:08:47 -0800 (PST) From: Joseph Qi Subject: [PATCH 3/3] blk-throttle: do downgrade/upgrade check when issuing io to lower layer To: Jens Axboe , Shaohua Li Cc: jinli.zjl@alibaba-inc.com, qijiang.qj@alibaba-inc.com, linux-block Message-ID: <21feac46-091c-8a41-a69c-ebb44646f5be@gmail.com> Date: Thu, 4 Jan 2018 19:08:32 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Language: en-US 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: Joseph Qi Currently downgrade/upgrade check is done when io firstly comes to block throttle layer. In case of writeback, a large number of ios will firstly be throttled in throttle queue and then dispatched when timer kicked, which won't be checked because REQ_THROTTLED is set. This will lead to low limit not guaranteed most of time. Fix this case by moving check logic down, in which we are ready to issue io to lower layer. Signed-off-by: Joseph Qi --- block/blk-throttle.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 9c0b5ff..6207554 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1065,8 +1065,6 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio) /* Charge the bio to the group */ tg->bytes_disp[rw] += bio_size; tg->io_disp[rw]++; - tg->last_bytes_disp[rw] += bio_size; - tg->last_io_disp[rw]++; /* * BIO_THROTTLED is used to prevent the same bio to be throttled @@ -2166,7 +2164,8 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, struct bio *bio) { struct throtl_qnode *qn = NULL; - struct throtl_grp *tg = blkg_to_tg(blkg ?: q->root_blkg); + struct throtl_grp *orig_tg = blkg_to_tg(blkg ?: q->root_blkg); + struct throtl_grp *tg = orig_tg; struct throtl_service_queue *sq; bool rw = bio_data_dir(bio); bool throttled = false; @@ -2174,11 +2173,11 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, WARN_ON_ONCE(!rcu_read_lock_held()); + spin_lock_irq(q->queue_lock); + /* see throtl_charge_bio() */ if (bio_flagged(bio, BIO_THROTTLED) || !tg->has_rules[rw]) - goto out; - - spin_lock_irq(q->queue_lock); + goto out_unlock; throtl_update_latency_buckets(td); @@ -2194,15 +2193,12 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, while (true) { if (tg->last_low_overflow_time[rw] == 0) tg->last_low_overflow_time[rw] = jiffies; - throtl_downgrade_check(tg); - throtl_upgrade_check(tg); /* throtl is FIFO - if bios are already queued, should queue */ if (sq->nr_queued[rw]) break; /* if above limits, break to queue */ if (!tg_may_dispatch(tg, bio, NULL)) { - tg->last_low_overflow_time[rw] = jiffies; if (throtl_can_upgrade(td, tg)) { throtl_upgrade_state(td); goto again; @@ -2246,8 +2242,6 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, tg->io_disp[rw], tg_iops_limit(tg, rw), sq->nr_queued[READ], sq->nr_queued[WRITE]); - tg->last_low_overflow_time[rw] = jiffies; - td->nr_queued[rw]++; throtl_add_bio_tg(bio, qn, tg); throttled = true; @@ -2264,8 +2258,13 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, } out_unlock: + throtl_downgrade_check(orig_tg); + throtl_upgrade_check(orig_tg); + if (!throttled) { + orig_tg->last_bytes_disp[rw] += throtl_bio_data_size(bio); + orig_tg->last_io_disp[rw]++; + } spin_unlock_irq(q->queue_lock); -out: bio_set_flag(bio, BIO_THROTTLED); #ifdef CONFIG_BLK_DEV_THROTTLING_LOW