Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3028987lqo; Tue, 14 May 2024 18:25:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFKYQo+FiV9MeCL8HOGpfhSTNlpDuZQWcXD6nWB8UzXu1q60BcQsrYAoVigJ6F0Ix1kVS/66tR9X+eXgBCu1m7kN2nUEYqUu41sujwhQ== X-Google-Smtp-Source: AGHT+IFzap4KpXYAgBhOS3QfcC4ip869FmdHOs7ZqPFZ4oqAMgyttPlBa/TNPb9HIAIx5uN573n/ X-Received: by 2002:ac8:7d0d:0:b0:43e:e6e:21bf with SMTP id d75a77b69052e-43e0e6e261bmr124219641cf.1.1715736327491; Tue, 14 May 2024 18:25:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715736327; cv=pass; d=google.com; s=arc-20160816; b=bYg/RwfPwBBAngDgBAMRmc9SMNW6smNnMTi58kujCldCT6FCLrLsVGkI7YOW4vo1Sl vbUtToO73Dv2O0CCbVjV//HND7aC8i0/vnQE05e5eiZatD5GXBbTD8WlZY0QHCre95fN kY4CY53sWsMQq7KqN5jeZG9HkxFkXIeZANxmliNWsSsO/ClT6fLFpBXAOPpHsi6lZ+8c vCNn0WiRD5RkBiCGVZnOCY3+TTQuryedyQmZ3AmPKFMMUiMCc7i8Bvcvlv0asQlQwvpk PLJFC6ZEVKhhajNy1rGY4pqeWyHnA6DkTFhyX+Bb5QtQVUXo7RvK0KgBRfoHhw1YZ4oS rAFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from; bh=oiG4O2hCRGEcQ6a9VnNAx6PGi18rQEH1MASbp3fUJb4=; fh=aLp6JX2nQZchPp4bZbB1BXrBVzPzKjcTx+fC0wO/zBE=; b=Il0kShN0JrU83DFV34uUxQKhQRF+5hwsGln8dOmdbdpfGj8UJphd0/ZxxHtkL9XHWP jxWCz6D5vqI7w6W8uaXhBiHN63/kP365F8TSXmO2Pr/kRKmIrY4thP3/dNFlrxPUhq6s 8KEZQktnIRPD9vRv3z9HQI7PWbBn8KejxoNgHvL7yvrc8/JbUGAwWAO7yb07YuSCdtrU JNfL3pyTYFGkZeJ/lBrojsZu3mc4vHTD9LMN3E0XrsTtPprFZBnsU4cg0nEU26IcvWmo 80yuU0NSp/LrfgK2pwY1LHgxSXE86U51PWQer0iDvp9vjOeMnXJ+WqkQ/A2GkjguHHV8 EFkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-179317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179317-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df54a1ff7si127562391cf.113.2024.05.14.18.25.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 18:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-179317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179317-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3AD5C1C20DC0 for ; Wed, 15 May 2024 01:25:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BC804430; Wed, 15 May 2024 01:25:18 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3140979C8; Wed, 15 May 2024 01:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715736317; cv=none; b=IwdCQw470jaGV+3kzuGSekIP5C/G/5wXRAaIYYrJ66PJb+oOd5Wd8bQycqA1gA86j8lc3hyuj6qnHl2x4faYP1RCby/+UCIf/cwtywtSY+jSiwcITljCIRv8YYS6tHH8ld1qrGlD0SJ+rDKTHme4XXwS/qHtOSM4sCrdlm4yHMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715736317; c=relaxed/simple; bh=cxIwpQSHcfuYZZ9GvvSMLZ3wG9q7rFvAlf9yitR+PVo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FvmOkqmofK3VTDrJkhHdi9IJNfGkRLg81dG1W6BtJwZiUEra2elIUeLq8tHge5MMsbgSPGVHsyJJPIoeSLe/RCqNG0dzq6PqDwf2El+TKtiX2fk/+rj7JflhI5TRUJofmKDEgQBxRgI8eHX1r5HLZKAb1SkW0oOkt0Z78xip74w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 44F1O5Om051360; Wed, 15 May 2024 09:24:05 +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 4VfFly3fXQz2QDRDk; Wed, 15 May 2024 09:20:46 +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; Wed, 15 May 2024 09:24:03 +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: Wed, 15 May 2024 09:23:49 +0800 Message-ID: <20240515012350.1166350-2-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240515012350.1166350-1-zhaoyang.huang@unisoc.com> References: <20240515012350.1166350-1-zhaoyang.huang@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 44F1O5Om051360 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); -- 2.25.1