From patchwork Wed Jan 10 05:02:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufei Xue X-Patchwork-Id: 10153959 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 B0D3E60231 for ; Wed, 10 Jan 2018 05:02:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A239E1FF87 for ; Wed, 10 Jan 2018 05:02:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9710227F86; Wed, 10 Jan 2018 05:02:43 +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 6EFB31FF87 for ; Wed, 10 Jan 2018 05:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934067AbeAJFCj (ORCPT ); Wed, 10 Jan 2018 00:02:39 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:43634 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934028AbeAJFCf (ORCPT ); Wed, 10 Jan 2018 00:02:35 -0500 Received: by mail-ot0-f195.google.com with SMTP id t28so3166542oti.10 for ; Tue, 09 Jan 2018 21:02:35 -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=+ZXFTApGpELTyXksGUvdAtkgnKGFuQZv1D8UMOKwP5E=; b=egyDyluEWd1A2S9UtJ+Z4aEiwlCUwr8eA3PGhMhHjyYuCygxQgeO/Ui5sM3KUV2aVb hz2CEx8KCbY+eba1eRJEfsusyou7KL1Gc+gHQIafPvK+xHtK3L+3O9xVSyQYGZK7oD9D 1PQ7Ef631MQkP9elq1IeE+XG10siDJQUKW97jLy5ky218bi3neVxsC2Tj6islF6BlWZe A2O2LP5DRyPbVWW9fUqAoT+iGkLizp80XZjUSfCd1Y4LIR+64/qVwwR5tclbaSK2h4jN RTAoerke72Q/NxUWh1KJxUjjH8X7DMYPPN/DBTyDTkJAeUjADDM+Z6OKltltvB7HRAOd mWZg== 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=+ZXFTApGpELTyXksGUvdAtkgnKGFuQZv1D8UMOKwP5E=; b=lPCzu8Md3Gbrd5iYR++vaWNk2b0NSglfwQZKkTsJkPFmsVcQ+h7NDJ+G90t8PP5H+k t5OzZ080ByS171xzLI4Ip38hYvg8cVmL3+GAWkvz+40CwSQjJH+maC5Mh/fkkxBhxt++ JpY3sY5mGpvafAKyJbHkEdiwsRFgGn2EdVyQCkNFxkSAHsOz8KfcmZOaUIDs/Hx5jjbF MQitIfw18He7oeAWG7mwDTaTEQFPL1To4ciPZNzh5wujyN5voGDdm37DSGo0JOksSzrn x8oBdd07974g0xuRiRRY0LbvFAajcdFYTniD8b2bErc10TjyMsHJZJDI+s/W1szNv3H+ eAxg== X-Gm-Message-State: AKwxytdNgzyjjGrf7s8CewOFluf1IX75N4n8hx3WAfNNVuJGgIOiA4AB nqJVZdZagXZlwJkwzuo9rhM= X-Google-Smtp-Source: ACJfBotUKOtzIPbeFGO7u9c8LoHyUpcIIQlaJz3tq8gDlVpRN8qtJ967DoirsQJ//rLwZ6qNZJ4DQw== X-Received: by 10.157.68.230 with SMTP id p38mr3856039otg.6.1515560555295; Tue, 09 Jan 2018 21:02:35 -0800 (PST) Received: from ali-186590e05fa3.local ([205.204.117.26]) by smtp.gmail.com with ESMTPSA id z51sm7912670otc.36.2018.01.09.21.02.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 21:02:34 -0800 (PST) From: xuejiufei Subject: [PATCH] blk-throttle: avoid double counted To: linux-block@vger.kernel.org, Jens Axboe Cc: jiufei.xjf@alibaba-inc.com, Shaohua Li Message-ID: <4448dd08-74b5-ef8f-e227-49c8e3dbe3eb@gmail.com> Date: Wed, 10 Jan 2018 13:02:29 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 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: Jiufei Xue If a bio is split after counted to the stat_bytes and stat_ios in blkcg_bio_issue_check(), the bio could be resubmited and enters the block throttle layer again. This will cause the part of the bio is counted twice. The flag BIO_THROTTLED can not be used to fix this problem considering the following two cases. 1. The bio is throttled and resubmited to the block throttle layer. It has the flag BIO_THROTTLED and should be counted. 2. The bio can be dispathed and has counted, and then is split and resubmitted to the block throttle layer. It also has the flag BIO_THROTTLED but should not be counted again. So we add another flag BIO_THROTL_COUNTED to avoid double counted. Signed-off-by: Jiufei Xue --- block/bio.c | 2 ++ include/linux/bio.h | 6 ++++-- include/linux/blk-cgroup.h | 3 ++- include/linux/blk_types.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/block/bio.c b/block/bio.c index 9ef6cf3..4594c2e 100644 --- a/block/bio.c +++ b/block/bio.c @@ -601,6 +601,8 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src) bio_set_flag(bio, BIO_CLONED); if (bio_flagged(bio_src, BIO_THROTTLED)) bio_set_flag(bio, BIO_THROTTLED); + if (bio_flagged(bio_src, BIO_THROTL_COUNTED)) + bio_set_flag(bio, BIO_THROTL_COUNTED); bio->bi_opf = bio_src->bi_opf; bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter = bio_src->bi_iter; diff --git a/include/linux/bio.h b/include/linux/bio.h index 23d29b3..aefc24c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -492,8 +492,10 @@ extern struct bio *bio_copy_user_iov(struct request_queue *, #define bio_set_dev(bio, bdev) \ do { \ - if ((bio)->bi_disk != (bdev)->bd_disk) \ - bio_clear_flag(bio, BIO_THROTTLED);\ + if ((bio)->bi_disk != (bdev)->bd_disk) { \ + bio_clear_flag(bio, BIO_THROTTLED); \ + bio_clear_flag(bio, BIO_THROTL_COUNTED);\ + } \ (bio)->bi_disk = (bdev)->bd_disk; \ (bio)->bi_partno = (bdev)->bd_partno; \ } while (0) diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index e9825ff..c151bc9 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -701,11 +701,12 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, throtl = blk_throtl_bio(q, blkg, bio); - if (!throtl) { + if (!throtl && !bio_flagged(bio, BIO_THROTL_COUNTED)) { blkg = blkg ?: q->root_blkg; blkg_rwstat_add(&blkg->stat_bytes, bio->bi_opf, bio->bi_iter.bi_size); blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1); + bio_set_flag(bio, BIO_THROTL_COUNTED); } rcu_read_unlock(); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 9e7d8bd..7a3890a 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -135,6 +135,7 @@ struct bio { * throttling rules. Don't do it again. */ #define BIO_TRACE_COMPLETION 10 /* bio_endio() should trace the final completion * of this bio. */ +#define BIO_THROTL_COUNTED 11 /* This bio has already counted to rwstat. */ /* See BVEC_POOL_OFFSET below before adding new flags */ /*