add patch fix-compile-warning-when-using-JBUFFER_TRACE
[ext4-patch-queue.git] / unlock-unused-pages-more-timely-when-doing-writeback
bloba2fb20ddb139c7eb9dfb73d6f962eed37092fa98
1 ext4: unlock unused_pages timely when doing writeback
3 From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
5 In mpage_add_bh_to_extent(), when accumulated extents length is greater
6 than MAX_WRITEPAGES_EXTENT_LEN or buffer head's b_stat is not equal, we
7 will not continue to search unmapped area for this page, but note this
8 page is locked, and will only be unlocked in mpage_release_unused_pages()
9 after ext4_io_submit, if io also is throttled by blk-throttle or similar
10 io qos, we will hold this page locked for a while, it's unnecessary.
12 I think the best fix is to refactor mpage_add_bh_to_extent() to let it
13 return some hints whether to unlock this page, but given that we will
14 improve dioread_nolock later, we can let it done later, so currently
15 the simple fix would just call mpage_release_unused_pages() before
16 ext4_io_submit().
18 Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
19 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 ---
21  fs/ext4/inode.c | 9 +++++----
22  1 file changed, 5 insertions(+), 4 deletions(-)
24 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
25 index 34d7e0703cc6..83a0d7c76736 100644
26 --- a/fs/ext4/inode.c
27 +++ b/fs/ext4/inode.c
28 @@ -2836,12 +2836,12 @@ static int ext4_writepages(struct address_space *mapping,
29                 goto unplug;
30         }
31         ret = mpage_prepare_extent_to_map(&mpd);
32 +       /* Unlock pages we didn't use */
33 +       mpage_release_unused_pages(&mpd, false);
34         /* Submit prepared bio */
35         ext4_io_submit(&mpd.io_submit);
36         ext4_put_io_end_defer(mpd.io_submit.io_end);
37         mpd.io_submit.io_end = NULL;
38 -       /* Unlock pages we didn't use */
39 -       mpage_release_unused_pages(&mpd, false);
40         if (ret < 0)
41                 goto unplug;
43 @@ -2909,10 +2909,11 @@ static int ext4_writepages(struct address_space *mapping,
44                         handle = NULL;
45                         mpd.do_map = 0;
46                 }
47 -               /* Submit prepared bio */
48 -               ext4_io_submit(&mpd.io_submit);
49                 /* Unlock pages we didn't use */
50                 mpage_release_unused_pages(&mpd, give_up_on_write);
51 +               /* Submit prepared bio */
52 +               ext4_io_submit(&mpd.io_submit);
54                 /*
55                  * Drop our io_end reference we got from init. We have
56                  * to be careful and use deferred io_end finishing if
57 -- 
58 2.17.2