Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp881492lqo; Wed, 8 May 2024 19:41:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUw+4tBpW6Opbcflo9s+mCle2tRqlyowpRTWwnJpCMFtRiyUV1rzHb03RGhx0dJr+pOkNIa/9jF1ORHKqmDTn5aklF/4Ro/ZzDVcOILIA== X-Google-Smtp-Source: AGHT+IFJyw/0xJ5yIsVAaK7bg6T0KcTudoAUTH5cUdo32ulGfRnAVSSfAh1/DwPF0k+gYfRS8AKR X-Received: by 2002:a9d:6b92:0:b0:6f0:5d32:d555 with SMTP id 46e09a7af769-6f0b7827676mr4602430a34.6.1715222509397; Wed, 08 May 2024 19:41:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715222509; cv=pass; d=google.com; s=arc-20160816; b=ocw1C9eL3zpNE2ATx2vMMIKOggz0yLYIxJJ8ambC12hg9F6Cbu9EWqotmY8Mi/ak3a bmajQgIFlk1UW7YAiZ2Du4VB9Jyd6uo7vb71Wza+754nfEdZfjMRzL9JClwGbavbvMAQ QVPDk6R9hcEwsb/76pV8pOWJzSuIGkbsdzI2qcQ6HX4jJskjCMQyFHegmHgX7tp8PdMM Sxg1G5qPG7MTS5NJsH2TsBaEAoRBvuXj3anu5Kh+SzI65+kJltX15sUEnUH28GBTKSTV JBHPVqVoXRktYinyVIv4miZX1j6GGq1VRcKVuVKpHRDhXvXD2SiqRd2sXjtI2m1DumV/ 0Vcg== 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=H3BNI8ksWzrbV21JpQetkPrPvYYwX1aT4DvsR0Q11giNNgZdkviAvJ/F4G21QgQZtS oqHiyrwruo1ATJWp4yB7AKR6cZ50vi+hkbJjUjGRQLCk8HGVtRdm2aJtqHOeyQjN8ctl SsAncqcjHmEvtNsPpwWabOnvNYtXSf1Ayog8NElZ3/YoNRth4O2E+Uxy8JnvLrF5o0A4 Cb1Gzki5u1ljRqLDseMJCLHV0ezmZtXSKreLYesLSPlimYBQoalPgo8CLeuAIGzyHmmr sFoRJDe2Rath3I8awYgUZ+x1e7obJk1RdU/wJEgO/eX+Sl3n+qjRzo1cgtJAc7fmhgtv nDUw==; 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-174065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174065-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63412e1efd3si408382a12.758.2024.05.08.19.41.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 19:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-174065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174065-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 89787283B2E for ; Thu, 9 May 2024 02:41:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4798F146D77; Thu, 9 May 2024 02:41:30 +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 0A966146A7C; Thu, 9 May 2024 02:41:27 +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=1715222489; cv=none; b=r320G7sDsz+zZKTizQxcPKMcIFid/0UqsETSwddyB2aPOfDUUM+gC4cdpJ3IRZbGSy4w2hQnO4GL0kTl9Neps4dvWej1p+FWzXXq2QOFj4VC/S5hKhn2IDXQ+fGw5sluZGdosQIpEI3Zt6UkK+1dwQUpf1BtRqW2Dg7NYTmMYn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715222489; c=relaxed/simple; bh=cxIwpQSHcfuYZZ9GvvSMLZ3wG9q7rFvAlf9yitR+PVo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I+Y5RPWRqjzq3kP2YWn2J+J7akh3v2X9H88JFgqPinTeYLgauIJbx3i7P3n3J5D7dMVBJSZIqr3yKEkFzYMz825bjHfmLFmZExIEnhUkeadghVI83ZELTUKoCemuOky6rAupdua/BCHXXc+uQK4NFAiJVyMK/ZDRN99UxhPkutY= 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 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> 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 4492dk5p051858 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