diff mbox series

[v2,1/3] block: Export bio_discard_limit

Message ID 20240902205828.943155-2-luca.stefani.ge1@gmail.com (mailing list archive)
State New
Headers show
Series btrfs: Don't block suspend during fstrim | expand

Commit Message

Luca Stefani Sept. 2, 2024, 8:56 p.m. UTC
It can be used to calculate the sector size limit of each
discard call allowing filesystem to implement their own
chunked discard logic with customized behavior, for example
cancellation due to signals.

Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
---
 block/blk-lib.c        | 3 ++-
 include/linux/blkdev.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

David Sterba Sept. 2, 2024, 9:57 p.m. UTC | #1
On Mon, Sep 02, 2024 at 10:56:10PM +0200, Luca Stefani wrote:
> It can be used to calculate the sector size limit of each
> discard call allowing filesystem to implement their own
> chunked discard logic with customized behavior, for example
> cancellation due to signals.

Maybe to add context for block layer people why we want to export this:

The fs trim loops over ranges and sends discard requests, some ranges
can be large so it's all transparently handled by blkdev_issue_discard()
and processed in smaller chunks.

We need to insert checks for cancellation (or suspend) requests into the
the loop. Rather than setting an arbitrary chunk length on the
filesystem level I've suggested to use bio_discard_limit() assuming it
will do optimal number of IO requests. Then we don't have to guess
whether 1G or 10G is the right value, unnecessarily increasing the
number of requests when the device could handle larger ranges.
Christoph Hellwig Sept. 3, 2024, 5:07 a.m. UTC | #2
On Mon, Sep 02, 2024 at 11:57:05PM +0200, David Sterba wrote:
> On Mon, Sep 02, 2024 at 10:56:10PM +0200, Luca Stefani wrote:
> > It can be used to calculate the sector size limit of each
> > discard call allowing filesystem to implement their own
> > chunked discard logic with customized behavior, for example
> > cancellation due to signals.
> 
> Maybe to add context for block layer people why we want to export this:
> 
> The fs trim loops over ranges and sends discard requests, some ranges
> can be large so it's all transparently handled by blkdev_issue_discard()
> and processed in smaller chunks.

Then don't use blkdev_issue_discard but use blk_alloc_discard_bio
directly.

NAK to the export of bio_discard_limit.
diff mbox series

Patch

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 4c9f20a689f7..501cbfc4f112 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -10,7 +10,7 @@ 
 
 #include "blk.h"
 
-static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
+sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
 {
 	unsigned int discard_granularity = bdev_discard_granularity(bdev);
 	sector_t granularity_aligned_sector;
@@ -34,6 +34,7 @@  static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
 	 */
 	return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
 }
+EXPORT_SYMBOL(bio_discard_limit);
 
 struct bio *blk_alloc_discard_bio(struct block_device *bdev,
 		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b7664d593486..42d63400025b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1088,6 +1088,7 @@  static inline long nr_blockdev_pages(void)
 
 extern void blk_io_schedule(void);
 
+sector_t bio_discard_limit(struct block_device *bdev, sector_t sector);
 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		sector_t nr_sects, gfp_t gfp_mask);
 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,