linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] block: Check the queue limit before bio submitting
@ 2023-10-25  9:22 ed.tsai
  2023-11-01  2:23 ` Ed Tsai (蔡宗軒)
  0 siblings, 1 reply; 15+ messages in thread
From: ed.tsai @ 2023-10-25  9:22 UTC (permalink / raw)
  To: Jens Axboe, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, stanley.chu, peter.wang, alice.chao, powen.kao,
	naomi.chu, will.shiu, chun-hung.wu, casper.li, Ed Tsai,
	linux-block, linux-kernel, linux-arm-kernel, linux-mediatek

From: Ed Tsai <ed.tsai@mediatek.com>

Referring to commit 07173c3ec276 ("block: enable multipage bvecs"),
each bio_vec now holds more than one page, potentially exceeding
1MB in size and causing alignment issues with the queue limit.

In a sequential read/write scenario, the file system maximizes the
bio's capacity before submitting. However, misalignment with the
queue limit can result in the bio being split into smaller I/O
operations.

For instance, assuming the maximum I/O size is set to 512KB and the
memory is highly fragmented, resulting in each bio containing only
one 2-pages bio_vec (i.e., bi_size = 1028KB). This would cause the
bio to be split into two 512KB portions and one 4KB portion. As a
result, the originally expected continuous large I/O operations are
interspersed with many small I/O operations.

To address this issue, this patch adds a check for the max_sectors
before submitting the bio. This allows the upper layers to proactively
detect and handle alignment issues.

I performed the Antutu V10 Storage Test on a UFS 4.0 device, which
resulted in a significant improvement in the Sequential test:

Sequential Read (average of 5 rounds):
Original: 3033.7 MB/sec
Patched: 3520.9 MB/sec

Sequential Write (average of 5 rounds):
Original: 2225.4 MB/sec
Patched: 2800.3 MB/sec

Signed-off-by: Ed Tsai <ed.tsai@mediatek.com>
---
 block/bio.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/block/bio.c b/block/bio.c
index 816d412c06e9..a4a1f775b9ea 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1227,6 +1227,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
 	iov_iter_extraction_t extraction_flags = 0;
 	unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt;
 	unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt;
+	struct queue_limits *lim = &bdev_get_queue(bio->bi_bdev)->limits;
 	struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt;
 	struct page **pages = (struct page **)bv;
 	ssize_t size, left;
@@ -1275,6 +1276,11 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
 		struct page *page = pages[i];
 
 		len = min_t(size_t, PAGE_SIZE - offset, left);
+		if (bio->bi_iter.bi_size + len >
+		    lim->max_sectors << SECTOR_SHIFT) {
+			ret = left;
+			break;
+		}
 		if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
 			ret = bio_iov_add_zone_append_page(bio, page, len,
 					offset);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-11-07  4:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25  9:22 [PATCH 1/1] block: Check the queue limit before bio submitting ed.tsai
2023-11-01  2:23 ` Ed Tsai (蔡宗軒)
2023-11-03  8:15   ` Christoph Hellwig
2023-11-03  9:05     ` Ed Tsai (蔡宗軒)
2023-11-03 16:20   ` Ming Lei
2023-11-04  1:11     ` Ed Tsai (蔡宗軒)
2023-11-04  2:12       ` Yu Kuai
2023-11-04  3:43       ` Ming Lei
2023-11-06  1:33         ` Ed Tsai (蔡宗軒)
2023-11-06  1:40           ` Ed Tsai (蔡宗軒)
2023-11-06  4:53             ` Ming Lei
2023-11-06 11:54               ` Ming Lei
2023-11-07  2:53                 ` Ed Tsai (蔡宗軒)
2023-11-07  3:48                   ` Ming Lei
2023-11-07  4:35                     ` Ed Tsai (蔡宗軒)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).