From patchwork Wed Feb 14 03:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufei Xue X-Patchwork-Id: 10217985 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 BB28F6055C for ; Wed, 14 Feb 2018 03:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B40E128DA9 for ; Wed, 14 Feb 2018 03:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A46C628DB3; Wed, 14 Feb 2018 03:22:19 +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, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 0EF6728DA9 for ; Wed, 14 Feb 2018 03:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966717AbeBNDWS (ORCPT ); Tue, 13 Feb 2018 22:22:18 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:35311 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966588AbeBNDWQ (ORCPT ); Tue, 13 Feb 2018 22:22:16 -0500 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R151e4; CH=green; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e07488; MF=jiufei.xue@linux.alibaba.com; NM=1; PH=DS; RN=6; SR=0; TI=SMTPD_---0Sy7V0vn_1518578531; Received: from ali-186590e05fa3.local(mailfrom:jiufei.xue@linux.alibaba.com fp:42.120.74.106) by smtp.aliyun-inc.com(127.0.0.1); Wed, 14 Feb 2018 11:22:11 +0800 To: Shaohua Li , Jens Axboe Cc: linux-block@vger.kernel.org, caspar@linux.alibaba.com From: xuejiufei Subject: [PATCH RESEND] blk-throttle: avoid double counted Message-ID: Date: Wed, 14 Feb 2018 11:22:10 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.6.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 If a bio is split after counted to the stat_bytes and stat_ios in blkcg_bio_issue_check(), the bio could be resubmitted 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 resubmitted to the block throttle layer. It has the flag BIO_THROTTLED and should be counted. 2. The bio can be dispatched and has been counted, then it 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 Reviewed-by: Liu Bo Tested-by: Liu Bo --- 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 */ /*