From patchwork Mon May 7 16:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10384463 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 0038C60548 for ; Mon, 7 May 2018 16:13:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE3DA26E98 for ; Mon, 7 May 2018 16:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2B7A287DA; Mon, 7 May 2018 16:13:50 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 7324C28385 for ; Mon, 7 May 2018 16:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752550AbeEGQNt (ORCPT ); Mon, 7 May 2018 12:13:49 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:52932 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752389AbeEGQNs (ORCPT ); Mon, 7 May 2018 12:13:48 -0400 Received: by mail-it0-f67.google.com with SMTP id y189-v6so6398020itb.2 for ; Mon, 07 May 2018 09:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f1kOrenxEDQ/9MCh+eHegmlohnB0LZXC+mbtnaBTapk=; b=FhUl9z8hoMAo9YmLRgZwNaGKr9Q7p2Guk9lsAL70ew0gHgIwkZNFO2rje2iONz6pVM OPgIlCfwlqrPR5hWokSB7wQ/d9tOoWiJ3Fokg0QdpJz/EInWgphH7Tl17UvjmAdECLjm OloeYtbxmsPMvhFzXh8PhJPniZ5lShWp28iErNvpIicQ9PywX0srr37XeA4+BJ8qLrwE pee513awrf1Q7zYFbkGeUO0Eg1ZrptXwa/FEIknSKUqM9knua4tX31WE91CWIqcepTyO gHGGr0ya4wIvamIR77i+wUxGZsZM7sDRgaxe9e6I1sk/thRIo8qsOwTOxIZGeJnCKJth RCsg== 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=f1kOrenxEDQ/9MCh+eHegmlohnB0LZXC+mbtnaBTapk=; b=ixYbxL7JK8A7PPLWjukYfXZ4V7UojY2k5MQsR98zm8goW7MwC45wGdJMD7DHFxjKaR ZjY/3xhTgRMO8BHvU2rThzHbgTknWHTLqLbzZsZTflsSSVYQO3hkSTwPQSbmMdiQt1Bs xMmlp5isBwbuVLnNxLdLmYWsrw9Y//n7nhRi3R04V9iAbckEjCsss0CK5M9RK6pbvdgm CwCInv3VKMBEPl6XbxQWzNUVAQKJHD49puaB6U6tYHj6CAvBfx+7doTPHM1UBtRtaq4h Zq5PDVlQN/yvRNxXpbNyN7qALHGDqRvlVVjuL659VK9TWTMw6CHL8U7R0qxV51mbn+Q9 NH8w== X-Gm-Message-State: ALKqPwcmhv9OX8OAtlFBe+a+THCRUW0lTQ0WoRlHG2lXHokgqeBqxcIw rxNeXLA0oyHY0H4nlqP8ftVaAg== X-Google-Smtp-Source: AB8JxZpRsZtHC+hqQ1p2r9nYh40zMnyleWOHct0iWknFXuoSPI39ydwWSoNnI4TLlwN8kiMaSlR2yA== X-Received: by 2002:a24:7f0d:: with SMTP id r13-v6mr272207itc.39.1525709627520; Mon, 07 May 2018 09:13:47 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id q5-v6sm9003192iod.32.2018.05.07.09.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 May 2018 09:13:46 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org, linux-xfs@vger.kernel.org Cc: dchinner@redhat.com, hch@lst.de, Jens Axboe Subject: [PATCH 4/4] blk-wbt: throttle discards like background writes Date: Mon, 7 May 2018 10:13:35 -0600 Message-Id: <1525709615-14395-5-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525709615-14395-1-git-send-email-axboe@kernel.dk> References: <1525709615-14395-1-git-send-email-axboe@kernel.dk> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Throttle discards like we would any background write. Discards should be background activity, so if they are impacting foreground IO, then we will throttle them down. Signed-off-by: Jens Axboe Reviewed-by: Darrick J. Wong Reviewed-by: Omar Sandoval --- block/blk-stat.h | 6 +++--- block/blk-wbt.c | 43 ++++++++++++++++++++++++++----------------- block/blk-wbt.h | 4 +++- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/block/blk-stat.h b/block/blk-stat.h index 2dd36347252a..c22049a8125e 100644 --- a/block/blk-stat.h +++ b/block/blk-stat.h @@ -10,11 +10,11 @@ /* * from upper: - * 3 bits: reserved for other usage + * 4 bits: reserved for other usage * 12 bits: size - * 49 bits: time + * 48 bits: time */ -#define BLK_STAT_RES_BITS 3 +#define BLK_STAT_RES_BITS 4 #define BLK_STAT_SIZE_BITS 12 #define BLK_STAT_RES_SHIFT (64 - BLK_STAT_RES_BITS) #define BLK_STAT_SIZE_SHIFT (BLK_STAT_RES_SHIFT - BLK_STAT_SIZE_BITS) diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 25d202345965..a7a724580033 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -106,6 +106,8 @@ static inline struct rq_wait *get_rq_wait(struct rq_wb *rwb, { if (wb_acct & WBT_KSWAPD) return &rwb->rq_wait[WBT_RWQ_KSWAPD]; + else if (wb_acct & WBT_DISCARD) + return &rwb->rq_wait[WBT_RWQ_DISCARD]; return &rwb->rq_wait[WBT_RWQ_BG]; } @@ -143,10 +145,13 @@ void __wbt_done(struct rq_wb *rwb, enum wbt_flags wb_acct) } /* - * If the device does write back caching, drop further down - * before we wake people up. + * For discards, our limit is always the background. For writes, if + * the device does write back caching, drop further down before we + * wake people up. */ - if (rwb->wc && !wb_recent_wait(rwb)) + if (wb_acct & WBT_DISCARD) + limit = rwb->wb_background; + else if (rwb->wc && !wb_recent_wait(rwb)) limit = 0; else limit = rwb->wb_normal; @@ -483,6 +488,9 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw) { unsigned int limit; + if ((rw & REQ_OP_MASK) == REQ_OP_DISCARD) + return rwb->wb_background; + /* * At this point we know it's a buffered write. If this is * kswapd trying to free memory, or REQ_SYNC is set, then @@ -564,21 +572,20 @@ static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags wb_acct, static inline bool wbt_should_throttle(struct rq_wb *rwb, struct bio *bio) { - const int op = bio_op(bio); - - /* - * If not a WRITE, do nothing - */ - if (op != REQ_OP_WRITE) - return false; - - /* - * Don't throttle WRITE_ODIRECT - */ - if ((bio->bi_opf & (REQ_SYNC | REQ_IDLE)) == (REQ_SYNC | REQ_IDLE)) + switch (bio_op(bio)) { + case REQ_OP_WRITE: + /* + * Don't throttle WRITE_ODIRECT + */ + if ((bio->bi_opf & (REQ_SYNC | REQ_IDLE)) == + (REQ_SYNC | REQ_IDLE)) + return false; + /* fallthrough */ + case REQ_OP_DISCARD: + return true; + default: return false; - - return true; + } } /* @@ -605,6 +612,8 @@ enum wbt_flags wbt_wait(struct rq_wb *rwb, struct bio *bio, spinlock_t *lock) if (current_is_kswapd()) ret |= WBT_KSWAPD; + if (bio_op(bio) == REQ_OP_DISCARD) + ret |= WBT_DISCARD; __wbt_wait(rwb, ret, bio->bi_opf, lock); diff --git a/block/blk-wbt.h b/block/blk-wbt.h index 8038b4a0d4ef..d6a125e49db5 100644 --- a/block/blk-wbt.h +++ b/block/blk-wbt.h @@ -14,13 +14,15 @@ enum wbt_flags { WBT_TRACKED = 1, /* write, tracked for throttling */ WBT_READ = 2, /* read */ WBT_KSWAPD = 4, /* write, from kswapd */ + WBT_DISCARD = 8, /* discard */ - WBT_NR_BITS = 3, /* number of bits */ + WBT_NR_BITS = 4, /* number of bits */ }; enum { WBT_RWQ_BG = 0, WBT_RWQ_KSWAPD, + WBT_RWQ_DISCARD, WBT_NUM_RWQ, };