From: Huang Jianan <huangjianan@oppo.com> To: linux-erofs@lists.ozlabs.org Cc: huangjianan@oppo.com, guoweichao@oppo.com, zhangshiming@oppo.com, linux-kernel@vger.kernel.org Subject: [PATCH] erofs: support direct IO for uncompressed file Date: Mon, 14 Dec 2020 22:04:27 +0800 [thread overview] Message-ID: <20201214140428.44944-1-huangjianan@oppo.com> (raw) direct IO is useful in certain scenarios for uncompressed files. For example, it can avoid double pagecache when use the uncompressed file to mount upper layer filesystem. In addition, another patch adds direct IO test for the stress tool which was mentioned here: https://lore.kernel.org/linux-erofs/20200206135631.1491-1-hsiangkao@aol.com/ Signed-off-by: Huang Jianan <huangjianan@oppo.com> Signed-off-by: Guo Weichao <guoweichao@oppo.com> --- fs/erofs/data.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index ea4f693bee22..3067aa3defff 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -6,6 +6,8 @@ */ #include "internal.h" #include <linux/prefetch.h> +#include <linux/uio.h> +#include <linux/blkdev.h> #include <trace/events/erofs.h> @@ -312,6 +314,60 @@ static void erofs_raw_access_readahead(struct readahead_control *rac) submit_bio(bio); } +static int erofs_get_block(struct inode *inode, sector_t iblock, + struct buffer_head *bh, int create) +{ + struct erofs_map_blocks map = { + .m_la = blknr_to_addr(iblock), + }; + int err; + + err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (err) + return err; + + if (map.m_flags & EROFS_MAP_MAPPED) + map_bh(bh, inode->i_sb, erofs_blknr(map.m_pa)); + + return err; +} + +static int check_direct_IO(struct inode *inode, struct iov_iter *iter, + loff_t offset) +{ + unsigned i_blkbits = READ_ONCE(inode->i_blkbits); + unsigned blkbits = i_blkbits; + unsigned blocksize_mask = (1 << blkbits) - 1; + unsigned long align = offset | iov_iter_alignment(iter); + struct block_device *bdev = inode->i_sb->s_bdev; + + if (align & blocksize_mask) { + if (bdev) + blkbits = blksize_bits(bdev_logical_block_size(bdev)); + blocksize_mask = (1 << blkbits) - 1; + if (align & blocksize_mask) + return -EINVAL; + return 1; + } + return 0; +} + +static ssize_t erofs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + struct inode *inode = mapping->host; + loff_t offset = iocb->ki_pos; + int err; + + err = check_direct_IO(inode, iter, offset); + if (err) + return err < 0 ? err : 0; + + return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter, + erofs_get_block, NULL, NULL, + DIO_LOCKING | DIO_SKIP_HOLES); +} + static sector_t erofs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode = mapping->host; @@ -336,6 +392,7 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block) const struct address_space_operations erofs_raw_access_aops = { .readpage = erofs_raw_access_readpage, .readahead = erofs_raw_access_readahead, + .direct_IO = erofs_direct_IO, .bmap = erofs_bmap, }; -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Huang Jianan <huangjianan@oppo.com> To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, guoweichao@oppo.com, zhangshiming@oppo.com Subject: [PATCH] erofs: support direct IO for uncompressed file Date: Mon, 14 Dec 2020 22:04:27 +0800 [thread overview] Message-ID: <20201214140428.44944-1-huangjianan@oppo.com> (raw) direct IO is useful in certain scenarios for uncompressed files. For example, it can avoid double pagecache when use the uncompressed file to mount upper layer filesystem. In addition, another patch adds direct IO test for the stress tool which was mentioned here: https://lore.kernel.org/linux-erofs/20200206135631.1491-1-hsiangkao@aol.com/ Signed-off-by: Huang Jianan <huangjianan@oppo.com> Signed-off-by: Guo Weichao <guoweichao@oppo.com> --- fs/erofs/data.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index ea4f693bee22..3067aa3defff 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -6,6 +6,8 @@ */ #include "internal.h" #include <linux/prefetch.h> +#include <linux/uio.h> +#include <linux/blkdev.h> #include <trace/events/erofs.h> @@ -312,6 +314,60 @@ static void erofs_raw_access_readahead(struct readahead_control *rac) submit_bio(bio); } +static int erofs_get_block(struct inode *inode, sector_t iblock, + struct buffer_head *bh, int create) +{ + struct erofs_map_blocks map = { + .m_la = blknr_to_addr(iblock), + }; + int err; + + err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (err) + return err; + + if (map.m_flags & EROFS_MAP_MAPPED) + map_bh(bh, inode->i_sb, erofs_blknr(map.m_pa)); + + return err; +} + +static int check_direct_IO(struct inode *inode, struct iov_iter *iter, + loff_t offset) +{ + unsigned i_blkbits = READ_ONCE(inode->i_blkbits); + unsigned blkbits = i_blkbits; + unsigned blocksize_mask = (1 << blkbits) - 1; + unsigned long align = offset | iov_iter_alignment(iter); + struct block_device *bdev = inode->i_sb->s_bdev; + + if (align & blocksize_mask) { + if (bdev) + blkbits = blksize_bits(bdev_logical_block_size(bdev)); + blocksize_mask = (1 << blkbits) - 1; + if (align & blocksize_mask) + return -EINVAL; + return 1; + } + return 0; +} + +static ssize_t erofs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + struct inode *inode = mapping->host; + loff_t offset = iocb->ki_pos; + int err; + + err = check_direct_IO(inode, iter, offset); + if (err) + return err < 0 ? err : 0; + + return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter, + erofs_get_block, NULL, NULL, + DIO_LOCKING | DIO_SKIP_HOLES); +} + static sector_t erofs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode = mapping->host; @@ -336,6 +392,7 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block) const struct address_space_operations erofs_raw_access_aops = { .readpage = erofs_raw_access_readpage, .readahead = erofs_raw_access_readahead, + .direct_IO = erofs_direct_IO, .bmap = erofs_bmap, }; -- 2.25.1
next reply other threads:[~2020-12-14 14:06 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-14 14:04 Huang Jianan [this message] 2020-12-14 14:04 ` [PATCH] erofs: support direct IO for uncompressed file Huang Jianan 2020-12-14 14:04 ` [PATCH] fsstress: support direct IO Huang Jianan 2020-12-14 14:04 ` Huang Jianan 2020-12-22 13:21 ` [PATCH] erofs: support direct IO for uncompressed file Gao Xiang 2020-12-22 13:21 ` Gao Xiang 2020-12-22 14:22 ` Christoph Hellwig 2020-12-22 14:22 ` Christoph Hellwig 2020-12-22 19:39 ` Gao Xiang 2020-12-22 19:39 ` Gao Xiang 2020-12-23 7:44 ` Christoph Hellwig 2020-12-23 7:44 ` Christoph Hellwig 2020-12-23 8:48 ` Huang Jianan 2020-12-23 8:54 ` Christoph Hellwig 2020-12-23 8:54 ` Christoph Hellwig 2020-12-23 9:03 ` Gao Xiang 2020-12-23 9:03 ` Gao Xiang
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=20201214140428.44944-1-huangjianan@oppo.com \ --to=huangjianan@oppo.com \ --cc=guoweichao@oppo.com \ --cc=linux-erofs@lists.ozlabs.org \ --cc=linux-kernel@vger.kernel.org \ --cc=zhangshiming@oppo.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.