From patchwork Fri Oct 6 11:45:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 9989033 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 70F8160247 for ; Fri, 6 Oct 2017 11:45:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6373E28CD7 for ; Fri, 6 Oct 2017 11:45:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 588E728D70; Fri, 6 Oct 2017 11:45:33 +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, 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 CBA2128CD7 for ; Fri, 6 Oct 2017 11:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751535AbdJFLpb (ORCPT ); Fri, 6 Oct 2017 07:45:31 -0400 Received: from forwardcorp1j.cmail.yandex.net ([5.255.227.106]:51413 "EHLO forwardcorp1j.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbdJFLpb (ORCPT ); Fri, 6 Oct 2017 07:45:31 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id 999D720DCC; Fri, 6 Oct 2017 14:45:28 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id 921902440B76; Fri, 6 Oct 2017 14:45:28 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:f1eb:8412:ce38:c408]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id MsrqraLyyo-jSxCqUKg; Fri, 06 Oct 2017 14:45:28 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1507290328; bh=YoVZBQFQShK7CkrAxPh6EgBupDyR094jIOqbG2dCAgI=; h=Subject:From:To:Cc:Date:Message-ID; b=pYIRPBHXYLIb6/T1xaxHqpEp38EVcD20kq2RKDcIyL5UgsqtLC/xwU5axIkE4UsxE 6l3bCpZiLZXc6hBOULHBc+rIiXd893wbBN8vO/Ua0WJRhCQs5UM+KvJAlkWujFqI4r nHuxlpLzyCPWcrJkznzopp0eJWJlqRhRg1tN2b08= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH RFC] blk-throttle: add feedback to cgroup writeback about throttled writes From: Konstantin Khlebnikov To: linux-block@vger.kernel.org, Jens Axboe , linux-kernel@vger.kernel.org Cc: Tejun Heo , linux-mm@kvack.org, Andrew Morton Date: Fri, 06 Oct 2017 14:45:26 +0300 Message-ID: <150729032600.744699.6582090880216248200.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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 Throttler steals bio before allocating requests for them, thus throttled writeback never reaches congestion. This adds bit WB_write_throttled into per-cgroup bdi congestion control. It's set when write bandwidth limit is exceeded and throttler has at least one bio inside and cleared when last throttled bio is gone. Signed-off-by: Konstantin Khlebnikov --- block/blk-throttle.c | 8 ++++++++ include/linux/backing-dev-defs.h | 19 +++++++++++++++++++ include/linux/backing-dev.h | 6 ++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 0fea76aa0f3f..7ec0aaf9efa7 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1145,6 +1145,10 @@ static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw) bio = throtl_pop_queued(&sq->queued[rw], &tg_to_put); sq->nr_queued[rw]--; + /* Last throttled @bio is gone, clear congestion bit. */ + if (rw && !sq->nr_queued[rw]) + clear_wb_throttled(tg_to_blkg(tg)->wb_congested); + throtl_charge_bio(tg, bio); /* @@ -2215,6 +2219,10 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, * its @tg's disptime is not in the future. */ if (tg->flags & THROTL_TG_WAS_EMPTY) { + /* Next write will be throttled, set congestion bit. */ + if (rw && blkg) + set_wb_throttled(blkg->wb_congested); + tg_update_disptime(tg); throtl_schedule_next_dispatch(tg->service_queue.parent_sq, true); } diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index 866c433e7d32..343107fd4eff 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -29,6 +29,7 @@ enum wb_state { enum wb_congested_state { WB_async_congested, /* The async (write) queue is getting full */ WB_sync_congested, /* The sync queue is getting full */ + WB_write_throttled, /* Associated blkcg is throttled */ }; typedef int (congested_fn)(void *, int); @@ -200,6 +201,16 @@ static inline void set_bdi_congested(struct backing_dev_info *bdi, int sync) #ifdef CONFIG_CGROUP_WRITEBACK +static inline void set_wb_throttled(struct bdi_writeback_congested *congested) +{ + set_bit(WB_write_throttled, &congested->state); +} + +static inline void clear_wb_throttled(struct bdi_writeback_congested *congested) +{ + clear_bit(WB_write_throttled, &congested->state); +} + /** * wb_tryget - try to increment a wb's refcount * @wb: bdi_writeback to get @@ -244,6 +255,14 @@ static inline bool wb_dying(struct bdi_writeback *wb) #else /* CONFIG_CGROUP_WRITEBACK */ +static inline void set_wb_throttled(struct bdi_writeback_congested *congested) +{ +} + +static inline void clear_wb_throttled(struct bdi_writeback_congested *congested) +{ +} + static inline bool wb_tryget(struct bdi_writeback *wb) { return true; diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 854e1bdd0b2a..3619641b5ec5 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -460,13 +460,15 @@ static inline int inode_read_congested(struct inode *inode) static inline int inode_write_congested(struct inode *inode) { - return inode_congested(inode, 1 << WB_async_congested); + return inode_congested(inode, (1 << WB_async_congested) | + (1 << WB_write_throttled)); } static inline int inode_rw_congested(struct inode *inode) { return inode_congested(inode, (1 << WB_sync_congested) | - (1 << WB_async_congested)); + (1 << WB_async_congested) | + (1 << WB_write_throttled)); } static inline int bdi_congested(struct backing_dev_info *bdi, int cong_bits)