From nobody Tue Feb 10 11:56:08 2026 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: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 44F1O5Om051360 Content-Type: text/plain; charset="utf-8" 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 =20 +unsigned long blk_throttle_budgt(struct block_device *bdev) +{ + struct request_queue *q =3D bdev_get_queue(bdev); + struct blkcg *blkcg; + struct blkcg_gq *blkg; + struct throtl_grp *tg; + long long bytes_allowed =3D 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 =3D css_to_blkcg(task_css(current, io_cgrp_id)); + if (!blkcg) + goto out; + + blkg =3D blkg_lookup(blkcg, q); + if (!blkg || !blkg_tryget(blkg)) + goto out; + + tg =3D blkg_to_tg(blkg); + bps_limit =3D tg_bps_limit(tg, READ); + if (bps_limit =3D=3D U64_MAX) + goto out; + + jiffy_elapsed =3D jiffy_elapsed_rnd =3D jiffies - tg->slice_start[READ]; + if (!jiffy_elapsed) + jiffy_elapsed_rnd =3D tg->td->throtl_slice; + + jiffy_elapsed_rnd =3D roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); + bytes_allowed =3D 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 =3D 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 @@ */ =20 #include +#include =20 struct bio; struct cgroup_subsys_state; struct gendisk; +struct block_device; =20 #define FC_APPID_LEN 129 =20 @@ -45,6 +47,14 @@ static inline struct cgroup_subsys_state *bio_blkcg_css(= struct bio *bio) } #endif /* CONFIG_BLK_CGROUP */ =20 +#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); =20 --=20 2.25.1 From nobody Tue Feb 10 11:56:08 2026 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 313B279C0; 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=1715736318; cv=none; b=bb9eCobtPHXe4hITyimPE6uNWKlgzVfB6iw3UT6vDaXxj5FC8Wt2RVUxEn9xmM+/WoRsJzlAR87AXeHMuLakxyoRS1/wD3CJcyBgJkAmYFOCrPG9+CmM3qBKDhNV1FDsJphzbToJwWObqcS8dy1JFVHRjKAJ3VPXNO1CC6AgOZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715736318; c=relaxed/simple; bh=yMMIUz7DubXFQXYpZ3HCVv1OQrz7GVWdZJEPrbTdrZU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dc6mmrOdRG0g69A4CAdUL+JVxry2oWuVlTq4o4bIiybNIaaFeY9IFLp4P5RhOny07ZLTpjuZQh1IvN5qqJv/92NB1ksZpIbJSvQpSaZkXcG7ksxlPtYS2mfDfnCltBbinJpHFiThBA26cbBWuJJE6vc/LDI8PRphEUjuA6wBSV8= 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 44F1O7LZ051706; Wed, 15 May 2024 09:24:07 +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 4VfFm04QmWz2PDtZH; Wed, 15 May 2024 09:20:48 +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:05 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Jens Axboe , Tejun Heo , Josef Bacik , Baolin Wang , , , , , Zhaoyang Huang , Subject: [RFC PATCH 2/2] mm: introduce budgt control in readahead Date: Wed, 15 May 2024 09:23:50 +0800 Message-ID: <20240515012350.1166350-3-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: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 44F1O7LZ051706 Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang Currently, readahead's size is decided mainly by page cache's status like hit/miss or hole size which could lead to suspension of following bio which is over the size of blk-throttle allowed size when BLK_THROTTLING is on. Introduce the budgt value here to have the bio's size be within the legal size. Signed-off-by: Zhaoyang Huang --- mm/readahead.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 130c0e7df99f..2b6120ced6f9 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -358,16 +359,23 @@ static unsigned long get_init_ra_size(unsigned long s= ize, unsigned long max) * Get the previous window size, ramp it up, and * return it as the new window size. */ -static unsigned long get_next_ra_size(struct file_ra_state *ra, +static unsigned long get_next_ra_size(struct readahead_control *ractl, unsigned long max) { - unsigned long cur =3D ra->size; + unsigned long cur =3D ractl->ra->size; + struct inode *inode =3D ractl->mapping->host; + unsigned long budgt =3D inode->i_sb->s_bdev ? + blk_throttle_budgt(inode->i_sb->s_bdev) : 0; + unsigned long val =3D max; =20 if (cur < max / 16) - return 4 * cur; + val =3D 4 * cur; if (cur <=3D max / 2) - return 2 * cur; - return max; + val =3D 2 * cur; + + val =3D budgt ? min(budgt / PAGE_SIZE, val) : val; + + return val; } =20 /* @@ -437,6 +445,8 @@ static int try_context_readahead(struct address_space *= mapping, unsigned long max) { pgoff_t size; + unsigned long budgt =3D mapping->host->i_sb->s_bdev ? + blk_throttle_budgt(mapping->host->i_sb->s_bdev) : 0; =20 size =3D count_history_pages(mapping, index, max); =20 @@ -455,7 +465,7 @@ static int try_context_readahead(struct address_space *= mapping, size *=3D 2; =20 ra->start =3D index; - ra->size =3D min(size + req_size, max); + ra->size =3D min3(budgt / PAGE_SIZE, size + req_size, max); ra->async_size =3D 1; =20 return 1; @@ -552,6 +562,8 @@ static void ondemand_readahead(struct readahead_control= *ractl, pgoff_t index =3D readahead_index(ractl); pgoff_t expected, prev_index; unsigned int order =3D folio ? folio_order(folio) : 0; + unsigned long budgt =3D ractl->mapping->host->i_sb->s_bdev ? + blk_throttle_budgt(ractl->mapping->host->i_sb->s_bdev) : 0; =20 /* * If the request exceeds the readahead window, allow the read to @@ -574,7 +586,7 @@ static void ondemand_readahead(struct readahead_control= *ractl, 1UL << order); if (index =3D=3D expected || index =3D=3D (ra->start + ra->size)) { ra->start +=3D ra->size; - ra->size =3D get_next_ra_size(ra, max_pages); + ra->size =3D get_next_ra_size(ractl, max_pages); ra->async_size =3D ra->size; goto readit; } @@ -599,7 +611,7 @@ static void ondemand_readahead(struct readahead_control= *ractl, ra->start =3D start; ra->size =3D start - index; /* old async_size */ ra->size +=3D req_size; - ra->size =3D get_next_ra_size(ra, max_pages); + ra->size =3D get_next_ra_size(ractl, max_pages); ra->async_size =3D ra->size; goto readit; } @@ -631,6 +643,9 @@ static void ondemand_readahead(struct readahead_control= *ractl, * standalone, small random read * Read as is, and do not pollute the readahead state. */ + if (budgt) + req_size =3D min(budgt / PAGE_SIZE, req_size); + do_page_cache_ra(ractl, req_size, 0); return; =20 @@ -647,7 +662,7 @@ static void ondemand_readahead(struct readahead_control= *ractl, * Take care of maximum IO pages as above. */ if (index =3D=3D ra->start && ra->size =3D=3D ra->async_size) { - add_pages =3D get_next_ra_size(ra, max_pages); + add_pages =3D get_next_ra_size(ractl, max_pages); if (ra->size + add_pages <=3D max_pages) { ra->async_size =3D add_pages; ra->size +=3D add_pages; --=20 2.25.1