]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.32.17/0038-ext4-don-t-scan-accumulate-more-pages-than-mballoc-w.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.32.17 / 0038-ext4-don-t-scan-accumulate-more-pages-than-mballoc-w.patch
1 From 2f4283aff3e5415fa36cbf81aa2a6247bfbb0527 Mon Sep 17 00:00:00 2001
2 From: Eric Sandeen <sandeen@redhat.com>
3 Date: Sun, 30 May 2010 22:49:52 -0400
4 Subject: ext4: don't scan/accumulate more pages than mballoc will allocate
5
6 commit c445e3e0a5c2804524dec6e55f66d63f6bc5bc3e upstream (as of v2.6.34-git13)
7
8 There was a bug reported on RHEL5 that a 10G dd on a 12G box
9 had a very, very slow sync after that.
10
11 At issue was the loop in write_cache_pages scanning all the way
12 to the end of the 10G file, even though the subsequent call
13 to mpage_da_submit_io would only actually write a smallish amt; then
14 we went back to the write_cache_pages loop ... wasting tons of time
15 in calling __mpage_da_writepage for thousands of pages we would
16 just revisit (many times) later.
17
18 Upstream it's not such a big issue for sys_sync because we get
19 to the loop with a much smaller nr_to_write, which limits the loop.
20
21 However, talking with Aneesh he realized that fsync upstream still
22 gets here with a very large nr_to_write and we face the same problem.
23
24 This patch makes mpage_add_bh_to_extent stop the loop after we've
25 accumulated 2048 pages, by setting mpd->io_done = 1; which ultimately
26 causes the write_cache_pages loop to break.
27
28 Repeating the test with a dirty_ratio of 80 (to leave something for
29 fsync to do), I don't see huge IO performance gains, but the reduction
30 in cpu usage is striking: 80% usage with stock, and 2% with the
31 below patch. Instrumenting the loop in write_cache_pages clearly
32 shows that we are wasting time here.
33
34 Eventually we need to change mpage_da_map_pages() also submit its I/O
35 to the block layer, subsuming mpage_da_submit_io(), and then change it
36 call ext4_get_blocks() multiple times.
37
38 Signed-off-by: Eric Sandeen <sandeen@redhat.com>
39 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
40 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
41 ---
42 fs/ext4/inode.c | 9 +++++++++
43 1 file changed, 9 insertions(+)
44
45 --- a/fs/ext4/inode.c
46 +++ b/fs/ext4/inode.c
47 @@ -2361,6 +2361,15 @@ static void mpage_add_bh_to_extent(struc
48 sector_t next;
49 int nrblocks = mpd->b_size >> mpd->inode->i_blkbits;
50
51 + /*
52 + * XXX Don't go larger than mballoc is willing to allocate
53 + * This is a stopgap solution. We eventually need to fold
54 + * mpage_da_submit_io() into this function and then call
55 + * ext4_get_blocks() multiple times in a loop
56 + */
57 + if (nrblocks >= 8*1024*1024/mpd->inode->i_sb->s_blocksize)
58 + goto flush_it;
59 +
60 /* check if thereserved journal credits might overflow */
61 if (!(EXT4_I(mpd->inode)->i_flags & EXT4_EXTENTS_FL)) {
62 if (nrblocks >= EXT4_MAX_TRANS_DATA) {