From patchwork Thu May 9 02:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13659394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAC42C04FFE for ; Thu, 9 May 2024 02:41:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7716F6B0092; Wed, 8 May 2024 22:41:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70E896B0099; Wed, 8 May 2024 22:41:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 201976B0092; Wed, 8 May 2024 22:41:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CB0D36B0092 for ; Wed, 8 May 2024 22:41:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D87B40734 for ; Thu, 9 May 2024 02:41:21 +0000 (UTC) X-FDA: 82097305962.03.3FF8794 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf08.hostedemail.com (Postfix) with ESMTP id 7A764160008 for ; Thu, 9 May 2024 02:41:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715222479; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oiG4O2hCRGEcQ6a9VnNAx6PGi18rQEH1MASbp3fUJb4=; b=1WyvHSiqabMlbweH3imD+/02JF/KI4ibApi/mz4PwysQ9jpjpDw67hDOF5XMqXVMzYBsHc SgonsONAdy6odbLDiLOzFo1Yu/7PpgX/OTXOQxWjV+m19/bbSrcGdFr7Qv4NwUyzoBA3It eMOLdFgDEbyvoW7/4T2HAxp9HAoxGkA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715222479; a=rsa-sha256; cv=none; b=a0o/tDCkYR5kF5QNPY3cb+bbM7mHKGUD9MxyMjrYSx/irLo9ECaoNaf/lRjjJ4dXhxRn4r VDK6B1Hxb/YSxn656unDfcGmIZrCRnqYkZROkl+A9qDP52QY8wjrVDqibBBi9W75wDCB3c RHjHSHDSe/lHwhHBkDUDjs7eEm84yww= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 4492dk5p051858; Thu, 9 May 2024 10:39:46 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4VZbkH4hbGz2PGl6X; Thu, 9 May 2024 10:36:39 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 9 May 2024 10:39:43 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Jens Axboe , Tejun Heo , Josef Bacik , Baolin Wang , , , , , Zhaoyang Huang , Subject: [RFC PATCH 1/2] block: introduce helper function to calculate bps budgt Date: Thu, 9 May 2024 10:39:36 +0800 Message-ID: <20240509023937.1090421-2-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240509023937.1090421-1-zhaoyang.huang@unisoc.com> References: <20240509023937.1090421-1-zhaoyang.huang@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 4492dk5p051858 X-Rspamd-Queue-Id: 7A764160008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3gkknm9rehmwtu8zgwdmmnsidy3fc1xf X-HE-Tag: 1715222478-636296 X-HE-Meta: U2FsdGVkX1/mGnXkGSqP2bCFW7/7vU8D7wNHqI9R8FqJcBPTirzXwwKvkfCWuCtydFVtdiRfggnPF6zK8BXcKEpNxeT/+LjSYg71s5CHyROJx+Wp7XJ2d3l80UMN8L3oCuotuFp1YcNieiw9VrBbLLAKwwVv26EO1fz3KM3/oHMdqoxgYvaJ4xLP1CTiacfADfTklQICEr7kHqy79aXGIiBxa8t+UDYOtDKGuKReBSwGb+hHl7WGEwvDeKXN8ru/CAZ3jIVUuqWGJLAV5mGth36KeDskVgfi6Q3qLmStoLHxIyEoP0uA8LmWjgyQQ0R2TSrrll4z6EmbnTQpZngSkAhNPHzN7/gwQ8QZUaGvlPr9pM11AnMt3CSjt9ECf/0VnirONOjhvicUGSa57JTEj+3IMC+R5NDIE79Zbl2/LYa2Ph0pzqo4OT4ryUwWCinD3CZGlQVJVEHRKEZ7lj6duie2EzUQontGwx1EjkzII3OyWE+SnHj8CtikpPWPFuxtpjI5M2zCR5C/hoV71VCsfuDdk4aewejTIbwJgUE9UB0n2dnGXPa+JPP/7NHPGESKQsU8l70FQiO01Aak5bVvWXrpe+usAh7RFRU2yW2N3+9L1YoLDBDcxlnyC233cj+VGQTQwKp+0jRjqCApFkdQQoFSphZnj96AGdv8Nymenkwog84CHcJUaP1Dg5fxOPxxaXRMwc3Swas+tXtrsmN6sDQOuJBEplT5/MVhK1ZAlHMmx6P5O02UeAK2IZco9U/ldKGy9EvWK4GQLoz1b2u9H4YPUtiHQLm1NmUNc1nroQFYgjfWGztrjiVmUGIhv+27OO9rQ+eRnoVecUiFO8qEOGWbf5cIggWh/NHl1bqe+sbIxLsQCsXRC85wcZC1Kwq5ltgHsrNX37ucGNcIR7NwpyssrPkxSNW8NALAGR4Sr5P3aJ2CPLzPGB2zxsZvv+wQK5kJBnRCoe3TlpG+QxH k2mhA2HL y+uG31iGEylKR72YUnUROEhpajJxA7mNiRHsnbSPRWgm4AqJJ3gNC08GAW8zY/4+n5FJzsuIUhwWNrgJl+69liuL6ZvbY3NVHITS1mJuc3/vGgpvvPu2r9AW/2axWKwKhezAKoSnQ952KtKPQ4V92TNaVH7Y1ZVC3ZDaT3UEFPGm7N4SFcOdZX+ToB0A9pKgtUVlHWRve2D+0vO0LgvFkQje2KmC+9+ZSdijMaedHrMYl5KY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhaoyang Huang The 'over-sized' bio under blk throttle control will be delayed to launch which breaks original IO timing and have the immediate BW be not within the bps limit. Introduce a helper function to calculate block device's budgt which provide the allowed bytes for current bio. Signed-off-by: Zhaoyang Huang --- block/blk-throttle.c | 44 ++++++++++++++++++++++++++++++++++++++ include/linux/blk-cgroup.h | 10 +++++++++ 2 files changed, 54 insertions(+) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index f4850a6f860b..41c75258183d 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "blk.h" #include "blk-cgroup-rwstat.h" #include "blk-stat.h" @@ -2365,6 +2366,49 @@ void blk_throtl_bio_endio(struct bio *bio) } #endif +unsigned long blk_throttle_budgt(struct block_device *bdev) +{ + struct request_queue *q = bdev_get_queue(bdev); + struct blkcg *blkcg; + struct blkcg_gq *blkg; + struct throtl_grp *tg; + long long bytes_allowed = 0; + unsigned long jiffy_elapsed, jiffy_elapsed_rnd; + u64 bps_limit; + + if (!q) + return U64_MAX; + + rcu_read_lock(); + spin_lock_irq(&q->queue_lock); + blkcg = css_to_blkcg(task_css(current, io_cgrp_id)); + if (!blkcg) + goto out; + + blkg = blkg_lookup(blkcg, q); + if (!blkg || !blkg_tryget(blkg)) + goto out; + + tg = blkg_to_tg(blkg); + bps_limit = tg_bps_limit(tg, READ); + if (bps_limit == U64_MAX) + goto out; + + jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[READ]; + if (!jiffy_elapsed) + jiffy_elapsed_rnd = tg->td->throtl_slice; + + jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); + bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) + + tg->carryover_bytes[READ]; + blkg_put(blkg); +out: + spin_unlock_irq(&q->queue_lock); + rcu_read_unlock(); + return bytes_allowed; +} + + int blk_throtl_init(struct gendisk *disk) { struct request_queue *q = disk->queue; diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index dd5841a42c33..ba79fa464e0a 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -15,10 +15,12 @@ */ #include +#include struct bio; struct cgroup_subsys_state; struct gendisk; +struct block_device; #define FC_APPID_LEN 129 @@ -45,6 +47,14 @@ static inline struct cgroup_subsys_state *bio_blkcg_css(struct bio *bio) } #endif /* CONFIG_BLK_CGROUP */ +#ifdef CONFIG_BLK_DEV_THROTTLING +unsigned long blk_throttle_budgt(struct block_device *bdev); +#else +static inline unsigned long blk_throttle_budgt(struct block_device *bdev) +{ + return U64_MAX; +} +#endif int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len); char *blkcg_get_fc_appid(struct bio *bio);