Skip to content

Commit ac7fe3a

Browse files
adam900710kdave
authored andcommitted
btrfs: enable direct IO for bs > ps cases
Previously direct IO was disabled if the fs block size was larger than the page size, the reasons are: - Iomap direct IO can split the range ignoring the fs block alignment Which could trigger the bio size check from btrfs_submit_bio(). - The buffer is only ensured to be contiguous in user space memory The underlying physical memory is not ensured to be contiguous, and that can cause problems for the checksum generation/verification and RAID56 handling. However the above problems are solved by the following upstream commits: - 001397f ("iomap: add IOMAP_DIO_FSBLOCK_ALIGNED flag") Which added an extra flag that can be utilized by the fs to ensure the bio submitted by iomap is always aligned to fs block size. - ec20799 ("btrfs: enable encoded read/write/send for bs > ps cases") - 8870dbe ("btrfs: raid56: enable bs > ps support") Which makes btrfs to handle bios that are not backed by large folios but still are aligned to fs block size. As the commits have been merged we can enable direct IO support for bs > ps cases. Reviewed-by: Neal Gompa <neal@gompa.dev> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 795c994 commit ac7fe3a

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

fs/btrfs/direct-io.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static ssize_t btrfs_dio_read(struct kiocb *iocb, struct iov_iter *iter,
763763
struct btrfs_dio_data data = { 0 };
764764

765765
return iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops,
766-
IOMAP_DIO_PARTIAL, &data, done_before);
766+
IOMAP_DIO_PARTIAL | IOMAP_DIO_FSBLOCK_ALIGNED, &data, done_before);
767767
}
768768

769769
static struct iomap_dio *btrfs_dio_write(struct kiocb *iocb, struct iov_iter *iter,
@@ -772,7 +772,7 @@ static struct iomap_dio *btrfs_dio_write(struct kiocb *iocb, struct iov_iter *it
772772
struct btrfs_dio_data data = { 0 };
773773

774774
return __iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops,
775-
IOMAP_DIO_PARTIAL, &data, done_before);
775+
IOMAP_DIO_PARTIAL | IOMAP_DIO_FSBLOCK_ALIGNED, &data, done_before);
776776
}
777777

778778
static ssize_t check_direct_IO(struct btrfs_fs_info *fs_info,
@@ -785,19 +785,6 @@ static ssize_t check_direct_IO(struct btrfs_fs_info *fs_info,
785785

786786
if (iov_iter_alignment(iter) & blocksize_mask)
787787
return -EINVAL;
788-
789-
/*
790-
* For bs > ps support, we heavily rely on large folios to make sure no
791-
* block will cross large folio boundaries.
792-
*
793-
* But memory provided by direct IO is only virtually contiguous, not
794-
* physically contiguous, and will break the btrfs' large folio requirement.
795-
*
796-
* So for bs > ps support, all direct IOs should fallback to buffered ones.
797-
*/
798-
if (fs_info->sectorsize > PAGE_SIZE)
799-
return -EINVAL;
800-
801788
return 0;
802789
}
803790

0 commit comments

Comments
 (0)