[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230929102726.2985188-3-john.g.garry@oracle.com>
Date: Fri, 29 Sep 2023 10:27:07 +0000
From: John Garry <john.g.garry@...cle.com>
To: axboe@...nel.dk, kbusch@...nel.org, hch@....de, sagi@...mberg.me,
jejb@...ux.ibm.com, martin.petersen@...cle.com, djwong@...nel.org,
viro@...iv.linux.org.uk, brauner@...nel.org,
chandan.babu@...cle.com, dchinner@...hat.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-nvme@...ts.infradead.org, linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org, tytso@....edu, jbongio@...gle.com,
linux-api@...r.kernel.org, John Garry <john.g.garry@...cle.com>
Subject: [PATCH 02/21] block: Limit atomic writes according to bio and queue limits
We rely the block layer always being able to send a bio of size
atomic_write_unit_max without being required to split it due to request
queue or other bio limits.
A bio may contain min(BIO_MAX_VECS, limits->max_segments) vectors,
and each vector is at worst case the device logical block size from
direct IO alignment requirement.
Signed-off-by: John Garry <john.g.garry@...cle.com>
---
block/blk-settings.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index d151be394c98..57d487a00c64 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -213,6 +213,18 @@ void blk_queue_atomic_write_boundary_bytes(struct request_queue *q,
}
EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes);
+static unsigned int blk_queue_max_guaranteed_bio_size_sectors(
+ struct request_queue *q)
+{
+ struct queue_limits *limits = &q->limits;
+ unsigned int max_segments = min_t(unsigned int, BIO_MAX_VECS,
+ limits->max_segments);
+ /* Limit according to dev sector size as we only support direct-io */
+ unsigned int limit = max_segments * queue_logical_block_size(q);
+
+ return rounddown_pow_of_two(limit >> SECTOR_SHIFT);
+}
+
/**
* blk_queue_atomic_write_unit_min_sectors - smallest unit that can be written
* atomically to the device.
@@ -223,8 +235,10 @@ void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q,
unsigned int sectors)
{
struct queue_limits *limits = &q->limits;
+ unsigned int guaranteed_sectors =
+ blk_queue_max_guaranteed_bio_size_sectors(q);
- limits->atomic_write_unit_min_sectors = sectors;
+ limits->atomic_write_unit_min_sectors = min(guaranteed_sectors, sectors);
}
EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_sectors);
@@ -238,8 +252,10 @@ void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q,
unsigned int sectors)
{
struct queue_limits *limits = &q->limits;
+ unsigned int guaranteed_sectors =
+ blk_queue_max_guaranteed_bio_size_sectors(q);
- limits->atomic_write_unit_max_sectors = sectors;
+ limits->atomic_write_unit_max_sectors = min(guaranteed_sectors, sectors);
}
EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_sectors);
--
2.31.1
Powered by blists - more mailing lists