From: "zhaoyang.huang" <zhaoyang.huang@unisoc.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>,
Josef Bacik <josef@toxicpanda.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>, <linux-mm@kvack.org>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<cgroups@vger.kernel.org>,
Zhaoyang Huang <huangzhaoyang@gmail.com>, <steve.kang@unisoc.com>
Subject: [RFC PATCH 2/2] mm: introduce budgt control in readahead
Date: Thu, 9 May 2024 10:39:37 +0800 [thread overview]
Message-ID: <20240509023937.1090421-3-zhaoyang.huang@unisoc.com> (raw)
In-Reply-To: <20240509023937.1090421-1-zhaoyang.huang@unisoc.com>
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
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 <zhaoyang.huang@unisoc.com>
---
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 <linux/blk-cgroup.h>
#include <linux/fadvise.h>
#include <linux/sched/mm.h>
+#include <linux/minmax.h>
#include "internal.h"
@@ -358,16 +359,23 @@ static unsigned long get_init_ra_size(unsigned long size, 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 = ra->size;
+ unsigned long cur = ractl->ra->size;
+ struct inode *inode = ractl->mapping->host;
+ unsigned long budgt = inode->i_sb->s_bdev ?
+ blk_throttle_budgt(inode->i_sb->s_bdev) : 0;
+ unsigned long val = max;
if (cur < max / 16)
- return 4 * cur;
+ val = 4 * cur;
if (cur <= max / 2)
- return 2 * cur;
- return max;
+ val = 2 * cur;
+
+ val = budgt ? min(budgt / PAGE_SIZE, val) : val;
+
+ return val;
}
/*
@@ -437,6 +445,8 @@ static int try_context_readahead(struct address_space *mapping,
unsigned long max)
{
pgoff_t size;
+ unsigned long budgt = mapping->host->i_sb->s_bdev ?
+ blk_throttle_budgt(mapping->host->i_sb->s_bdev) : 0;
size = count_history_pages(mapping, index, max);
@@ -455,7 +465,7 @@ static int try_context_readahead(struct address_space *mapping,
size *= 2;
ra->start = index;
- ra->size = min(size + req_size, max);
+ ra->size = min3(budgt / PAGE_SIZE, size + req_size, max);
ra->async_size = 1;
return 1;
@@ -552,6 +562,8 @@ static void ondemand_readahead(struct readahead_control *ractl,
pgoff_t index = readahead_index(ractl);
pgoff_t expected, prev_index;
unsigned int order = folio ? folio_order(folio) : 0;
+ unsigned long budgt = ractl->mapping->host->i_sb->s_bdev ?
+ blk_throttle_budgt(ractl->mapping->host->i_sb->s_bdev) : 0;
/*
* 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 == expected || index == (ra->start + ra->size)) {
ra->start += ra->size;
- ra->size = get_next_ra_size(ra, max_pages);
+ ra->size = get_next_ra_size(ractl, max_pages);
ra->async_size = ra->size;
goto readit;
}
@@ -599,7 +611,7 @@ static void ondemand_readahead(struct readahead_control *ractl,
ra->start = start;
ra->size = start - index; /* old async_size */
ra->size += req_size;
- ra->size = get_next_ra_size(ra, max_pages);
+ ra->size = get_next_ra_size(ractl, max_pages);
ra->async_size = 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 = min(budgt / PAGE_SIZE, req_size);
+
do_page_cache_ra(ractl, req_size, 0);
return;
@@ -647,7 +662,7 @@ static void ondemand_readahead(struct readahead_control *ractl,
* Take care of maximum IO pages as above.
*/
if (index == ra->start && ra->size == ra->async_size) {
- add_pages = get_next_ra_size(ra, max_pages);
+ add_pages = get_next_ra_size(ractl, max_pages);
if (ra->size + add_pages <= max_pages) {
ra->async_size = add_pages;
ra->size += add_pages;
--
2.25.1
next prev parent reply other threads:[~2024-05-09 2:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 2:39 [RFC PATCH 0/2] " zhaoyang.huang
2024-05-09 2:39 ` [RFC PATCH 1/2] block: introduce helper function to calculate bps budgt zhaoyang.huang
2024-05-09 2:39 ` zhaoyang.huang [this message]
2024-05-09 3:15 ` [RFC PATCH 2/2] mm: introduce budgt control in readahead Matthew Wilcox
2024-05-10 2:43 ` Zhaoyang Huang
2024-05-10 3:18 ` Matthew Wilcox
2024-05-11 7:35 ` Zhaoyang Huang
2024-05-14 2:37 ` Zhaoyang Huang
2024-05-09 12:39 ` Christoph Hellwig
2024-05-10 3:06 ` Zhaoyang Huang
2024-05-10 4:14 ` Matthew Wilcox
2024-05-10 7:08 ` Zhaoyang Huang
2024-05-15 1:23 [RFC PATCH 0/2] introduce precised blk-throttle control zhaoyang.huang
2024-05-15 1:23 ` [RFC PATCH 2/2] mm: introduce budgt control in readahead zhaoyang.huang
2024-05-15 4:09 ` Matthew Wilcox
2024-05-15 6:31 ` Zhaoyang Huang
2024-05-15 7:40 ` Tejun Heo
2024-05-15 8:17 ` Zhaoyang Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240509023937.1090421-3-zhaoyang.huang@unisoc.com \
--to=zhaoyang.huang@unisoc.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=baolin.wang@linux.alibaba.com \
--cc=cgroups@vger.kernel.org \
--cc=huangzhaoyang@gmail.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=steve.kang@unisoc.com \
--cc=tj@kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox