reduce memory allocation in the btrfs direct I/O path
Subsystems (3)
Hi all,
this series adds two minor improvements to iomap that allow btrfs to avoid a memory allocation per read/write system call and another one per submitted bio. I also have at last two other pending uses for the iomap functionality later on, so they are not really btrfs specific either.
Diffstat:
fs/btrfs/btrfs_inode.h | 25 -------- fs/btrfs/ctree.h | 6 - fs/btrfs/file.c | 6 - fs/btrfs/inode.c | 152 +++++++++++++++++++++++-------------------------- fs/iomap/direct-io.c | 26 +++++++- include/linux/iomap.h | 4 + 6 files changed, 104 insertions(+), 115 deletions(-)
PATCH 1/5 iomap: allow the file system to provide a bio_set for direct I/O
Allow the file system to provide a specific bio_set for allocating direct I/O bios. This will allow file systems that use the ->submit_io hook to stash away additional information for file system use.
To make use of this additional space for information in the completion path, the file system needs to override the ->bi_end_io callback and then call back into iomap, so export iomap_dio_bio_end_io for that.
--- fs/iomap/direct-io.c | 18 ++++++++++++++---- include/linux/iomap.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-)
fs/iomap/direct-io.c +14 -4
@@ -51,6 +51,15 @@ struct iomap_dio { }; }; +static struct bio *iomap_dio_alloc_bio (const struct iomap_iter *iter, +struct iomap_dio *dio,unsigned short nr_vecs,unsigned int opf) +{ +if (dio->dops && dio->dops->bio_set) +return bio_alloc_bioset (iter->iomap.bdev, nr_vecs, opf, +GFP_KERNEL , dio->dops->bio_set); +return bio_alloc (iter->iomap.bdev, nr_vecs, opf,GFP_KERNEL ); +} +static void iomap_dio_submit_bio (const struct iomap_iter *iter,struct iomap_dio *dio,struct bio *bio,loff_t pos) {
@@ -144,7 +153,7 @@ static inline void iomap_dio_set_error(struct iomap_dio *dio, int ret)cmpxchg (&dio->error,0 , ret); } -static void iomap_dio_bio_end_io (struct bio *bio) +void iomap_dio_bio_end_io (struct bio *bio) {struct iomap_dio *dio = bio->bi_private;bool should_dirty = (dio->flags &IOMAP_DIO_DIRTY );
@@ -176,16 +185,17 @@ static void iomap_dio_bio_end_io(struct bio *bio)bio_put (bio); } } +EXPORT_SYMBOL_GPL (iomap_dio_bio_end_io);static void iomap_dio_zero (const struct iomap_iter *iter,struct iomap_dio *dio,loff_t pos,unsigned len) {struct inode *inode =file_inode (dio->iocb->ki_filp);struct page *page =ZERO_PAGE (0 ); -int flags =REQ_SYNC |REQ_IDLE ;struct bio *bio; - bio =bio_alloc (iter->iomap.bdev,1 ,REQ_OP_WRITE | flags,GFP_KERNEL ); + bio =iomap_dio_alloc_bio (iter, dio,1 , +REQ_OP_WRITE |REQ_SYNC |REQ_IDLE );fscrypt_set_bio_crypt_ctx (bio, inode, pos >> inode->i_blkbits,GFP_KERNEL ); bio->bi_iter.bi_sector =iomap_sector (&iter->iomap, pos);
@@ -311,7 +321,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, goto out; } - bio =bio_alloc (iomap->bdev, nr_pages, bio_opf,GFP_KERNEL ); + bio =iomap_dio_alloc_bio (iter, dio, nr_pages, bio_opf);fscrypt_set_bio_crypt_ctx (bio, inode, pos >> inode->i_blkbits,GFP_KERNEL ); bio->bi_iter.bi_sector =iomap_sector (iomap, pos);
include/linux/iomap.h +3 -0
@@ -320,6 +320,8 @@ struct iomap_dio_ops { unsigned flags);void (*submit_io)(const struct iomap_iter *iter,struct bio *bio,loff_t file_offset); + +struct bio_set *bio_set; };/*
@@ -349,6 +351,7 @@ struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, size_t done_before);ssize_t iomap_dio_complete (struct iomap_dio *dio); +void iomap_dio_bio_end_io (struct bio *bio);#ifdef CONFIG_SWAP struct file ;
Signature · 1 line
2.30.2
Re: [PATCH 1/5] iomap: allow the file system to provide a bio_set for direct I/O
Quoted 8 lines · Christoph Hellwig
Allow the file system to provide a specific
bio_setfor allocating direct I/O bios. This will allow file systems that use the ->submit_io hook to stash away additional information for file system use.To make use of this additional space for information in the completion path, the file system needs to override the ->bi_end_io callback and then call back into iomap, so export
iomap_dio_bio_end_iofor that.
I hear reports of people (Ted) at LSF asking for better support in porting things to iomap. Can we document the entire process of using additional space per bio somewhere in the header file?
/*
* Filesystems wishing to attach private information to a directio bio
* must provide a ->submit_io method that attaches the additional
* information to the bio and changes the ->bi_end_io callback to a
* custom function. This function should, at a minimum, perform any
* relevant post-processing of the bio and end with a call to
* iomap_dio_bio_end_io.
*/
I'm not sure where this would go in iomap.h, since this is more about custom bios than it is about biosets, but I think we could at least try to seed future converter patchset authors with some reasonable recipes so we don't end up with the sprawling messes that we have with bufferheads. Obviously, adding recipes is not something in scope for this patch.
This patch looks ok, so
--D
Quoted 88 lines
Signed-off-by Christoph Hellwig <[email protected]>--- fs/iomap/direct-io.c | 18 ++++++++++++++---- include/linux/iomap.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-)fs/iomap/direct-io.c +14
-4@@ -51,6 +51,15 @@ struct iomap_dio { }; }; +static struct bio *iomap_dio_alloc_bio (const struct iomap_iter *iter, +struct iomap_dio *dio,unsigned short nr_vecs,unsigned int opf) +{ +if (dio->dops && dio->dops->bio_set) +return bio_alloc_bioset (iter->iomap.bdev, nr_vecs, opf, +GFP_KERNEL , dio->dops->bio_set); +return bio_alloc (iter->iomap.bdev, nr_vecs, opf,GFP_KERNEL ); +} +static void iomap_dio_submit_bio (const struct iomap_iter *iter,struct iomap_dio *dio,struct bio *bio,loff_t pos) {@@ -144,7 +153,7 @@ static inline void iomap_dio_set_error(struct iomap_dio *dio, int ret)cmpxchg (&dio->error,0 , ret); } -static void iomap_dio_bio_end_io (struct bio *bio) +void iomap_dio_bio_end_io (struct bio *bio) {struct iomap_dio *dio = bio->bi_private;bool should_dirty = (dio->flags &IOMAP_DIO_DIRTY );@@ -176,16 +185,17 @@ static void iomap_dio_bio_end_io(struct bio *bio)bio_put (bio); } } +EXPORT_SYMBOL_GPL (iomap_dio_bio_end_io);static void iomap_dio_zero (const struct iomap_iter *iter,struct iomap_dio *dio,loff_t pos,unsigned len) {struct inode *inode =file_inode (dio->iocb->ki_filp);struct page *page =ZERO_PAGE (0 ); -int flags =REQ_SYNC |REQ_IDLE ;struct bio *bio; - bio =bio_alloc (iter->iomap.bdev,1 ,REQ_OP_WRITE | flags,GFP_KERNEL ); + bio =iomap_dio_alloc_bio (iter, dio,1 , +REQ_OP_WRITE |REQ_SYNC |REQ_IDLE );fscrypt_set_bio_crypt_ctx (bio, inode, pos >> inode->i_blkbits,GFP_KERNEL ); bio->bi_iter.bi_sector =iomap_sector (&iter->iomap, pos);@@ -311,7 +321,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, goto out; } - bio =bio_alloc (iomap->bdev, nr_pages, bio_opf,GFP_KERNEL ); + bio =iomap_dio_alloc_bio (iter, dio, nr_pages, bio_opf);fscrypt_set_bio_crypt_ctx (bio, inode, pos >> inode->i_blkbits,GFP_KERNEL ); bio->bi_iter.bi_sector =iomap_sector (iomap, pos);include/linux/iomap.h +3
-0@@ -320,6 +320,8 @@ struct iomap_dio_ops { unsigned flags);void (*submit_io)(const struct iomap_iter *iter,struct bio *bio,loff_t file_offset); + +struct bio_set *bio_set; };/* @@ -349,6 +351,7 @@ struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, size_t done_before);ssize_t iomap_dio_complete (struct iomap_dio *dio); +void iomap_dio_bio_end_io (struct bio *bio);#ifdef CONFIG_SWAP struct file ;Signature · 1 line
2.30.2
PATCH 2/5 iomap: add per-iomap_iter private data
In reply to Christoph HellwigAllow the file system to keep state for all iterations. For now only wire it up for direct I/O as there is an immediate need for it there.
--- fs/iomap/direct-io.c | 8 ++++++++ include/linux/iomap.h | 1 + 2 files changed, 9 insertions(+)
fs/iomap/direct-io.c +8 -0
@@ -520,6 +520,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio =NULL ; +/* +* Transfer the private data that was passed by the caller to the +* iomap_iter, and clear it in the iocb, as iocb->private will be +* used for polled bio completion later. +*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL ); +if (iov_iter_rw (iter) ==READ ) {if (iomi.pos >= dio->i_size) goto out_free_dio;
include/linux/iomap.h +1 -0
@@ -188,6 +188,7 @@ struct iomap_iter {unsigned flags;struct iomap iomap;struct iomap srcmap; +void *private; };int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops);
Signature · 1 line
2.30.2
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 14 lines · Christoph Hellwig
Allow the file system to keep state for all iterations. For now only wire it up for direct I/O as there is an immediate need for it there.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/iomap/direct-io.c | 8 ++++++++ include/linux/iomap.h | 1 + 2 files changed, 9 insertions(+)fs/iomap/direct-io.c +0
-0
fs/iomap/direct-io.c __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 529
Quoted 10 lines
fs/iomap/direct-io.c +7
-0@@ -520,6 +520,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio =NULL ; +/* +* Transfer the private data that was passed by the caller to the +* iomap_iter, and clear it in the iocb, as iocb->private will be +* used for polled bio completion later. +*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL );
nit: Why use WRITE_ONCE here? Generaly when it's used it will suggest to the reader something funny is going on with accessing that variable without holding a particular lock?
Quoted 16 lines
fs/iomap/direct-io.c +1
-0+if (iov_iter_rw (iter) ==READ ) {if (iomi.pos >= dio->i_size) goto out_free_dio;include/linux/iomap.h +1
-0@@ -188,6 +188,7 @@ struct iomap_iter {unsigned flags;struct iomap iomap;struct iomap srcmap; +void *private; };int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops);
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 6 lines · Nikolay Borisov
Quoted 6 lines
fs/iomap/direct-io.c +2
-0@@ -520,6 +520,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio =NULL ; + /* +* Transfer the private data that was passed by the caller to the +* iomap_iter, and clear it in the iocb, as iocb->private will be
Quoted 8 lines
fs/iomap/direct-io.c __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 529
Quoted 4 lines
fs/iomap/direct-io.c +4
-0+* used for polled bio completion later. +*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL );nit: Why use
WRITE_ONCEhere? Generaly when it's used it will suggest to the reader something funny is going on with accessing that variable without holding a particular lock?
Because we use WRITE_ONCE on iocb->private later on when we use it to store the bio that is polled for, and we really want the store that clears it to NULL to be done before we start dealing with bio submission.
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
In reply to Christoph HellwigQuoted 14 lines · Christoph Hellwig
Allow the file system to keep state for all iterations. For now only wire it up for direct I/O as there is an immediate need for it there.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/iomap/direct-io.c | 8 ++++++++ include/linux/iomap.h | 1 + 2 files changed, 9 insertions(+)fs/iomap/direct-io.c +0
-0
fs/iomap/direct-io.c __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 529
Quoted 10 lines
fs/iomap/direct-io.c +7
-0@@ -520,6 +520,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio =NULL ; +/* +* Transfer the private data that was passed by the caller to the +* iomap_iter, and clear it in the iocb, as iocb->private will be +* used for polled bio completion later. +*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL );
Do we need to transfer it back after the bio completes? Or is it a feature that iocb->private changes to the bio?
--D
Quoted 19 lines
fs/iomap/direct-io.c +1
-0+if (iov_iter_rw (iter) ==READ ) {if (iomi.pos >= dio->i_size) goto out_free_dio;include/linux/iomap.h +1
-0@@ -188,6 +188,7 @@ struct iomap_iter {unsigned flags;struct iomap iomap;struct iomap srcmap; +void *private; };int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops);Signature · 1 line
2.30.2
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 6 lines · Darrick J. Wong
fs/iomap/direct-io.c __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 529
Quoted 3 lines
fs/iomap/direct-io.c +3
-0+*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL );Do we need to transfer it back after the bio completes? Or is it a feature that
iocb->privatechanges to the bio?
No need to transfer it back. It ist just a creative way to pass private data in. Initially I just added yet another argument to iomap_dio_rw, and maybe I should just go back to that to make the things easier to follow.
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Darrick J. Wong
fs/iomap/direct-io.c __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 529
Quoted 3 lines
fs/iomap/direct-io.c +3
-0+*/ + iomi.private = iocb->private; +WRITE_ONCE (iocb->private,NULL );Do we need to transfer it back after the bio completes? Or is it a feature that
iocb->privatechanges to the bio?
Quoted 4 lines
No need to transfer it back. It ist just a creative way to pass private data in. Initially I just added yet another argument to
iomap_dio_rw, and maybe I should just go back to that to make the things easier to follow.
Hmm. Who owns iocb->private? AFAICT there are two users of it -- the directio code uses it to store bios for polling; and then there's ocfs2, which apparently uses it for iocb lock state(!) flags.
Getting back to iomap, I think the comment before __iomap_dio_rw should state that iocb->private will be transferred to iter->private to make that relationship more obvious, in case ocfs2 ever stumbles into iomap and explodes on impact.
--D
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 8 lines · Darrick J. Wong
Quoted 4 lines
No need to transfer it back. It ist just a creative way to pass private data in. Initially I just added yet another argument to
iomap_dio_rw, and maybe I should just go back to that to make the things easier to follow.Hmm. Who owns
iocb->private? AFAICT there are two users of it -- the directio code uses it to store bios for polling; and then there's ocfs2, which apparently uses it for iocb lock state(!) flags.
Yeah.
Quoted 4 lines
Getting back to iomap, I think the comment before
__iomap_dio_rwshould state thatiocb->privatewill be transferred toiter->privateto make that relationship more obvious, in case ocfs2 ever stumbles into iomap and explodes on impact.
I think I'll just look into passing an extra argument instead. It is pretty clear that using iocb->private was a little too clever and takes experienced file system developers way too much time to understand.
Re: [PATCH 2/5] iomap: add per-iomap_iter private data
Quoted 12 lines · Christoph Hellwig
Quoted 8 lines · Darrick J. Wong
Quoted 4 lines
No need to transfer it back. It ist just a creative way to pass private data in. Initially I just added yet another argument to
iomap_dio_rw, and maybe I should just go back to that to make the things easier to follow.Hmm. Who owns
iocb->private? AFAICT there are two users of it -- the directio code uses it to store bios for polling; and then there's ocfs2, which apparently uses it for iocb lock state(!) flags.Yeah.
Quoted 8 lines
Quoted 4 lines
Getting back to iomap, I think the comment before
__iomap_dio_rwshould state thatiocb->privatewill be transferred toiter->privateto make that relationship more obvious, in case ocfs2 ever stumbles into iomap and explodes on impact.I think I'll just look into passing an extra argument instead. It is pretty clear that using
iocb->privatewas a little too clever and takes experienced file system developers way too much time to understand.
Ok.
--D
PATCH 3/5 btrfs: add a btrfs_dio_rw wrapper
In reply to Christoph HellwigAdd a wrapper around iomap_dio_rw that keeps the direct I/O internals isolated in inode.c.
--- fs/btrfs/ctree.h | 5 +++-- fs/btrfs/file.c | 6 ++---- fs/btrfs/inode.c | 11 +++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-)
fs/btrfs/ctree.h +3 -2
@@ -3358,9 +3358,10 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter,ssize_t btrfs_do_encoded_write (struct kiocb *iocb,struct iov_iter *from,const struct btrfs_ioctl_encoded_io_args *encoded); +ssize_t btrfs_dio_rw (struct kiocb *iocb,struct iov_iter *iter, +size_t done_before); +extern const struct dentry_operations btrfs_dentry_operations; -extern const struct iomap_ops btrfs_dio_iomap_ops; -extern const struct iomap_dio_ops btrfs_dio_ops;/* Inode locking type flags, by default the exclusive lock is taken */ #define BTRFS_ILOCK_SHARED (1U << 0)
fs/btrfs/file.c +2 -4
@@ -1929,8 +1929,7 @@ static ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)*/ again: from->nofault = true; - err =iomap_dio_rw (iocb, from, &btrfs_dio_iomap_ops, &btrfs_dio_ops, -IOMAP_DIO_PARTIAL , written); + err =btrfs_dio_rw (iocb, from, written); from->nofault = false;/* No increment (+=) because iomap returns a cumulative value. */
@@ -3693,8 +3692,7 @@ static ssize_t btrfs_direct_read(struct kiocb *iocb, struct iov_iter *to)*/ pagefault_disable (); to->nofault = true; - ret =iomap_dio_rw (iocb, to, &btrfs_dio_iomap_ops, &btrfs_dio_ops, -IOMAP_DIO_PARTIAL , read); + ret =btrfs_dio_rw (iocb, to, read); to->nofault = false;pagefault_enable ();
fs/btrfs/inode.c +9 -2
@@ -8155,15 +8155,22 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,btrfs_dio_private_put (dip); } -const struct iomap_ops btrfs_dio_iomap_ops = { +static const struct iomap_ops btrfs_dio_iomap_ops = { .iomap_begin = btrfs_dio_iomap_begin, .iomap_end = btrfs_dio_iomap_end, }; -const struct iomap_dio_ops btrfs_dio_ops = { +static const struct iomap_dio_ops btrfs_dio_ops = { .submit_io = btrfs_submit_direct, }; +ssize_t btrfs_dio_rw (struct kiocb *iocb,struct iov_iter *iter, +size_t done_before) +{ +return iomap_dio_rw (iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops, +IOMAP_DIO_PARTIAL , done_before); +} +static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len) {
Signature · 1 line
2.30.2
PATCH 4/5 btrfs: allocate dio_data on stack
In reply to Christoph HellwigMake use of the new iomap_iter->private field to avoid a memory allocation per iomap range.
--- fs/btrfs/inode.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
fs/btrfs/inode.c +11 -22
@@ -7546,10 +7546,11 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { + struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct extent_map *em;struct extent_state *cached_state =NULL ; -struct btrfs_dio_data *dio_data =NULL ; +struct btrfs_dio_data *dio_data = iter->private;u64 lockstart, lockend;const bool write = !!(flags &IOMAP_WRITE );int ret =0 ;
@@ -7595,17 +7596,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, } } -if (flags &IOMAP_NOWAIT ) { - dio_data =kzalloc (sizeof (*dio_data),GFP_NOWAIT ); -if (!dio_data) -return -EAGAIN ; - }else { - dio_data =kzalloc (sizeof (*dio_data),GFP_NOFS ); -if (!dio_data) -return -ENOMEM ; - } - - iomap->private = dio_data; +memset (dio_data,0 ,sizeof (*dio_data));/* * We always try to allocate data space and must do it before locking
@@ -7769,23 +7760,22 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,extent_changeset_free (dio_data->data_reserved); } -kfree (dio_data); -return ret; }static int btrfs_dio_iomap_end (struct inode *inode,loff_t pos,loff_t length,ssize_t written,unsigned int flags,struct iomap *iomap) { -int ret =0 ; -struct btrfs_dio_data *dio_data = iomap->private; + struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap); +struct btrfs_dio_data *dio_data = iter->private;size_t submitted = dio_data->submitted;const bool write = !!(flags &IOMAP_WRITE ); +int ret =0 ;if (!write && (iomap->type ==IOMAP_HOLE )) {/* If reading from a hole, unlock and return */ unlock_extent (&BTRFS_I (inode)->io_tree, pos, pos + length -1 ); - goto out; +return 0 ; }if (submitted < length) {
@@ -7802,10 +7792,6 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length,if (write)extent_changeset_free (dio_data->data_reserved); -out: -kfree (dio_data); - iomap->private =NULL ; -return ret; }
@@ -8041,7 +8027,7 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,int ret;blk_status_t status;struct btrfs_io_geometry geom; -struct btrfs_dio_data *dio_data = iter->iomap.private; +struct btrfs_dio_data *dio_data = iter->private;struct extent_map *em =NULL ; dip =btrfs_create_dio_private (dio_bio, inode, file_offset);
@@ -8167,6 +8153,9 @@ static const struct iomap_dio_ops btrfs_dio_ops = {ssize_t btrfs_dio_rw (struct kiocb *iocb,struct iov_iter *iter,size_t done_before) { +struct btrfs_dio_data data; + + iocb->private = &data;return iomap_dio_rw (iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops,IOMAP_DIO_PARTIAL , done_before); }
Signature · 1 line
2.30.2
PATCH 5/5 btrfs: allocate the btrfs_dio_private as part of the iomap dio bio
In reply to Christoph HellwigCreate a new bio_set that contains all the per-bio private data needed by btrfs for direct I/O and tell the iomap code to use that instead of separately allocation the btrfs_dio_private structure.
--- fs/btrfs/btrfs_inode.h | 25 ---------- fs/btrfs/ctree.h | 1 - fs/btrfs/inode.c | 108 ++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 81 deletions(-)
fs/btrfs/btrfs_inode.h +0 -25
@@ -395,31 +395,6 @@ static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode)return true; } -struct btrfs_dio_private { -struct inode *inode; - -/* -* Since DIO can use anonymous page, we cannot use page_offset() to -* grab the file offset, thus need a dedicated member for file offset. -*/ -u64 file_offset; -u64 disk_bytenr; -/* Used for bio::bi_size */ -u32 bytes; - -/* -* References to this structure. There is one reference per in-flight -* bio plus one while we're still setting up. -*/ -refcount_t refs; - -/* dio_bio came from fs/direct-io.c */ -struct bio *dio_bio; - -/* Array of checksums */ -u8 csums[]; -}; -/* * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two * separate u32s. These two functions convert between the two representations.
fs/btrfs/ctree.h +0 -1
@@ -3217,7 +3217,6 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,int btrfs_find_orphan_item (struct btrfs_root *root,u64 offset);/* file-item.c */ -struct btrfs_dio_private ;int btrfs_del_csums (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr,u64 len);blk_status_t btrfs_lookup_bio_sums (struct inode *inode,struct bio *bio,u8 *dst);
fs/btrfs/inode.c +53 -55
184 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH 5/5] btrfs: allocate the btrfs_dio_private as part of the iomap dio bio
Quoted 18 lines · Christoph Hellwig
Create a new
bio_setthat contains all the per-bio private data needed by btrfs for direct I/O and tell the iomap code to use that instead of separately allocation thebtrfs_dio_privatestructure.Signed-off-by Christoph Hellwig <[email protected]>--- fs/btrfs/btrfs_inode.h | 25 ---------- fs/btrfs/ctree.h | 1 - fs/btrfs/inode.c | 108 ++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 81 deletions(-)fs/btrfs/btrfs_inode.h +0
-0@@ -395,31 +395,6 @@ static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode)return true; }
fs/btrfs/btrfs_inode.h static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode) · line 406
Quoted 10 lines
fs/btrfs/btrfs_inode.h +0
-9-struct btrfs_dio_private { -struct inode *inode; - -/* -* Since DIO can use anonymous page, we cannot use page_offset() to -* grab the file offset, thus need a dedicated member for file offset. -*/ -u64 file_offset; -u64 disk_bytenr;
nit: You are actually removing this member when copying the struct, that's an independent change (albeit I'd say insignificant). Generally we prefer such changes to be in separate patches with rationale when the given member became redundant.
<snip>
Re: [PATCH 5/5] btrfs: allocate the btrfs_dio_private as part of the iomap dio bio
Quoted 4 lines · Nikolay Borisov
nit: You are actually removing this member when copying the struct, that's an independent change (albeit I'd say insignificant). Generally we prefer such changes to be in separate patches with rationale when the given member became redundant.
This one actually was entirely unused, but yes, this could have been split into another patch.
Re: [PATCH 5/5] btrfs: allocate the btrfs_dio_private as part of the iomap dio bio
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Nikolay Borisov
nit: You are actually removing this member when copying the struct, that's an independent change (albeit I'd say insignificant). Generally we prefer such changes to be in separate patches with rationale when the given member became redundant.
This one actually was entirely unused, but yes, this could have been split into another patch.
Cleanest would be to do it in a separate patch, but as it's trivial mentioning it in the changelog would be also sufficient. When code is moved either within file or to another one it's better to keep it 1:1 besides some trivial renames or formatting. It's easy to overlook a line missing. For now no need to resend, I'll add a notice to the changelog.
Re: [PATCH 5/5] btrfs: allocate the btrfs_dio_private as part of the iomap dio bio
In reply to Christoph Hellwigfs/btrfs/inode.c static void btrfs_submit_direct(const struct iomap_iter *iter, · line 8038
Quoted 12 lines · Christoph Hellwig
fs/btrfs/inode.c +5
-3-if (!write) { +if (!write && !(BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )) {/* * Load the csums up front to reduce csum tree searches and * contention when submitting bios. -* -* If we have csums disabled this will do nothing. */ + status =BLK_STS_RESOURCE ; + dip->csums =kzalloc (fs_info->csum_size * + (dio_bio->bi_iter.bi_size >> fs_info->sectorsize_bits), +GFP_NOFS );
This should be either kmalloc_array or kcalloc, otherwise OK.
Nikolay Borisov
Reviewed-byQuoted 8 lines · Christoph Hellwig
Hi all,
this series adds two minor improvements to iomap that allow btrfs to avoid a memory allocation per read/write system call and another one per submitted bio. I also have at last two other pending uses for the iomap functionality later on, so they are not really btrfs specific either.
Quoted 9 lines
Diffstat:
fs/btrfs/btrfs_inode.h | 25 -------- fs/btrfs/ctree.h | 6 - fs/btrfs/file.c | 6 - fs/btrfs/inode.c | 152 +++++++++++++++++++++++-------------------------- fs/iomap/direct-io.c | 26 +++++++- include/linux/iomap.h | 4 + 6 files changed, 104 insertions(+), 115 deletions(-)
Apart from the silent disk_bytenr removal nit:
Quoted 7 lines · Christoph Hellwig
Hi all,
this series adds two minor improvements to iomap that allow btrfs to avoid a memory allocation per read/write system call and another one per submitted bio. I also have at last two other pending uses for the iomap functionality later on, so they are not really btrfs specific either.
The series is reasonably short so I'd like to add it to 5.20 queue, provided that the iomap patches get acked by Darrick. Any fixups I'd rather fold into my local branch, no need to resend unless there are significant updates.
Quoted 9 lines · David Sterba
Quoted 7 lines · Christoph Hellwig
Hi all,
this series adds two minor improvements to iomap that allow btrfs to avoid a memory allocation per read/write system call and another one per submitted bio. I also have at last two other pending uses for the iomap functionality later on, so they are not really btrfs specific either.
Quoted 4 lines
The series is reasonably short so I'd like to add it to 5.20 queue, provided that the iomap patches get acked by Darrick. Any fixups I'd rather fold into my local branch, no need to resend unless there are significant updates.
Hm. I'm planning on pushing out a (very late) iomap-5.19-merge branch, since (AFAICT) these changes are mostly plumbing. Do you want me to push the first three patches of this series for 5.19?
--D
Quoted 8 lines · Darrick J. Wong
Quoted 4 lines
The series is reasonably short so I'd like to add it to 5.20 queue, provided that the iomap patches get acked by Darrick. Any fixups I'd rather fold into my local branch, no need to resend unless there are significant updates.
Hm. I'm planning on pushing out a (very late) iomap-5.19-merge branch, since (AFAICT) these changes are mostly plumbing. Do you want me to push the first three patches of this series for 5.19?
Given that we have no conflicts it might be easiest to just merge the whole series through the btrfs tree.
Quoted 2 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong
Quoted 1 line
The series is reasonably short so I'd like to add it to 5.20 queue,
^^^^
Sorry, I meant 5.19, ie. the one that's about to start soon.
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
provided that the iomap patches get acked by Darrick. Any fixups I'd rather fold into my local branch, no need to resend unless there are significant updates.
Hm. I'm planning on pushing out a (very late) iomap-5.19-merge branch, since (AFAICT) these changes are mostly plumbing. Do you want me to push the first three patches of this series for 5.19?
Given that we have no conflicts it might be easiest to just merge the whole series through the btrfs tree.
Yeah, I'd rather take it via the btrfs tree.
Quoted 10 lines · David Sterba
Quoted 2 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong
Quoted 1 line
The series is reasonably short so I'd like to add it to 5.20 queue,
^^^^Sorry, I meant 5.19, ie. the one that's about to start soon.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
provided that the iomap patches get acked by Darrick. Any fixups I'd rather fold into my local branch, no need to resend unless there are significant updates.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Hm. I'm planning on pushing out a (very late) iomap-5.19-merge branch, since (AFAICT) these changes are mostly plumbing. Do you want me to push the first three patches of this series for 5.19?
Given that we have no conflicts it might be easiest to just merge the whole series through the btrfs tree.
Yeah, I'd rather take it via the btrfs tree.
Ah, *5.19*. Yes, this plan now sounds good to me!
(I had wondered, 5.20 seemed like an awfully long time to wait for something as straightforward as that.)
--D