Add Jan Kara's "avoid unnecessary transaction stalls during writeback"
[ext4-patch-queue.git] / allow-io-submission-without-io_end
blob2c9c1cfc901463303bf915d6e09f21d39c173fb4
1 ext4: allow IO submission without io_end
3 From: Jan Kara <jack@suse.cz>
5 Allow submission of bio through ext4_bio_write_page() without io_end.
6 For the case where we are not converting unwritten extents we don't need
7 io_end for anything anyway.
9 Signed-off-by: Jan Kara <jack@suse.cz>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/page-io.c | 18 +++++++++---------
13  1 file changed, 9 insertions(+), 9 deletions(-)
15 diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
16 index 208241b06662..a8a6caf4752a 100644
17 --- a/fs/ext4/page-io.c
18 +++ b/fs/ext4/page-io.c
19 @@ -298,23 +298,20 @@ static void ext4_end_bio(struct bio *bio)
20         ext4_io_end_t *io_end = bio->bi_private;
21         sector_t bi_sector = bio->bi_iter.bi_sector;
23 -       BUG_ON(!io_end);
24         bio->bi_end_io = NULL;
26         if (bio->bi_error) {
27                 struct inode *inode = io_end->inode;
29                 ext4_warning(inode->i_sb, "I/O error %d writing to inode %lu "
30 -                            "(offset %llu size %ld starting block %llu)",
31 +                            "(starting block %llu)",
32                              bio->bi_error, inode->i_ino,
33 -                            (unsigned long long) io_end->offset,
34 -                            (long) io_end->size,
35                              (unsigned long long)
36                              bi_sector >> (inode->i_blkbits - 9));
37                 mapping_set_error(inode->i_mapping, bio->bi_error);
38         }
40 -       if (io_end->flag & EXT4_IO_END_UNWRITTEN) {
41 +       if (io_end && io_end->flag & EXT4_IO_END_UNWRITTEN) {
42                 /*
43                  * Link bio into list hanging from io_end. We have to do it
44                  * atomically as bio completions can be racing against each
45 @@ -322,15 +319,17 @@ static void ext4_end_bio(struct bio *bio)
46                  */
47                 bio->bi_private = xchg(&io_end->bio, bio);
48                 ext4_put_io_end_defer(io_end);
49 -       } else {
50 +               return;
51 +       }
52 +       if (io_end) {
53                 /*
54                  * Drop io_end reference early. Inode can get freed once
55                  * we finish the bio.
56                  */
57                 ext4_put_io_end_defer(io_end);
58 -               ext4_finish_bio(bio);
59 -               bio_put(bio);
60         }
61 +       ext4_finish_bio(bio);
62 +       bio_put(bio);
63  }
65  void ext4_io_submit(struct ext4_io_submit *io)
66 @@ -366,7 +365,8 @@ static int io_submit_init_bio(struct ext4_io_submit *io,
67         bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
68         bio->bi_bdev = bh->b_bdev;
69         bio->bi_end_io = ext4_end_bio;
70 -       bio->bi_private = ext4_get_io_end(io->io_end);
71 +       if (io->io_end)
72 +               bio->bi_private = ext4_get_io_end(io->io_end);
73         io->io_bio = bio;
74         io->io_next_block = bh->b_blocknr;
75         return 0;
76 -- 
77 2.12.0