misc bio allocation cleanups
Subsystems (23)
Christoph Hellwig
maintainerHi Jens,
this series contains various cleanups for how bios are allocated or initialized plus related fallout.
Diffstat:
Documentation/filesystems/f2fs.rst | 1 block/bio.c | 167 ++++++++++++++++++------------------- block/blk-crypto-fallback.c | 2 block/blk-flush.c | 17 +-- drivers/block/drbd/drbd_actlog.c | 2 drivers/block/drbd/drbd_bitmap.c | 2 drivers/block/drbd/drbd_int.h | 2 drivers/block/drbd/drbd_main.c | 13 -- drivers/block/drbd/drbd_req.c | 5 - drivers/block/drbd/drbd_req.h | 12 -- drivers/block/drbd/drbd_worker.c | 5 - drivers/md/dm-clone-target.c | 14 --- drivers/md/dm-zoned-metadata.c | 6 - drivers/md/md.c | 48 +++------- drivers/md/md.h | 2 drivers/md/raid1.c | 2 drivers/md/raid10.c | 2 drivers/md/raid5-ppl.c | 2 drivers/md/raid5.c | 108 +++++++++-------------- drivers/nvme/target/io-cmd-bdev.c | 2 fs/block_dev.c | 2 fs/btrfs/volumes.c | 2 fs/exfat/file.c | 2 fs/ext4/fast_commit.c | 4 fs/ext4/fsync.c | 2 fs/ext4/ialloc.c | 2 fs/ext4/super.c | 2 fs/f2fs/data.c | 28 ------ fs/f2fs/f2fs.h | 2 fs/f2fs/segment.c | 12 -- fs/f2fs/super.c | 1 fs/fat/file.c | 2 fs/hfsplus/inode.c | 2 fs/hfsplus/super.c | 2 fs/jbd2/checkpoint.c | 2 fs/jbd2/commit.c | 4 fs/jbd2/recovery.c | 2 fs/libfs.c | 2 fs/nfs/blocklayout/blocklayout.c | 5 - fs/nilfs2/segbuf.c | 4 fs/nilfs2/the_nilfs.h | 2 fs/ocfs2/file.c | 2 fs/reiserfs/file.c | 2 fs/xfs/xfs_super.c | 2 fs/zonefs/super.c | 4 include/linux/bio.h | 6 - include/linux/blkdev.h | 4 include/linux/swap.h | 1 mm/page_io.c | 45 ++------- mm/swapfile.c | 10 -- 50 files changed, 213 insertions(+), 363 deletions(-)
Christoph Hellwig
maintainerPATCH 1/17 zonefs: use bio_alloc in zonefs_file_dio_append
Use bio_alloc instead of open coding it.
--- fs/zonefs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/zonefs/super.c +1 -1
@@ -678,7 +678,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)if (!nr_pages)return 0 ; - bio =bio_alloc_bioset (GFP_NOFS , nr_pages, &fs_bio_set); + bio =bio_alloc (GFP_NOFS , nr_pages);if (!bio)return -ENOMEM ;
Signature · 1 line
2.29.2
Re: [PATCH 01/17] zonefs: use bio_alloc in zonefs_file_dio_append
Quoted 13 lines · Christoph Hellwig
Use
bio_allocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/zonefs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/zonefs/super.c +0
-0
fs/zonefs/super.c static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) · line 684
Quoted 8 lines
fs/zonefs/super.c +1
-1@@ -678,7 +678,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)if (!nr_pages)return 0 ; - bio =bio_alloc_bioset (GFP_NOFS , nr_pages, &fs_bio_set); + bio =bio_alloc (GFP_NOFS , nr_pages);if (!bio)return -ENOMEM ;
Whoopsie my bad,
Re: [PATCH 01/17] zonefs: use bio_alloc in zonefs_file_dio_append
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Use
bio_allocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>
Ha Ha I was going send out a patch for this :P.
Re: [dm-devel] [PATCH 01/17] zonefs: use bio_alloc in zonefs_file_dio_append
In reply to Christoph HellwigQuoted 13 lines · Christoph Hellwig
Use
bio_allocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/zonefs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/zonefs/super.c +0
-0
fs/zonefs/super.c static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) · line 684
Quoted 8 lines
fs/zonefs/super.c +1
-1@@ -678,7 +678,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)if (!nr_pages)return 0 ; - bio =bio_alloc_bioset (GFP_NOFS , nr_pages, &fs_bio_set); + bio =bio_alloc (GFP_NOFS , nr_pages);if (!bio)return -ENOMEM ;
Signature · 2 lines
Damien Le Moal Western Digital Research
Christoph Hellwig
maintainerPATCH 2/17 btrfs: use bio_kmalloc in __alloc_device
In reply to Christoph HellwigUse bio_kmalloc instead of open coding it.
--- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/volumes.c +1 -1
@@ -421,7 +421,7 @@ static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)* Preallocate a bio that's always going to be used for flushing device * barriers and matches the device lifespan */ - dev->flush_bio =bio_alloc_bioset (GFP_KERNEL ,0 ,NULL ); + dev->flush_bio =bio_kmalloc (GFP_KERNEL ,0 );if (!dev->flush_bio) {kfree (dev);return ERR_PTR (-ENOMEM );
Signature · 1 line
2.29.2
Re: [PATCH 02/17] btrfs: use bio_kmalloc in __alloc_device
Quoted 3 lines · Christoph Hellwig
Use
bio_kmallocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>
yay I contributed,
Josef
Re: [PATCH 02/17] btrfs: use bio_kmalloc in __alloc_device
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Use
bio_kmallocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Christoph Hellwig
maintainerPATCH 3/17 blk-crypto: use bio_kmalloc in blk_crypto_clone_bio
In reply to Christoph HellwigUse bio_kmalloc instead of open coding it.
--- block/blk-crypto-fallback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-crypto-fallback.c +1 -1
@@ -164,7 +164,7 @@ static struct bio *blk_crypto_clone_bio(struct bio *bio_src)struct bio_vec bv;struct bio *bio; - bio =bio_alloc_bioset (GFP_NOIO ,bio_segments (bio_src),NULL ); + bio =bio_kmalloc (GFP_NOIO ,bio_segments (bio_src));if (!bio)return NULL ; bio->bi_bdev = bio_src->bi_bdev;
Signature · 1 line
2.29.2
Re: [PATCH 03/17] blk-crypto: use bio_kmalloc in blk_crypto_clone_bio
Quoted 13 lines · Christoph Hellwig
Use
bio_kmallocinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-crypto-fallback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-crypto-fallback.c +0
-0
block/blk-crypto-fallback.c static struct bio *blk_crypto_clone_bio(struct bio *bio_src) · line 170
Quoted 8 lines
block/blk-crypto-fallback.c +1
-1@@ -164,7 +164,7 @@ static struct bio *blk_crypto_clone_bio(struct bio *bio_src)struct bio_vec bv;struct bio *bio; - bio =bio_alloc_bioset (GFP_NOIO ,bio_segments (bio_src),NULL ); + bio =bio_kmalloc (GFP_NOIO ,bio_segments (bio_src));if (!bio)return NULL ; bio->bi_bdev = bio_src->bi_bdev;
Looks good,
Christoph Hellwig
maintainerPATCH 4/17 block: split bio_kmalloc from bio_alloc_bioset
In reply to Christoph Hellwigbio_kmalloc shares almost no logic with the bio_set based fast path in bio_alloc_bioset. Split it into an entirely separate implementation.
--- block/bio.c | 167 ++++++++++++++++++++++---------------------- include/linux/bio.h | 6 +- 2 files changed, 86 insertions(+), 87 deletions(-)
block/bio.c +85 -82
@@ -396,123 +396,101 @@ static void punt_bios_to_rescuer(struct bio_set *bs)* @nr_iovecs: number of iovecs to pre-allocate * @bs: the bio_set to allocate from. * -* Description: -* If @bs is NULL, uses kmalloc() to allocate the bio; else the allocation is -* backed by the @bs's mempool. +* Allocate a bio from the mempools in @bs. * -* When @bs is not NULL, if %__GFP_DIRECT_RECLAIM is set then bio_alloc will -* always be able to allocate a bio. This is due to the mempool guarantees. -* To make this work, callers must never allocate more than 1 bio at a time -* from this pool. Callers that need to allocate more than 1 bio must always -* submit the previously allocated bio for IO before attempting to allocate -* a new one. Failure to do so can cause deadlocks under memory pressure. +* If %__GFP_DIRECT_RECLAIM is set then bio_alloc will always be able to +* allocate a bio. This is due to the mempool guarantees. To make this work, +* callers must never allocate more than 1 bio at a time from the general pool. +* Callers that need to allocate more than 1 bio must always submit the +* previously allocated bio for IO before attempting to allocate a new one. +* Failure to do so can cause deadlocks under memory pressure. * -* Note that when running under submit_bio_noacct() (i.e. any block -* driver), bios are not submitted until after you return - see the code in -* submit_bio_noacct() that converts recursion into iteration, to prevent -* stack overflows. +* Note that when running under submit_bio_noacct() (i.e. any block driver), +* bios are not submitted until after you return - see the code in +* submit_bio_noacct() that converts recursion into iteration, to prevent +* stack overflows. * -* This would normally mean allocating multiple bios under -* submit_bio_noacct() would be susceptible to deadlocks, but we have -* deadlock avoidance code that resubmits any blocked bios from a rescuer -* thread. +* This would normally mean allocating multiple bios under submit_bio_noacct() +* would be susceptible to deadlocks, but we have +* deadlock avoidance code that resubmits any blocked bios from a rescuer +* thread. * -* However, we do not guarantee forward progress for allocations from other -* mempools. Doing multiple allocations from the same mempool under -* submit_bio_noacct() should be avoided - instead, use bio_set's front_pad -* for per bio allocations. +* However, we do not guarantee forward progress for allocations from other +* mempools. Doing multiple allocations from the same mempool under +* submit_bio_noacct() should be avoided - instead, use bio_set's front_pad +* for per bio allocations. * -* RETURNS: -* Pointer to new bio on success, NULL on failure. +* Returns: Pointer to new bio on success, NULL on failure. */ struct bio *bio_alloc_bioset (gfp_t gfp_mask,unsigned int nr_iovecs,struct bio_set *bs) {gfp_t saved_gfp = gfp_mask; -unsigned front_pad; -unsigned inline_vecs; -struct bio_vec *bvl =NULL ;struct bio *bio;void *p; -if (!bs) { -if (nr_iovecs >UIO_MAXIOV ) -return NULL ; - - p =kmalloc (struct_size (bio, bi_inline_vecs, nr_iovecs), gfp_mask); - front_pad =0 ; - inline_vecs = nr_iovecs; - }else { -/* should not use nobvec bioset for nr_iovecs > 0 */ -if (WARN_ON_ONCE (!mempool_initialized (&bs->bvec_pool) && - nr_iovecs >0 )) -return NULL ; -/* -* submit_bio_noacct() converts recursion to iteration; this -* means if we're running beneath it, any bios we allocate and -* submit will not be submitted (and thus freed) until after we -* return. -* -* This exposes us to a potential deadlock if we allocate -* multiple bios from the same bio_set() while running -* underneath submit_bio_noacct(). If we were to allocate -* multiple bios (say a stacking block driver that was splitting -* bios), we would deadlock if we exhausted the mempool's -* reserve. -* -* We solve this, and guarantee forward progress, with a rescuer -* workqueue per bio_set. If we go to allocate and there are -* bios on current->bio_list, we first try the allocation -* without __GFP_DIRECT_RECLAIM; if that fails, we punt those -* bios we would be blocking to the rescuer workqueue before -* we retry with the original gfp_flags. -*/ - -if (current->bio_list && - (!bio_list_empty (¤t->bio_list[0 ]) || - !bio_list_empty (¤t->bio_list[1 ])) && - bs->rescue_workqueue) - gfp_mask &= ~__GFP_DIRECT_RECLAIM; +/* should not use nobvec bioset for nr_iovecs > 0 */ +if (WARN_ON_ONCE (!mempool_initialized (&bs->bvec_pool) && nr_iovecs >0 )) +return NULL ; +/* +* submit_bio_noacct() converts recursion to iteration; this means if +* we're running beneath it, any bios we allocate and submit will not be +* submitted (and thus freed) until after we return. +* +* This exposes us to a potential deadlock if we allocate multiple bios +* from the same bio_set() while running underneath submit_bio_noacct(). +* If we were to allocate multiple bios (say a stacking block driver +* that was splitting bios), we would deadlock if we exhausted the +* mempool's reserve. +* +* We solve this, and guarantee forward progress, with a rescuer +* workqueue per bio_set. If we go to allocate and there are bios on +* current->bio_list, we first try the allocation without +* __GFP_DIRECT_RECLAIM; if that fails, we punt those bios we would be +* blocking to the rescuer workqueue before we retry with the original +* gfp_flags. +*/ +if (current->bio_list && + (!bio_list_empty (¤t->bio_list[0 ]) || + !bio_list_empty (¤t->bio_list[1 ])) && + bs->rescue_workqueue) + gfp_mask &= ~__GFP_DIRECT_RECLAIM; + + p =mempool_alloc (&bs->bio_pool, gfp_mask); +if (!p && gfp_mask != saved_gfp) { +punt_bios_to_rescuer (bs); + gfp_mask = saved_gfp; p =mempool_alloc (&bs->bio_pool, gfp_mask); -if (!p && gfp_mask != saved_gfp) { -punt_bios_to_rescuer (bs); - gfp_mask = saved_gfp; - p =mempool_alloc (&bs->bio_pool, gfp_mask); - } - - front_pad = bs->front_pad; - inline_vecs =BIO_INLINE_VECS ; } -if (unlikely (!p))return NULL ; - bio = p + front_pad; -bio_init (bio,NULL ,0 ); - -if (nr_iovecs > inline_vecs) { + bio = p + bs->front_pad; +if (nr_iovecs >BIO_INLINE_VECS ) {unsigned long idx =0 ; +struct bio_vec *bvl =NULL ; bvl =bvec_alloc (gfp_mask, nr_iovecs, &idx, &bs->bvec_pool);if (!bvl && gfp_mask != saved_gfp) {punt_bios_to_rescuer (bs); gfp_mask = saved_gfp; - bvl =bvec_alloc (gfp_mask, nr_iovecs, &idx, &bs->bvec_pool); + bvl =bvec_alloc (gfp_mask, nr_iovecs, &idx, + &bs->bvec_pool); }if (unlikely (!bvl)) goto err_free; bio->bi_flags |= idx <<BVEC_POOL_OFFSET ; - bio->bi_max_vecs =bvec_nr_vecs (idx); +bio_init (bio, bvl,bvec_nr_vecs (idx)); }else if (nr_iovecs) { - bvl = bio->bi_inline_vecs; - bio->bi_max_vecs = inline_vecs; +bio_init (bio, bio->bi_inline_vecs,BIO_INLINE_VECS ); + }else { +bio_init (bio,NULL ,0 ); } bio->bi_pool = bs; - bio->bi_io_vec = bvl;return bio; err_free:
@@ -521,6 +499,31 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs, }EXPORT_SYMBOL (bio_alloc_bioset); +/** +* bio_kmalloc - kmalloc a bio for I/O +* @gfp_mask: the GFP_* mask given to the slab allocator +* @nr_iovecs: number of iovecs to pre-allocate +* +* Use kmalloc to allocate and initialize a bio. +* +* Returns: Pointer to new bio on success, NULL on failure. +*/ +struct bio *bio_kmalloc (gfp_t gfp_mask,unsigned int nr_iovecs) +{ +struct bio *bio; + +if (nr_iovecs >UIO_MAXIOV ) +return NULL ; + + bio =kmalloc (struct_size (bio, bi_inline_vecs, nr_iovecs), gfp_mask); +if (unlikely (!bio)) +return NULL ; +bio_init (bio, nr_iovecs ? bio->bi_inline_vecs :NULL , nr_iovecs); + bio->bi_pool =NULL ; +return bio; +} +EXPORT_SYMBOL (bio_kmalloc); +void zero_fill_bio_iter (struct bio *bio,struct bvec_iter start) {unsigned long flags;
include/linux/bio.h +1 -5
@@ -408,6 +408,7 @@ extern int biovec_init_pool(mempool_t *pool, int pool_entries);extern int bioset_init_from_src (struct bio_set *bs,struct bio_set *src);extern struct bio *bio_alloc_bioset (gfp_t ,unsigned int ,struct bio_set *); +struct bio *bio_kmalloc (gfp_t gfp_mask,unsigned int nr_iovecs);extern void bio_put (struct bio *);extern void __bio_clone_fast (struct bio *,struct bio *);
@@ -420,11 +421,6 @@ static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)return bio_alloc_bioset (gfp_mask, nr_iovecs, &fs_bio_set); } -static inline struct bio *bio_kmalloc (gfp_t gfp_mask,unsigned int nr_iovecs) -{ -return bio_alloc_bioset (gfp_mask, nr_iovecs,NULL ); -} -extern blk_qc_t submit_bio (struct bio *);extern void bio_endio (struct bio *);
Signature · 1 line
2.29.2
Re: [PATCH 04/17] block: split bio_kmalloc from bio_alloc_bioset
Quoted 8 lines · Christoph Hellwig
bio_kmallocshares almost no logic with thebio_setbased fast path inbio_alloc_bioset. Split it into an entirely separate implementation.Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 167 ++++++++++++++++++++++---------------------- include/linux/bio.h | 6 +- 2 files changed, 86 insertions(+), 87 deletions(-)
This patch causes current linux-next to OOM for me when running xfstests after about ten minutes. Haven't looked into why yet, this is just the results of a git bisect.
The qemu command line is:
qemu-system-x86_64 -nodefaults -nographic -cpu host -machine accel=kvm,nvdimm -m 2G,slots=8,maxmem=1T -smp 6 -kernel /home/willy/kernel/folio/.build_test_kernel-x86_64/kpgk/vmlinuz -append console=hvc0 root=/dev/sda rw log_buf_len=8M ktest.dir=/home/willy/kernel/ktest ktest.env=/tmp/build-test-kernel-nJO6QgxOmo/env quiet systemd.show_status=0 systemd.log-target=journal crashkernel=128M no_console_suspend -device virtio-serial -chardev stdio,id=console -device virtconsole,chardev=console -serial unix:/tmp/build-test-kernel-nJO6QgxOmo/vm-kgdb,server,nowait -monitor unix:/tmp/build-test-kernel-nJO6QgxOmo/vm-mon,server,nowait -gdb unix:/tmp/build-test-kernel-nJO6QgxOmo/vm-gdb,server,nowait -device virtio-rng-pci -virtfs local,path=/,mount_tag=host,security_model=none -device virtio-scsi-pci,id
=hba -nic user,model=virtio,hostfwd=tcp:127.0.0.1:24674-:22 -drive if=none,format=raw,id=disk0,file=/var/lib/ktest/root.amd64,snapshot=on -device scsi-hd,bus=hba.0,drive=disk0 -drive if=none
,format=raw,id=disk1,file=/tmp/build-test-kernel-nJO6QgxOmo/dev-1,cache=unsafe -device scsi-hd,bus=hba.0,drive=disk1 -drive if=none,format=raw,id=disk2,file=/tmp/build-test-kernel-nJO6QgxOmo/dev-2,cache=unsafe -device scsi-hd,bus=hba.0,drive=disk2 -drive if=none,format=raw,id=disk3,file=/tmp/build-test-kernel-nJO6QgxOmo/dev-3,cache=unsafe -device scsi-hd,bus=hba.0,drive=disk3
Christoph Hellwig
maintainerRe: [PATCH 04/17] block: split bio_kmalloc from bio_alloc_bioset
Quoted 10 lines · Matthew Wilcox
Quoted 8 lines · Christoph Hellwig
bio_kmallocshares almost no logic with thebio_setbased fast path inbio_alloc_bioset. Split it into an entirely separate implementation.Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 167 ++++++++++++++++++++++---------------------- include/linux/bio.h | 6 +- 2 files changed, 86 insertions(+), 87 deletions(-)
Quoted 3 lines
This patch causes current linux-next to OOM for me when running xfstests after about ten minutes. Haven't looked into why yet, this is just the results of a git bisect.
I've run tests on linux-next all weekend and could not reproduce the issue. Can you share your .config?
Christoph Hellwig
maintainerPATCH 5/17 block: use an on-stack bio in blkdev_issue_flush
In reply to Christoph HellwigThere is no point in allocating memory for a synchronous flush.
--- block/blk-flush.c | 17 ++++++----------- drivers/md/dm-zoned-metadata.c | 6 +++--- drivers/md/raid5-ppl.c | 2 +- drivers/nvme/target/io-cmd-bdev.c | 2 +- fs/block_dev.c | 2 +- fs/exfat/file.c | 2 +- fs/ext4/fast_commit.c | 4 ++-- fs/ext4/fsync.c | 2 +- fs/ext4/ialloc.c | 2 +- fs/ext4/super.c | 2 +- fs/fat/file.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/hfsplus/super.c | 2 +- fs/jbd2/checkpoint.c | 2 +- fs/jbd2/commit.c | 4 ++-- fs/jbd2/recovery.c | 2 +- fs/libfs.c | 2 +- fs/nilfs2/the_nilfs.h | 2 +- fs/ocfs2/file.c | 2 +- fs/reiserfs/file.c | 2 +- fs/xfs/xfs_super.c | 2 +- fs/zonefs/super.c | 2 +- include/linux/blkdev.h | 4 ++-- 23 files changed, 33 insertions(+), 38 deletions(-)
block/blk-flush.c +6 -11
@@ -432,23 +432,18 @@ void blk_insert_flush(struct request *rq)/** * blkdev_issue_flush - queue a flush * @bdev: blockdev to issue flush for -* @gfp_mask: memory allocation flags (for bio_alloc) * * Description: * Issue a flush for the block device in question. */ -int blkdev_issue_flush (struct block_device *bdev,gfp_t gfp_mask) +int blkdev_issue_flush (struct block_device *bdev) { -struct bio *bio; -int ret =0 ; +struct bio bio; - bio =bio_alloc (gfp_mask,0 ); -bio_set_dev (bio, bdev); - bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; - - ret =submit_bio_wait (bio); -bio_put (bio); -return ret; +bio_init (&bio,NULL ,0 ); +bio_set_dev (&bio, bdev); + bio.bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; +return submit_bio_wait (&bio); }EXPORT_SYMBOL (blkdev_issue_flush);
drivers/md/dm-zoned-metadata.c +3 -3
@@ -819,7 +819,7 @@ static int dmz_write_sb(struct dmz_metadata *zmd, unsigned int set) ret =dmz_rdwr_block (dev,REQ_OP_WRITE , zmd->sb[set].block, mblk->page);if (ret ==0 ) - ret =blkdev_issue_flush (dev->bdev,GFP_NOIO ); + ret =blkdev_issue_flush (dev->bdev);return ret; }
@@ -862,7 +862,7 @@ static int dmz_write_dirty_mblocks(struct dmz_metadata *zmd,/* Flush drive cache (this will also sync data) */ if (ret ==0 ) - ret =blkdev_issue_flush (dev->bdev,GFP_NOIO ); + ret =blkdev_issue_flush (dev->bdev);return ret; }
@@ -933,7 +933,7 @@ int dmz_flush_metadata(struct dmz_metadata *zmd)/* If there are no dirty metadata blocks, just flush the device cache */ if (list_empty (&write_list)) { - ret =blkdev_issue_flush (dev->bdev,GFP_NOIO ); + ret =blkdev_issue_flush (dev->bdev); goto err; }
drivers/md/raid5-ppl.c +1 -1
@@ -1037,7 +1037,7 @@ static int ppl_recover(struct ppl_log *log, struct ppl_header *pplhdr, }/* flush the disk cache after recovery if necessary */ - ret =blkdev_issue_flush (rdev->bdev,GFP_KERNEL ); + ret =blkdev_issue_flush (rdev->bdev); out:__free_page (page);return ret;
drivers/nvme/target/io-cmd-bdev.c +1 -1
@@ -333,7 +333,7 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)u16 nvmet_bdev_flush (struct nvmet_req *req) { -if (blkdev_issue_flush (req->ns->bdev,GFP_KERNEL )) +if (blkdev_issue_flush (req->ns->bdev))return NVME_SC_INTERNAL |NVME_SC_DNR ;return 0 ; }
fs/block_dev.c +1 -1
@@ -681,7 +681,7 @@ int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)* i_mutex and doing so causes performance issues with concurrent * O_SYNC writers to a block device. */ - error =blkdev_issue_flush (bdev,GFP_KERNEL ); + error =blkdev_issue_flush (bdev);if (error == -EOPNOTSUPP ) error =0 ;
fs/exfat/file.c +1 -1
@@ -361,7 +361,7 @@ int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)if (err)return err; -return blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); +return blkdev_issue_flush (inode->i_sb->s_bdev); }const struct file_operations exfat_file_operations = {
fs/ext4/fast_commit.c +2 -2
@@ -1076,7 +1076,7 @@ static int ext4_fc_perform_commit(journal_t *journal)* flush before we start writing fast commit blocks. */ if (journal->j_fs_dev != journal->j_dev) -blkdev_issue_flush (journal->j_fs_dev,GFP_NOFS ); +blkdev_issue_flush (journal->j_fs_dev);blk_start_plug (&plug);if (sbi->s_fc_bytes ==0 ) {
@@ -1535,7 +1535,7 @@ static int ext4_fc_replay_inode(struct super_block *sb, struct ext4_fc_tl *tl) out:iput (inode);if (!ret) -blkdev_issue_flush (sb->s_bdev,GFP_KERNEL ); +blkdev_issue_flush (sb->s_bdev);return 0 ; }
fs/ext4/fsync.c +1 -1
@@ -174,7 +174,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ret =ext4_fsync_journal (inode, datasync, &needs_barrier);if (needs_barrier) { - err =blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); + err =blkdev_issue_flush (inode->i_sb->s_bdev);if (!ret) ret = err; }
fs/ext4/ialloc.c +1 -1
@@ -1583,7 +1583,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,if (ret <0 ) goto err_out;if (barrier) -blkdev_issue_flush (sb->s_bdev,GFP_NOFS ); +blkdev_issue_flush (sb->s_bdev); skip_zeroout:ext4_lock_group (sb, group);
fs/ext4/super.c +1 -1
@@ -5709,7 +5709,7 @@ static int ext4_sync_fs(struct super_block *sb, int wait) needs_barrier = true;if (needs_barrier) {int err; - err =blkdev_issue_flush (sb->s_bdev,GFP_KERNEL ); + err =blkdev_issue_flush (sb->s_bdev);if (!ret) ret = err; }
fs/fat/file.c +1 -1
@@ -195,7 +195,7 @@ int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)if (err)return err; -return blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); +return blkdev_issue_flush (inode->i_sb->s_bdev); }
fs/hfsplus/inode.c +1 -1
@@ -340,7 +340,7 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, }if (!test_bit (HFSPLUS_SB_NOBARRIER , &sbi->flags)) -blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); +blkdev_issue_flush (inode->i_sb->s_bdev);inode_unlock (inode);
fs/hfsplus/super.c +1 -1
@@ -239,7 +239,7 @@ static int hfsplus_sync_fs(struct super_block *sb, int wait)mutex_unlock (&sbi->vh_mutex);if (!test_bit (HFSPLUS_SB_NOBARRIER , &sbi->flags)) -blkdev_issue_flush (sb->s_bdev,GFP_KERNEL ); +blkdev_issue_flush (sb->s_bdev);return error; }
fs/jbd2/checkpoint.c +1 -1
@@ -416,7 +416,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)* jbd2_cleanup_journal_tail() doesn't get called all that often. */ if (journal->j_flags &JBD2_BARRIER ) -blkdev_issue_flush (journal->j_fs_dev,GFP_NOFS ); +blkdev_issue_flush (journal->j_fs_dev);return __jbd2_update_log_tail (journal, first_tid, blocknr); }
fs/jbd2/commit.c +2 -2
@@ -825,7 +825,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)if (commit_transaction->t_need_data_flush && (journal->j_fs_dev != journal->j_dev) && (journal->j_flags &JBD2_BARRIER )) -blkdev_issue_flush (journal->j_fs_dev,GFP_NOFS ); +blkdev_issue_flush (journal->j_fs_dev);/* Done it all: now write the commit record asynchronously. */ if (jbd2_has_feature_async_commit (journal)) {
@@ -932,7 +932,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) stats.run.rs_blocks_logged++;if (jbd2_has_feature_async_commit (journal) && journal->j_flags &JBD2_BARRIER ) { -blkdev_issue_flush (journal->j_dev,GFP_NOFS ); +blkdev_issue_flush (journal->j_dev); }if (err)
fs/jbd2/recovery.c +1 -1
@@ -326,7 +326,7 @@ int jbd2_journal_recover(journal_t *journal) err = err2;/* Make sure all replayed data is on permanent storage */ if (journal->j_flags &JBD2_BARRIER ) { - err2 =blkdev_issue_flush (journal->j_fs_dev,GFP_KERNEL ); + err2 =blkdev_issue_flush (journal->j_fs_dev);if (!err) err = err2; }
fs/libfs.c +1 -1
@@ -1117,7 +1117,7 @@ int generic_file_fsync(struct file *file, loff_t start, loff_t end, err =__generic_file_fsync (file, start, end, datasync);if (err)return err; -return blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); +return blkdev_issue_flush (inode->i_sb->s_bdev); }EXPORT_SYMBOL (generic_file_fsync);
fs/nilfs2/the_nilfs.h +1 -1
@@ -375,7 +375,7 @@ static inline int nilfs_flush_device(struct the_nilfs *nilfs)*/ smp_wmb (); - err =blkdev_issue_flush (nilfs->ns_bdev,GFP_KERNEL ); + err =blkdev_issue_flush (nilfs->ns_bdev);if (err != -EIO ) err =0 ;return err;
fs/ocfs2/file.c +1 -1
@@ -194,7 +194,7 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end, needs_barrier = true; err =jbd2_complete_transaction (journal, commit_tid);if (needs_barrier) { - ret =blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); + ret =blkdev_issue_flush (inode->i_sb->s_bdev);if (!err) err = ret; }
fs/reiserfs/file.c +1 -1
@@ -159,7 +159,7 @@ static int reiserfs_sync_file(struct file *filp, loff_t start, loff_t end, barrier_done =reiserfs_commit_for_inode (inode);reiserfs_write_unlock (inode->i_sb);if (barrier_done !=1 &&reiserfs_barrier_flush (inode->i_sb)) -blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); +blkdev_issue_flush (inode->i_sb->s_bdev);inode_unlock (inode);if (barrier_done <0 )return barrier_done;
fs/xfs/xfs_super.c +1 -1
@@ -342,7 +342,7 @@ voidxfs_blkdev_issue_flush ( xfs_buftarg_t *buftarg) { -blkdev_issue_flush (buftarg->bt_bdev,GFP_NOFS ); +blkdev_issue_flush (buftarg->bt_bdev); }STATIC void
fs/zonefs/super.c +1 -1
@@ -541,7 +541,7 @@ static int zonefs_file_fsync(struct file *file, loff_t start, loff_t end,if (ZONEFS_I (inode)->i_ztype ==ZONEFS_ZTYPE_CNV ) ret =file_write_and_wait_range (file, start, end);if (!ret) - ret =blkdev_issue_flush (inode->i_sb->s_bdev,GFP_KERNEL ); + ret =blkdev_issue_flush (inode->i_sb->s_bdev);if (ret)zonefs_io_error (inode, true);
include/linux/blkdev.h +2 -2
@@ -1288,7 +1288,7 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk) !list_empty(&plug->cb_list)); } -int blkdev_issue_flush (struct block_device *,gfp_t ); +int blkdev_issue_flush (struct block_device *bdev);long nr_blockdev_pages (void );#else /* CONFIG_BLOCK */ struct blk_plug {
@@ -1316,7 +1316,7 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk)return false; } -static inline int blkdev_issue_flush (struct block_device *bdev,gfp_t gfp_mask) +static inline int blkdev_issue_flush (struct block_device *bdev) {return 0 ; }
Signature · 1 line
2.29.2
Re: [PATCH 05/17] block: use an on-stack bio in blkdev_issue_flush
Quoted 3 lines · Christoph Hellwig
There is no point in allocating memory for a synchronous flush.
Signed-off-by Christoph Hellwig <[email protected]>
True, looks good.
Christoph Hellwig
maintainerPATCH 6/17 dm-clone: use blkdev_issue_flush in commit_metadata
In reply to Christoph HellwigUse blkdev_issue_flush instead of open coding it.
--- drivers/md/dm-clone-target.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/md/dm-clone-target.c +1 -13
@@ -85,12 +85,6 @@ struct clone {struct dm_clone_metadata *cmd; -/* -* bio used to flush the destination device, before committing the -* metadata. -*/ -struct bio flush_bio; -/* Region hydration hash table */ struct hash_table_bucket *ht;
@@ -1155,11 +1149,7 @@ static int commit_metadata(struct clone *clone, bool *dest_dev_flushed) goto out; } -bio_reset (&clone->flush_bio); -bio_set_dev (&clone->flush_bio, clone->dest_dev->bdev); - clone->flush_bio.bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; - - r =submit_bio_wait (&clone->flush_bio); + r =blkdev_issue_flush (clone->dest_dev->bdev);if (unlikely (r)) {__metadata_operation_failed (clone,"flush destination device" , r); goto out;
@@ -1886,7 +1876,6 @@ static int clone_ctr(struct dm_target *ti, unsigned int argc, char **argv)bio_list_init (&clone->deferred_flush_completions); clone->hydration_offset =0 ;atomic_set (&clone->hydrations_in_flight,0 ); -bio_init (&clone->flush_bio,NULL ,0 ); clone->wq =alloc_workqueue ("dm-" DM_MSG_PREFIX ,WQ_MEM_RECLAIM ,0 );if (!clone->wq) {
@@ -1958,7 +1947,6 @@ static void clone_dtr(struct dm_target *ti)struct clone *clone = ti->private;mutex_destroy (&clone->commit_lock); -bio_uninit (&clone->flush_bio);for (i =0 ; i < clone->nr_ctr_args; i++)kfree (clone->ctr_args[i]);
Signature · 1 line
2.29.2
Christoph Hellwig
maintainerPATCH 7/17 f2fs: use blkdev_issue_flush in __submit_flush_wait
In reply to Christoph HellwigUse the blkdev_issue_flush helper instead of duplicating it.
--- fs/f2fs/data.c | 3 ++- fs/f2fs/f2fs.h | 1 - fs/f2fs/segment.c | 12 +----------- 3 files changed, 3 insertions(+), 13 deletions(-)
fs/f2fs/data.c +2 -1
@@ -56,7 +56,8 @@ static inline struct bio *__f2fs_bio_alloc(gfp_t gfp_mask,return bio_alloc_bioset (gfp_mask, nr_iovecs, &f2fs_bioset); } -struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages,bool noio) +static struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages, +bool noio) {if (noio) {/* No failure on bio allocation */
fs/f2fs/f2fs.h +0 -1
@@ -3424,7 +3424,6 @@ void f2fs_destroy_checkpoint_caches(void);*/ int __init f2fs_init_bioset (void );void f2fs_destroy_bioset (void ); -struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages,bool noio);int f2fs_init_bio_entry_cache (void );void f2fs_destroy_bio_entry_cache (void ); void f2fs_submit_bio(struct f2fs_sb_info *sbi,
fs/f2fs/segment.c +1 -11
@@ -566,17 +566,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)static int __submit_flush_wait (struct f2fs_sb_info *sbi,struct block_device *bdev) { -struct bio *bio; -int ret; - - bio =f2fs_bio_alloc (sbi,0 , false); -if (!bio) -return -ENOMEM ; - - bio->bi_opf =REQ_OP_WRITE |REQ_SYNC |REQ_PREFLUSH ; -bio_set_dev (bio, bdev); - ret =submit_bio_wait (bio); -bio_put (bio); +int ret =blkdev_issue_flush (bdev);trace_f2fs_issue_flush (bdev,test_opt (sbi,NOBARRIER ),test_opt (sbi,FLUSH_MERGE ), ret);
Signature · 1 line
2.29.2
Re: [f2fs-dev] [PATCH 07/17] f2fs: use blkdev_issue_flush in __submit_flush_wait
Quoted 3 lines · Christoph Hellwig
Use the
blkdev_issue_flushhelper instead of duplicating it.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Christoph Hellwig
maintainerPATCH 8/17 f2fs: remove FAULT_ALLOC_BIO
In reply to Christoph HellwigSleeping bio allocations do not fail, which means that injecting an error into sleeping bio allocations is a little silly.
--- Documentation/filesystems/f2fs.rst | 1 - fs/f2fs/data.c | 29 ++++------------------------- fs/f2fs/f2fs.h | 1 - fs/f2fs/super.c | 1 - 4 files changed, 4 insertions(+), 28 deletions(-)
Documentation/filesystems/f2fs.rst +0 -1
@@ -179,7 +179,6 @@ fault_type=%d Support configuring fault injection type, should be FAULT_KVMALLOC 0x000000002 FAULT_PAGE_ALLOC 0x000000004 FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 FAULT_ALLOC_NID 0x000000020 FAULT_ORPHAN 0x000000040 FAULT_BLOCK 0x000000080
fs/f2fs/data.c +4 -25
@@ -50,28 +50,6 @@ void f2fs_destroy_bioset(void)bioset_exit (&f2fs_bioset); } -static inline struct bio *__f2fs_bio_alloc (gfp_t gfp_mask, -unsigned int nr_iovecs) -{ -return bio_alloc_bioset (gfp_mask, nr_iovecs, &f2fs_bioset); -} - -static struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages, -bool noio) -{ -if (noio) { -/* No failure on bio allocation */ -return __f2fs_bio_alloc (GFP_NOIO , npages); - } - -if (time_to_inject (sbi,FAULT_ALLOC_BIO )) { -f2fs_show_injection_info (sbi,FAULT_ALLOC_BIO ); -return NULL ; - } - -return __f2fs_bio_alloc (GFP_KERNEL , npages); -} -static bool __is_cp_guaranteed (struct page *page) {struct address_space *mapping = page->mapping;
@@ -433,7 +411,7 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)struct f2fs_sb_info *sbi = fio->sbi;struct bio *bio; - bio =f2fs_bio_alloc (sbi, npages, true); + bio =bio_alloc_bioset (GFP_NOIO , npages, &f2fs_bioset);f2fs_target_device (sbi, fio->new_blkaddr, bio);if (is_read_io (fio->op)) {
@@ -1029,8 +1007,9 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,struct bio_post_read_ctx *ctx;unsigned int post_read_steps =0 ; - bio =f2fs_bio_alloc (sbi,min_t (int, nr_pages,BIO_MAX_PAGES ), - for_write); + bio =bio_alloc_bioset (for_write ?GFP_NOIO :GFP_KERNEL , +min_t (int, nr_pages,BIO_MAX_PAGES ), + &f2fs_bioset);if (!bio)return ERR_PTR (-ENOMEM );
fs/f2fs/f2fs.h +0 -1
@@ -43,7 +43,6 @@ enum {FAULT_KVMALLOC ,FAULT_PAGE_ALLOC ,FAULT_PAGE_GET , -FAULT_ALLOC_BIO ,FAULT_ALLOC_NID ,FAULT_ORPHAN , FAULT_BLOCK,
fs/f2fs/super.c +0 -1
@@ -45,7 +45,6 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_KVMALLOC] = "kvmalloc", [FAULT_PAGE_ALLOC] = "page alloc", [FAULT_PAGE_GET] = "page get", - [FAULT_ALLOC_BIO] = "alloc bio", [FAULT_ALLOC_NID] = "alloc nid", [FAULT_ORPHAN] = "orphan", [FAULT_BLOCK] = "no more block",
Signature · 1 line
2.29.2
Re: [f2fs-dev] [PATCH 08/17] f2fs: remove FAULT_ALLOC_BIO
Jaegeuk,
I remember that you concerned about backport issue of bio fault injection entry removal? IIRC.
If you have no objection on this now, let me Ack f2fs part change on this series.
Thanks,
Quoted 95 lines · Christoph Hellwig
Sleeping bio allocations do not fail, which means that injecting an error into sleeping bio allocations is a little silly.
Signed-off-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/f2fs.rst | 1 - fs/f2fs/data.c | 29 ++++------------------------- fs/f2fs/f2fs.h | 1 - fs/f2fs/super.c | 1 - 4 files changed, 4 insertions(+), 28 deletions(-)Documentation/filesystems/f2fs.rst +0
-1@@ -179,7 +179,6 @@ fault_type=%d Support configuring fault injection type, should be FAULT_KVMALLOC 0x000000002 FAULT_PAGE_ALLOC 0x000000004 FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 FAULT_ALLOC_NID 0x000000020 FAULT_ORPHAN 0x000000040 FAULT_BLOCK 0x000000080fs/f2fs/data.c +4
-25@@ -50,28 +50,6 @@ void f2fs_destroy_bioset(void)bioset_exit (&f2fs_bioset); } -static inline struct bio *__f2fs_bio_alloc (gfp_t gfp_mask, -unsigned int nr_iovecs) -{ -return bio_alloc_bioset (gfp_mask, nr_iovecs, &f2fs_bioset); -} - -static struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages, -bool noio) -{ -if (noio) { -/* No failure on bio allocation */ -return __f2fs_bio_alloc (GFP_NOIO , npages); - } - -if (time_to_inject (sbi,FAULT_ALLOC_BIO )) { -f2fs_show_injection_info (sbi,FAULT_ALLOC_BIO ); -return NULL ; - } - -return __f2fs_bio_alloc (GFP_KERNEL , npages); -} -static bool __is_cp_guaranteed (struct page *page) {struct address_space *mapping = page->mapping;@@ -433,7 +411,7 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)struct f2fs_sb_info *sbi = fio->sbi;struct bio *bio; - bio =f2fs_bio_alloc (sbi, npages, true); + bio =bio_alloc_bioset (GFP_NOIO , npages, &f2fs_bioset);f2fs_target_device (sbi, fio->new_blkaddr, bio);if (is_read_io (fio->op)) {@@ -1029,8 +1007,9 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,struct bio_post_read_ctx *ctx;unsigned int post_read_steps =0 ; - bio =f2fs_bio_alloc (sbi,min_t (int, nr_pages,BIO_MAX_PAGES ), - for_write); + bio =bio_alloc_bioset (for_write ?GFP_NOIO :GFP_KERNEL , +min_t (int, nr_pages,BIO_MAX_PAGES ), + &f2fs_bioset);if (!bio)return ERR_PTR (-ENOMEM );fs/f2fs/f2fs.h +0
-1@@ -43,7 +43,6 @@ enum {FAULT_KVMALLOC ,FAULT_PAGE_ALLOC ,FAULT_PAGE_GET , -FAULT_ALLOC_BIO ,FAULT_ALLOC_NID ,FAULT_ORPHAN , FAULT_BLOCK,fs/f2fs/super.c +0
-0
fs/f2fs/super.c const char *f2fs_fault_name[FAULT_MAX] = { · line 50
Quoted 7 lines
fs/f2fs/super.c +0
-1@@ -45,7 +45,6 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_KVMALLOC] = "kvmalloc", [FAULT_PAGE_ALLOC] = "page alloc", [FAULT_PAGE_GET] = "page get", - [FAULT_ALLOC_BIO] = "alloc bio", [FAULT_ALLOC_NID] = "alloc nid", [FAULT_ORPHAN] = "orphan", [FAULT_BLOCK] = "no more block",
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH 08/17] f2fs: remove FAULT_ALLOC_BIO
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Sleeping bio allocations do not fail, which means that injecting an error into sleeping bio allocations is a little silly.
Signed-off-by Christoph Hellwig <[email protected]>
Already merged tho.
Quoted 99 lines
--- Documentation/filesystems/f2fs.rst | 1 - fs/f2fs/data.c | 29 ++++------------------------- fs/f2fs/f2fs.h | 1 - fs/f2fs/super.c | 1 - 4 files changed, 4 insertions(+), 28 deletions(-)Documentation/filesystems/f2fs.rst +0
-1@@ -179,7 +179,6 @@ fault_type=%d Support configuring fault injection type, should be FAULT_KVMALLOC 0x000000002 FAULT_PAGE_ALLOC 0x000000004 FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 FAULT_ALLOC_NID 0x000000020 FAULT_ORPHAN 0x000000040 FAULT_BLOCK 0x000000080fs/f2fs/data.c +4
-25@@ -50,28 +50,6 @@ void f2fs_destroy_bioset(void)bioset_exit (&f2fs_bioset); } -static inline struct bio *__f2fs_bio_alloc (gfp_t gfp_mask, -unsigned int nr_iovecs) -{ -return bio_alloc_bioset (gfp_mask, nr_iovecs, &f2fs_bioset); -} - -static struct bio *f2fs_bio_alloc (struct f2fs_sb_info *sbi,int npages, -bool noio) -{ -if (noio) { -/* No failure on bio allocation */ -return __f2fs_bio_alloc (GFP_NOIO , npages); - } - -if (time_to_inject (sbi,FAULT_ALLOC_BIO )) { -f2fs_show_injection_info (sbi,FAULT_ALLOC_BIO ); -return NULL ; - } - -return __f2fs_bio_alloc (GFP_KERNEL , npages); -} -static bool __is_cp_guaranteed (struct page *page) {struct address_space *mapping = page->mapping;@@ -433,7 +411,7 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)struct f2fs_sb_info *sbi = fio->sbi;struct bio *bio; - bio =f2fs_bio_alloc (sbi, npages, true); + bio =bio_alloc_bioset (GFP_NOIO , npages, &f2fs_bioset);f2fs_target_device (sbi, fio->new_blkaddr, bio);if (is_read_io (fio->op)) {@@ -1029,8 +1007,9 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,struct bio_post_read_ctx *ctx;unsigned int post_read_steps =0 ; - bio =f2fs_bio_alloc (sbi,min_t (int, nr_pages,BIO_MAX_PAGES ), - for_write); + bio =bio_alloc_bioset (for_write ?GFP_NOIO :GFP_KERNEL , +min_t (int, nr_pages,BIO_MAX_PAGES ), + &f2fs_bioset);if (!bio)return ERR_PTR (-ENOMEM );fs/f2fs/f2fs.h +0
-1@@ -43,7 +43,6 @@ enum {FAULT_KVMALLOC ,FAULT_PAGE_ALLOC ,FAULT_PAGE_GET , -FAULT_ALLOC_BIO ,FAULT_ALLOC_NID ,FAULT_ORPHAN , FAULT_BLOCK,fs/f2fs/super.c +0
-1@@ -45,7 +45,6 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_KVMALLOC] = "kvmalloc", [FAULT_PAGE_ALLOC] = "page alloc", [FAULT_PAGE_GET] = "page get", - [FAULT_ALLOC_BIO] = "alloc bio", [FAULT_ALLOC_NID] = "alloc nid", [FAULT_ORPHAN] = "orphan", [FAULT_BLOCK] = "no more block",Signature · 1 line
2.29.2
Re: [f2fs-dev] [PATCH 08/17] f2fs: remove FAULT_ALLOC_BIO
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Sleeping bio allocations do not fail, which means that injecting an error into sleeping bio allocations is a little silly.
Signed-off-by Christoph Hellwig<[email protected]>
Thanks,
Christoph Hellwig
maintainerPATCH 9/17 drbd: remove bio_alloc_drbd
In reply to Christoph HellwigGiven that drbd_md_io_bio_set is initialized during module initialization and the module fails to load if the initialization fails there is no need to fall back to plain bio_alloc.
--- drivers/block/drbd/drbd_actlog.c | 2 +- drivers/block/drbd/drbd_bitmap.c | 2 +- drivers/block/drbd/drbd_int.h | 2 -- drivers/block/drbd/drbd_main.c | 13 ------------- 4 files changed, 2 insertions(+), 17 deletions(-)
drivers/block/drbd/drbd_actlog.c +1 -1
@@ -138,7 +138,7 @@ static int _drbd_md_sync_page_io(struct drbd_device *device, op_flags |=REQ_FUA |REQ_PREFLUSH ; op_flags |=REQ_SYNC ; - bio =bio_alloc_drbd (GFP_NOIO ); + bio =bio_alloc_bioset (GFP_NOIO ,1 , &drbd_md_io_bio_set);bio_set_dev (bio, bdev->md_bdev); bio->bi_iter.bi_sector = sector; err = -EIO ;
drivers/block/drbd/drbd_bitmap.c +1 -1
@@ -976,7 +976,7 @@ static void drbd_bm_endio(struct bio *bio)static void bm_page_io_async (struct drbd_bm_aio_ctx *ctx,int page_nr)__must_hold (local) { -struct bio *bio =bio_alloc_drbd (GFP_NOIO ); +struct bio *bio =bio_alloc_bioset (GFP_NOIO ,1 , &drbd_md_io_bio_set);struct drbd_device *device = ctx->device;struct drbd_bitmap *b = device->bitmap;struct page *page;
drivers/block/drbd/drbd_int.h +0 -2
@@ -1422,8 +1422,6 @@ extern mempool_t drbd_md_io_page_pool;/* We also need to make sure we get a bio * when we need it for housekeeping purposes */ extern struct bio_set drbd_md_io_bio_set; -/* to allocate from that set */ -extern struct bio *bio_alloc_drbd (gfp_t gfp_mask);/* And a bio_set for cloning */ extern struct bio_set drbd_io_bio_set;
drivers/block/drbd/drbd_main.c +0 -13
@@ -138,19 +138,6 @@ static const struct block_device_operations drbd_ops = { .release = drbd_release, }; -struct bio *bio_alloc_drbd (gfp_t gfp_mask) -{ -struct bio *bio; - -if (!bioset_initialized (&drbd_md_io_bio_set)) -return bio_alloc (gfp_mask,1 ); - - bio =bio_alloc_bioset (gfp_mask,1 , &drbd_md_io_bio_set); -if (!bio) -return NULL ; -return bio; -} -#ifdef __CHECKER__/* When checking with sparse, and this is an inline function, sparse will give tons of false positives. When this is a real functions sparse works.
Signature · 1 line
2.29.2
Christoph Hellwig
maintainerPATCH 10/17 drbd: remove drbd_req_make_private_bio
In reply to Christoph HellwigOpen code drbd_req_make_private_bio in the two callers to prepare for further changes. Also don't bother to initialize bi_next as the bio code already does that that.
--- drivers/block/drbd/drbd_req.c | 5 ++++- drivers/block/drbd/drbd_req.h | 12 ------------ drivers/block/drbd/drbd_worker.c | 5 ++++- 3 files changed, 8 insertions(+), 14 deletions(-)
drivers/block/drbd/drbd_req.c +4 -1
@@ -30,7 +30,10 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, struct bioreturn NULL ;memset (req,0 ,sizeof (*req)); -drbd_req_make_private_bio (req, bio_src); + req->private_bio =bio_clone_fast (bio_src,GFP_NOIO , &drbd_io_bio_set); + req->private_bio->bi_private = req; + req->private_bio->bi_end_io = drbd_request_endio; + req->rq_state = (bio_data_dir (bio_src) ==WRITE ?RQ_WRITE :0 ) | (bio_op (bio_src) ==REQ_OP_WRITE_SAME ?RQ_WSAME :0 ) | (bio_op (bio_src) ==REQ_OP_WRITE_ZEROES ?RQ_ZEROES :0 )
drivers/block/drbd/drbd_req.h +0 -12
@@ -256,18 +256,6 @@ enum drbd_req_state_bits {#define MR_WRITE 1#define MR_READ 2 -static inline void drbd_req_make_private_bio (struct drbd_request *req,struct bio *bio_src) -{ -struct bio *bio; - bio =bio_clone_fast (bio_src,GFP_NOIO , &drbd_io_bio_set); - - req->private_bio = bio; - - bio->bi_private = req; - bio->bi_end_io = drbd_request_endio; - bio->bi_next =NULL ; -} -/* Short lived temporary struct on the stack. * We could squirrel the error to be returned into * bio->bi_iter.bi_size, or similar. But that would be too ugly. */
drivers/block/drbd/drbd_worker.c +4 -1
@@ -1523,8 +1523,11 @@ int w_restart_disk_io(struct drbd_work *w, int cancel)if (bio_data_dir (req->master_bio) ==WRITE && req->rq_state &RQ_IN_ACT_LOG )drbd_al_begin_io (device, &req->i); -drbd_req_make_private_bio (req, req->master_bio); + req->private_bio =bio_clone_fast (req->master_bio,GFP_NOIO , + &drbd_io_bio_set);bio_set_dev (req->private_bio, device->ldev->backing_bdev); + req->private_bio->bi_private = req; + req->private_bio->bi_end_io = drbd_request_endio;submit_bio_noacct (req->private_bio);return 0 ;
Signature · 1 line
2.29.2
Christoph Hellwig
maintainerPATCH 11/17 md: remove bio_alloc_mddev
In reply to Christoph Hellwigbio_alloc_mddev is never called with a NULL mddev, and ->bio_set is initialized in md_run, so it always must be initialized as well. Just open code the remaining call to bio_alloc_bioset.
--- drivers/md/md.c | 12 +----------- drivers/md/md.h | 2 -- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-)
drivers/md/md.c +1 -11
@@ -340,16 +340,6 @@ static int start_readonly;*/ static bool create_on_open = true; -struct bio *bio_alloc_mddev (gfp_t gfp_mask,int nr_iovecs, -struct mddev *mddev) -{ -if (!mddev || !bioset_initialized (&mddev->bio_set)) -return bio_alloc (gfp_mask, nr_iovecs); - -return bio_alloc_bioset (gfp_mask, nr_iovecs, &mddev->bio_set); -} -EXPORT_SYMBOL_GPL (bio_alloc_mddev); -static struct bio *md_bio_alloc_sync (struct mddev *mddev) {if (!mddev || !bioset_initialized (&mddev->sync_set))
@@ -613,7 +603,7 @@ static void submit_flushes(struct work_struct *ws)atomic_inc (&rdev->nr_pending);atomic_inc (&rdev->nr_pending);rcu_read_unlock (); - bi =bio_alloc_mddev (GFP_NOIO ,0 , mddev); + bi =bio_alloc_bioset (GFP_NOIO ,0 , &mddev->bio_set); bi->bi_end_io = md_end_flush; bi->bi_private = rdev;bio_set_dev (bi, rdev->bdev);
drivers/md/md.h +0 -2
@@ -742,8 +742,6 @@ extern void md_rdev_clear(struct md_rdev *rdev);extern void md_handle_request (struct mddev *mddev,struct bio *bio);extern void mddev_suspend (struct mddev *mddev);extern void mddev_resume (struct mddev *mddev); -extern struct bio *bio_alloc_mddev (gfp_t gfp_mask,int nr_iovecs, -struct mddev *mddev);extern void md_reload_sb (struct mddev *mddev,int raid_disk);extern void md_update_sb (struct mddev *mddev,int force);
drivers/md/raid1.c +1 -1
@@ -1104,7 +1104,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,int i =0 ;struct bio *behind_bio =NULL ; - behind_bio =bio_alloc_mddev (GFP_NOIO , vcnt, r1_bio->mddev); + behind_bio =bio_alloc_bioset (GFP_NOIO , vcnt, &r1_bio->mddev->bio_set);if (!behind_bio)return ;
drivers/md/raid10.c +1 -1
@@ -4531,7 +4531,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,return sectors_done; } - read_bio =bio_alloc_mddev (GFP_KERNEL ,RESYNC_PAGES , mddev); + read_bio =bio_alloc_bioset (GFP_KERNEL ,RESYNC_PAGES , &mddev->bio_set);bio_set_dev (read_bio, rdev->bdev); read_bio->bi_iter.bi_sector = (r10_bio->devs[r10_bio->read_slot].addr
Signature · 1 line
2.29.2
Re: [PATCH 11/17] md: remove bio_alloc_mddev
Quoted 6 lines · Christoph Hellwig
bio_alloc_mddevis never called with a NULL mddev, and ->bio_set is initialized inmd_run, so it always must be initialized as well. Just open code the remaining call tobio_alloc_bioset.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 79 lines
--- drivers/md/md.c | 12 +----------- drivers/md/md.h | 2 -- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-)drivers/md/md.c +1
-11@@ -340,16 +340,6 @@ static int start_readonly;*/ static bool create_on_open = true; -struct bio *bio_alloc_mddev (gfp_t gfp_mask,int nr_iovecs, -struct mddev *mddev) -{ -if (!mddev || !bioset_initialized (&mddev->bio_set)) -return bio_alloc (gfp_mask, nr_iovecs); - -return bio_alloc_bioset (gfp_mask, nr_iovecs, &mddev->bio_set); -} -EXPORT_SYMBOL_GPL (bio_alloc_mddev); -static struct bio *md_bio_alloc_sync (struct mddev *mddev) {if (!mddev || !bioset_initialized (&mddev->sync_set))@@ -613,7 +603,7 @@ static void submit_flushes(struct work_struct *ws)atomic_inc (&rdev->nr_pending);atomic_inc (&rdev->nr_pending);rcu_read_unlock (); - bi =bio_alloc_mddev (GFP_NOIO ,0 , mddev); + bi =bio_alloc_bioset (GFP_NOIO ,0 , &mddev->bio_set); bi->bi_end_io = md_end_flush; bi->bi_private = rdev;bio_set_dev (bi, rdev->bdev);drivers/md/md.h +0
-2@@ -742,8 +742,6 @@ extern void md_rdev_clear(struct md_rdev *rdev);extern void md_handle_request (struct mddev *mddev,struct bio *bio);extern void mddev_suspend (struct mddev *mddev);extern void mddev_resume (struct mddev *mddev); -extern struct bio *bio_alloc_mddev (gfp_t gfp_mask,int nr_iovecs, -struct mddev *mddev);extern void md_reload_sb (struct mddev *mddev,int raid_disk);extern void md_update_sb (struct mddev *mddev,int force);drivers/md/raid1.c +1
-1@@ -1104,7 +1104,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,int i =0 ;struct bio *behind_bio =NULL ; - behind_bio =bio_alloc_mddev (GFP_NOIO , vcnt, r1_bio->mddev); + behind_bio =bio_alloc_bioset (GFP_NOIO , vcnt, &r1_bio->mddev->bio_set);if (!behind_bio)return ;drivers/md/raid10.c +1
-2@@ -4531,7 +4531,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,return sectors_done; } - read_bio =bio_alloc_mddev (GFP_KERNEL ,RESYNC_PAGES , mddev); + read_bio =bio_alloc_bioset (GFP_KERNEL ,RESYNC_PAGES , &mddev->bio_set);bio_set_dev (read_bio, rdev->bdev); read_bio->bi_iter.bi_sector = (r10_bio->devs[r10_bio->read_slot].addr --2.29.2
Christoph Hellwig
maintainerPATCH 12/17 md: simplify sync_page_io
In reply to Christoph HellwigUse an on-stack bio and biovec for the single page synchronous I/O.
--- drivers/md/md.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/md/md.c +13 -13
@@ -1021,29 +1021,29 @@ int md_super_wait(struct mddev *mddev)int sync_page_io (struct md_rdev *rdev,sector_t sector,int size,struct page *page,int op,int op_flags,bool metadata_op) { -struct bio *bio =md_bio_alloc_sync (rdev->mddev); -int ret; +struct bio bio; +struct bio_vec bvec; + +bio_init (&bio, &bvec,1 );if (metadata_op && rdev->meta_bdev) -bio_set_dev (bio, rdev->meta_bdev); +bio_set_dev (&bio, rdev->meta_bdev);else -bio_set_dev (bio, rdev->bdev); -bio_set_op_attrs (bio, op, op_flags); +bio_set_dev (&bio, rdev->bdev); + bio.bi_opf = op | op_flags;if (metadata_op) - bio->bi_iter.bi_sector = sector + rdev->sb_start; + bio.bi_iter.bi_sector = sector + rdev->sb_start;else if (rdev->mddev->reshape_position != MaxSector && (rdev->mddev->reshape_backwards == (sector >= rdev->mddev->reshape_position))) - bio->bi_iter.bi_sector = sector + rdev->new_data_offset; + bio.bi_iter.bi_sector = sector + rdev->new_data_offset;else - bio->bi_iter.bi_sector = sector + rdev->data_offset; -bio_add_page (bio, page, size,0 ); + bio.bi_iter.bi_sector = sector + rdev->data_offset; +bio_add_page (&bio, page, size,0 ); -submit_bio_wait (bio); +submit_bio_wait (&bio); - ret = !bio->bi_status; -bio_put (bio); -return ret; +return !bio.bi_status; }EXPORT_SYMBOL_GPL (sync_page_io);
Signature · 1 line
2.29.2
Re: [PATCH 12/17] md: simplify sync_page_io
Quoted 4 lines · Christoph Hellwig
Use an on-stack bio and biovec for the single page synchronous I/O.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 54 lines
--- drivers/md/md.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)drivers/md/md.c +13
-14@@ -1021,29 +1021,29 @@ int md_super_wait(struct mddev *mddev)int sync_page_io (struct md_rdev *rdev,sector_t sector,int size,struct page *page,int op,int op_flags,bool metadata_op) { -struct bio *bio =md_bio_alloc_sync (rdev->mddev); -int ret; +struct bio bio; +struct bio_vec bvec; + +bio_init (&bio, &bvec,1 );if (metadata_op && rdev->meta_bdev) -bio_set_dev (bio, rdev->meta_bdev); +bio_set_dev (&bio, rdev->meta_bdev);else -bio_set_dev (bio, rdev->bdev); -bio_set_op_attrs (bio, op, op_flags); +bio_set_dev (&bio, rdev->bdev); + bio.bi_opf = op | op_flags;if (metadata_op) - bio->bi_iter.bi_sector = sector + rdev->sb_start; + bio.bi_iter.bi_sector = sector + rdev->sb_start;else if (rdev->mddev->reshape_position != MaxSector && (rdev->mddev->reshape_backwards == (sector >= rdev->mddev->reshape_position))) - bio->bi_iter.bi_sector = sector + rdev->new_data_offset; + bio.bi_iter.bi_sector = sector + rdev->new_data_offset;else - bio->bi_iter.bi_sector = sector + rdev->data_offset; -bio_add_page (bio, page, size,0 ); + bio.bi_iter.bi_sector = sector + rdev->data_offset; +bio_add_page (&bio, page, size,0 ); -submit_bio_wait (bio); +submit_bio_wait (&bio); - ret = !bio->bi_status; -bio_put (bio); -return ret; +return !bio.bi_status; }EXPORT_SYMBOL_GPL (sync_page_io); --2.29.2
Christoph Hellwig
maintainerPATCH 13/17 md: remove md_bio_alloc_sync
In reply to Christoph Hellwigmd_bio_alloc_sync is never called with a NULL mddev, and ->sync_set is initialized in md_run, so it always must be initialized as well. Just open code the remaining call to bio_alloc_bioset.
--- drivers/md/md.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/md/md.c +1 -9
@@ -340,14 +340,6 @@ static int start_readonly;*/ static bool create_on_open = true; -static struct bio *md_bio_alloc_sync (struct mddev *mddev) -{ -if (!mddev || !bioset_initialized (&mddev->sync_set)) -return bio_alloc (GFP_NOIO ,1 ); - -return bio_alloc_bioset (GFP_NOIO ,1 , &mddev->sync_set); -} -/* * We have a system wide 'event count' that is incremented * on any 'interesting' event, and readers of /proc/mdstat
@@ -989,7 +981,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,if (test_bit (Faulty, &rdev->flags))return ; - bio =md_bio_alloc_sync (mddev); + bio =bio_alloc_bioset (GFP_NOIO ,1 , &mddev->sync_set);atomic_inc (&rdev->nr_pending);
Signature · 1 line
2.29.2
Re: [PATCH 13/17] md: remove md_bio_alloc_sync
Quoted 6 lines · Christoph Hellwig
md_bio_alloc_syncis never called with a NULL mddev, and ->sync_set is initialized inmd_run, so it always must be initialized as well. Just open code the remaining call tobio_alloc_bioset.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 35 lines
--- drivers/md/md.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/md/md.c +1
-10@@ -340,14 +340,6 @@ static int start_readonly;*/ static bool create_on_open = true; -static struct bio *md_bio_alloc_sync (struct mddev *mddev) -{ -if (!mddev || !bioset_initialized (&mddev->sync_set)) -return bio_alloc (GFP_NOIO ,1 ); - -return bio_alloc_bioset (GFP_NOIO ,1 , &mddev->sync_set); -} -/* * We have a system wide 'event count' that is incremented * on any 'interesting' event, and readers of /proc/mdstat @@ -989,7 +981,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,if (test_bit (Faulty, &rdev->flags))return ; - bio =md_bio_alloc_sync (mddev); + bio =bio_alloc_bioset (GFP_NOIO ,1 , &mddev->sync_set);atomic_inc (&rdev->nr_pending); --2.29.2
Christoph Hellwig
maintainerPATCH 14/17 md/raid6: refactor raid5_read_one_chunk
In reply to Christoph HellwigRefactor raid5_read_one_chunk so that all simple checks are done before allocating the bio.
--- drivers/md/raid5.c | 108 +++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 63 deletions(-)
drivers/md/raid5.c +45 -63
@@ -5393,90 +5393,72 @@ static void raid5_align_endio(struct bio *bi)static int raid5_read_one_chunk (struct mddev *mddev,struct bio *raid_bio) {struct r5conf *conf = mddev->private; -int dd_idx; -struct bio * align_bi; +struct bio *align_bio;struct md_rdev *rdev; -sector_t end_sector; +sector_t sector, end_sector, first_bad; +int bad_sectors, dd_idx;if (!in_chunk_boundary (mddev, raid_bio)) {pr_debug ("%s: non aligned\n" , __func__);return 0 ; } -/* -* use bio_clone_fast to make a copy of the bio -*/ - align_bi =bio_clone_fast (raid_bio,GFP_NOIO , &mddev->bio_set); -if (!align_bi) -return 0 ; -/* -* set bi_end_io to a new function, and set bi_private to the -* original bio. -*/ - align_bi->bi_end_io = raid5_align_endio; - align_bi->bi_private = raid_bio; -/* -* compute position -*/ - align_bi->bi_iter.bi_sector = -raid5_compute_sector (conf, raid_bio->bi_iter.bi_sector, -0 , &dd_idx,NULL ); - end_sector =bio_end_sector (align_bi); + sector =raid5_compute_sector (conf, raid_bio->bi_iter.bi_sector,0 , + &dd_idx,NULL ); + end_sector =bio_end_sector (raid_bio); +rcu_read_lock (); +if (r5c_big_stripe_cached (conf, sector)) + goto out_rcu_unlock; + rdev =rcu_dereference (conf->disks[dd_idx].replacement);if (!rdev ||test_bit (Faulty, &rdev->flags) || rdev->recovery_offset < end_sector) { rdev =rcu_dereference (conf->disks[dd_idx].rdev); -if (rdev && - (test_bit (Faulty, &rdev->flags) || +if (!rdev) + goto out_rcu_unlock; +if (test_bit (Faulty, &rdev->flags) || !(test_bit (In_sync, &rdev->flags) || - rdev->recovery_offset >= end_sector))) - rdev =NULL ; + rdev->recovery_offset >= end_sector)) + goto out_rcu_unlock; } -if (r5c_big_stripe_cached (conf, align_bi->bi_iter.bi_sector)) { -rcu_read_unlock (); -bio_put (align_bi); +atomic_inc (&rdev->nr_pending); +rcu_read_unlock (); + + align_bio =bio_clone_fast (raid_bio,GFP_NOIO , &mddev->bio_set); +bio_set_dev (align_bio, rdev->bdev); + align_bio->bi_end_io = raid5_align_endio; + align_bio->bi_private = raid_bio; + align_bio->bi_iter.bi_sector = sector; + + raid_bio->bi_next = (void *)rdev; + +if (is_badblock (rdev, sector,bio_sectors (align_bio), &first_bad, + &bad_sectors)) { +bio_put (align_bio); +rdev_dec_pending (rdev, mddev);return 0 ; } -if (rdev) { -sector_t first_bad; -int bad_sectors; - -atomic_inc (&rdev->nr_pending); -rcu_read_unlock (); - raid_bio->bi_next = (void *)rdev; -bio_set_dev (align_bi, rdev->bdev); - -if (is_badblock (rdev, align_bi->bi_iter.bi_sector, -bio_sectors (align_bi), - &first_bad, &bad_sectors)) { -bio_put (align_bi); -rdev_dec_pending (rdev, mddev); -return 0 ; - } +/* No reshape active, so we can trust rdev->data_offset */ + align_bio->bi_iter.bi_sector += rdev->data_offset; -/* No reshape active, so we can trust rdev->data_offset */ - align_bi->bi_iter.bi_sector += rdev->data_offset; +spin_lock_irq (&conf->device_lock); +wait_event_lock_irq (conf->wait_for_quiescent, conf->quiesce ==0 , + conf->device_lock); +atomic_inc (&conf->active_aligned_reads); +spin_unlock_irq (&conf->device_lock); -spin_lock_irq (&conf->device_lock); -wait_event_lock_irq (conf->wait_for_quiescent, - conf->quiesce ==0 , - conf->device_lock); -atomic_inc (&conf->active_aligned_reads); -spin_unlock_irq (&conf->device_lock); +if (mddev->gendisk) +trace_block_bio_remap (align_bio,disk_devt (mddev->gendisk), + raid_bio->bi_iter.bi_sector); +submit_bio_noacct (align_bio); +return 1 ; -if (mddev->gendisk) -trace_block_bio_remap (align_bi,disk_devt (mddev->gendisk), - raid_bio->bi_iter.bi_sector); -submit_bio_noacct (align_bi); -return 1 ; - }else { -rcu_read_unlock (); -bio_put (align_bi); -return 0 ; - } +out_rcu_unlock: +rcu_read_unlock (); +return 0 ; }static struct bio *chunk_aligned_read (struct mddev *mddev,struct bio *raid_bio)
Signature · 1 line
2.29.2
Re: [PATCH 14/17] md/raid6: refactor raid5_read_one_chunk
Quoted 5 lines · Christoph Hellwig
Refactor
raid5_read_one_chunkso that all simple checks are done before allocating the bio.Signed-off-by Christoph Hellwig <[email protected]>
Thanks for the clean-up!
Quoted 147 lines
--- drivers/md/raid5.c | 108 +++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 63 deletions(-)drivers/md/raid5.c +45
-64@@ -5393,90 +5393,72 @@ static void raid5_align_endio(struct bio *bi)static int raid5_read_one_chunk (struct mddev *mddev,struct bio *raid_bio) {struct r5conf *conf = mddev->private; -int dd_idx; -struct bio * align_bi; +struct bio *align_bio;struct md_rdev *rdev; -sector_t end_sector; +sector_t sector, end_sector, first_bad; +int bad_sectors, dd_idx;if (!in_chunk_boundary (mddev, raid_bio)) {pr_debug ("%s: non aligned\n" , __func__);return 0 ; } -/* -* use bio_clone_fast to make a copy of the bio -*/ - align_bi =bio_clone_fast (raid_bio,GFP_NOIO , &mddev->bio_set); -if (!align_bi) -return 0 ; -/* -* set bi_end_io to a new function, and set bi_private to the -* original bio. -*/ - align_bi->bi_end_io = raid5_align_endio; - align_bi->bi_private = raid_bio; -/* -* compute position -*/ - align_bi->bi_iter.bi_sector = -raid5_compute_sector (conf, raid_bio->bi_iter.bi_sector, -0 , &dd_idx,NULL ); - end_sector =bio_end_sector (align_bi); + sector =raid5_compute_sector (conf, raid_bio->bi_iter.bi_sector,0 , + &dd_idx,NULL ); + end_sector =bio_end_sector (raid_bio); +rcu_read_lock (); +if (r5c_big_stripe_cached (conf, sector)) + goto out_rcu_unlock; + rdev =rcu_dereference (conf->disks[dd_idx].replacement);if (!rdev ||test_bit (Faulty, &rdev->flags) || rdev->recovery_offset < end_sector) { rdev =rcu_dereference (conf->disks[dd_idx].rdev); -if (rdev && - (test_bit (Faulty, &rdev->flags) || +if (!rdev) + goto out_rcu_unlock; +if (test_bit (Faulty, &rdev->flags) || !(test_bit (In_sync, &rdev->flags) || - rdev->recovery_offset >= end_sector))) - rdev =NULL ; + rdev->recovery_offset >= end_sector)) + goto out_rcu_unlock; } -if (r5c_big_stripe_cached (conf, align_bi->bi_iter.bi_sector)) { -rcu_read_unlock (); -bio_put (align_bi); +atomic_inc (&rdev->nr_pending); +rcu_read_unlock (); + + align_bio =bio_clone_fast (raid_bio,GFP_NOIO , &mddev->bio_set); +bio_set_dev (align_bio, rdev->bdev); + align_bio->bi_end_io = raid5_align_endio; + align_bio->bi_private = raid_bio; + align_bio->bi_iter.bi_sector = sector; + + raid_bio->bi_next = (void *)rdev; + +if (is_badblock (rdev, sector,bio_sectors (align_bio), &first_bad, + &bad_sectors)) { +bio_put (align_bio); +rdev_dec_pending (rdev, mddev);return 0 ; } -if (rdev) { -sector_t first_bad; -int bad_sectors; - -atomic_inc (&rdev->nr_pending); -rcu_read_unlock (); - raid_bio->bi_next = (void *)rdev; -bio_set_dev (align_bi, rdev->bdev); - -if (is_badblock (rdev, align_bi->bi_iter.bi_sector, -bio_sectors (align_bi), - &first_bad, &bad_sectors)) { -bio_put (align_bi); -rdev_dec_pending (rdev, mddev); -return 0 ; - } +/* No reshape active, so we can trust rdev->data_offset */ + align_bio->bi_iter.bi_sector += rdev->data_offset; -/* No reshape active, so we can trust rdev->data_offset */ - align_bi->bi_iter.bi_sector += rdev->data_offset; +spin_lock_irq (&conf->device_lock); +wait_event_lock_irq (conf->wait_for_quiescent, conf->quiesce ==0 , + conf->device_lock); +atomic_inc (&conf->active_aligned_reads); +spin_unlock_irq (&conf->device_lock); -spin_lock_irq (&conf->device_lock); -wait_event_lock_irq (conf->wait_for_quiescent, - conf->quiesce ==0 , - conf->device_lock); -atomic_inc (&conf->active_aligned_reads); -spin_unlock_irq (&conf->device_lock); +if (mddev->gendisk) +trace_block_bio_remap (align_bio,disk_devt (mddev->gendisk), + raid_bio->bi_iter.bi_sector); +submit_bio_noacct (align_bio); +return 1 ; -if (mddev->gendisk) -trace_block_bio_remap (align_bi,disk_devt (mddev->gendisk), - raid_bio->bi_iter.bi_sector); -submit_bio_noacct (align_bi); -return 1 ; - }else { -rcu_read_unlock (); -bio_put (align_bi); -return 0 ; - } +out_rcu_unlock: +rcu_read_unlock (); +return 0 ; }static struct bio *chunk_aligned_read (struct mddev *mddev,struct bio *raid_bio) --2.29.2
Christoph Hellwig
maintainerPATCH 15/17 nfs/blocklayout: remove cruft in bl_alloc_init_bio
In reply to Christoph Hellwigbio_alloc never returns NULL when it can sleep.
--- fs/nfs/blocklayout/blocklayout.c | 5 ----- 1 file changed, 5 deletions(-)
fs/nfs/blocklayout/blocklayout.c +0 -5
@@ -123,11 +123,6 @@ bl_alloc_init_bio(int npg, struct block_device *bdev, sector_t disk_sector, npg =min (npg,BIO_MAX_PAGES ); bio =bio_alloc (GFP_NOIO , npg); -if (!bio && (current->flags &PF_MEMALLOC )) { -while (!bio && (npg /=2 )) - bio =bio_alloc (GFP_NOIO , npg); - } -if (bio) { bio->bi_iter.bi_sector = disk_sector;bio_set_dev (bio, bdev);
Signature · 1 line
2.29.2
Christoph Hellwig
maintainerPATCH 16/17 nilfs2: remove cruft in nilfs_alloc_seg_bio
In reply to Christoph Hellwigbio_alloc never returns NULL when it can sleep.
--- fs/nilfs2/segbuf.c | 4 ---- 1 file changed, 4 deletions(-)
fs/nilfs2/segbuf.c +0 -4
@@ -386,10 +386,6 @@ static struct bio *nilfs_alloc_seg_bio(struct the_nilfs *nilfs, sector_t start,struct bio *bio; bio =bio_alloc (GFP_NOIO , nr_vecs); -if (bio ==NULL ) { -while (!bio && (nr_vecs >>=1 )) - bio =bio_alloc (GFP_NOIO , nr_vecs); - }if (likely (bio)) {bio_set_dev (bio, nilfs->ns_bdev); bio->bi_iter.bi_sector =
Signature · 1 line
2.29.2
Re: [PATCH 16/17] nilfs2: remove cruft in nilfs_alloc_seg_bio
Quoted 4 lines · Christoph Hellwig
bio_allocnever returns NULL when it can sleep.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good.
Christoph Hellwig
maintainerPATCH 17/17 mm: remove get_swap_bio
In reply to Christoph HellwigJust reuse the block_device and sector from the swap_info structure, just as used by the SWP_SYNCHRONOUS path. Also remove the checks for NULL returns from bio_alloc as that can't happen for sleeping allocations.
--- include/linux/swap.h | 1 - mm/page_io.c | 45 +++++++++++++------------------------------- mm/swapfile.c | 10 ---------- 3 files changed, 13 insertions(+), 43 deletions(-)
include/linux/swap.h +0 -1
@@ -468,7 +468,6 @@ extern int free_swap_and_cache(swp_entry_t);int swap_type_of (dev_t device,sector_t offset);int find_first_swap (dev_t *device);extern unsigned int count_swap_pages (int ,int ); -extern sector_t map_swap_page (struct page *,struct block_device **);extern sector_t swapdev_block (int ,pgoff_t );extern int page_swapcount (struct page *);extern int __swap_count (swp_entry_t entry);
mm/page_io.c +13 -32
69 lines not on this page · raw message
mm/swapfile.c +0 -10
@@ -2301,16 +2301,6 @@ static sector_t map_swap_entry(swp_entry_t entry, struct block_device **bdev)return se->start_block + (offset - se->start_page); } -/* -* Returns the page offset into bdev for the specified page's swap entry. -*/ -sector_t map_swap_page (struct page *page,struct block_device **bdev) -{ -swp_entry_t entry; - entry.val =page_private (page); -return map_swap_entry (entry, bdev); -} -/* * Free all of a swapdev's extent information */
Signature · 1 line
2.29.2
Quoted 4 lines · Christoph Hellwig
Hi Jens,
this series contains various cleanups for how bios are allocated or initialized plus related fallout.
Applied, thanks.
Signature · 1 line
Jens Axboe
Hi Christoph,
I tried with latest for-5.12/block branch, and got below issue when trying to create raid1 array.
[ 80.605832] BUG: kernel NULL pointer dereference, address: 0000000000000018 [ 80.606159] #PF: supervisor read access in kernel mode [ 80.606159] #PF: error_code(0x0000) - not-present page [ 80.606159] PGD 0 P4D 0 [ 80.606159] Oops: 0000 [#1] SMP NOPTI [ 80.606159] CPU: 1 PID: 207 Comm: mdadm Not tainted 5.11.0-rc5+ #37 [ 80.606159] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 [ 80.606159] RIP: 0010:bdev_read_only+0x0/0x30 [ 80.606159] Code: 89 df 5b 5d e9 71 21 e7 ff 81 e6 ff ff 0f 00 48 c7 c7 40 99 d9 9e e8 0f e5 04 00 eb a0 0f 1f 00 66 2e 0f 1f 84 00 00 00 00 00 <80> 7f 18 00 b8 01 00 00 00 75 11 48 8b 97 60 03 00 00 48 8b 4a 40 [ 80.606159] RSP: 0018:ffffb14f405dfd38 EFLAGS: 00000246 [ 80.606159] RAX: 0000000000000000 RBX: ffff9b0e0863b018 RCX: ffff9b0e01edc000 [ 80.606159] RDX: ffff9b0e01b54c00 RSI: ffff9b0e0863b000 RDI: 0000000000000000 [ 80.606159] RBP: ffff9b0e01272200 R08: 0000000000000000 R09: 0000000000000000 [ 80.606159] R10: ffffee978004da40 R11: 0000000000000cc0 R12: ffff9b0e0863b000 [ 80.606159] R13: ffff9b0e01f2cc00 R14: ffff9b0e0863b000 R15: 0000000000000000 [ 80.606159] FS: 00007f522ec65740(0000) GS:ffff9b0e7bc80000(0000) knlGS:0000000000000000 [ 80.606159] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 80.606159] CR2: 0000000000000018 CR3: 0000000001364000 CR4: 00000000000006e0 [ 80.606159] Call Trace: [ 80.606159] bind_rdev_to_array+0x2f7/0x380 [ 80.606159] ? cred_has_capability+0x80/0x120 [ 80.606159] md_add_new_disk+0x204/0x630 [ 80.606159] ? security_capable+0x33/0x50 [ 80.606159] md_ioctl+0xee7/0x1690 [ 80.606159] ? selinux_file_ioctl+0x143/0x200 [ 80.606159] blkdev_ioctl+0x1ff/0x240 [ 80.606159] block_ioctl+0x34/0x40 [ 80.606159] __x64_sys_ioctl+0x89/0xc0 [ 80.606159] do_syscall_64+0x33/0x40 [ 80.606159] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 80.606159] RIP: 0033:0x7f522e564317 [ 80.606159] Code: b3 66 90 48 8b 05 71 4b 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 41 4b 2d 00 f7 d8 64 89 01 48 [ 80.606159] RSP: 002b:00007ffc3abd96f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 80.606159] RAX: ffffffffffffffda RBX: 00005653ee690350 RCX: 00007f522e564317 [ 80.606159] RDX: 00005653ee694058 RSI: 0000000040140921 RDI: 0000000000000004 [ 80.606159] RBP: 00005653ee690410 R08: 00007f522e839db0 R09: 0000000000000000 [ 80.606159] R10: 00005653ee690010 R11: 0000000000000246 R12: 0000000000000000 [ 80.606159] R13: 0000000000000000 R14: 0000000000000000 R15: 00005653ee694010 [ 80.606159] Modules linked in: [ 80.606159] CR2: 0000000000000018 [ 80.622996] ---[ end trace 22144b856a3c1001 ]--- [ 80.623285] RIP: 0010:bdev_read_only+0x0/0x30 [ 80.623501] Code: 89 df 5b 5d e9 71 21 e7 ff 81 e6 ff ff 0f 00 48 c7 c7 40 99 d9 9e e8 0f e5 04 00 eb a0 0f 1f 00 66 2e 0f 1f 84 00 00 00 00 00 <80> 7f 18 00 b8 01 00 00 00 75 11 48 8b 97 60 03 00 00 48 8b 4a 40 [ 80.624544] RSP: 0018:ffffb14f405dfd38 EFLAGS: 00000246 [ 80.624788] RAX: 0000000000000000 RBX: ffff9b0e0863b018 RCX: ffff9b0e01edc000 [ 80.625136] RDX: ffff9b0e01b54c00 RSI: ffff9b0e0863b000 RDI: 0000000000000000 [ 80.625449] RBP: ffff9b0e01272200 R08: 0000000000000000 R09: 0000000000000000 [ 80.625761] R10: ffffee978004da40 R11: 0000000000000cc0 R12: ffff9b0e0863b000 [ 80.626112] R13: ffff9b0e01f2cc00 R14: ffff9b0e0863b000 R15: 0000000000000000 [ 80.626429] FS: 00007f522ec65740(0000) GS:ffff9b0e7bc80000(0000) knlGS:0000000000000000 [ 80.626784] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 80.627035] CR2: 0000000000000018 CR3: 0000000001364000 CR4: 00000000000006e0
Killed
Thanks,
Guoqing