]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.172/f2fs-avoid-unneeded-loop-in-build_sit_entries.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.172 / f2fs-avoid-unneeded-loop-in-build_sit_entries.patch
1 From foo@baz Fri Jan 18 09:16:11 CET 2019
2 From: Chao Yu <yuchao0@huawei.com>
3 Date: Fri, 19 Aug 2016 23:13:47 +0800
4 Subject: f2fs: avoid unneeded loop in build_sit_entries
5
6 From: Chao Yu <yuchao0@huawei.com>
7
8 commit d600af236da51d9e3b90d21a23f95b820bd02e2f upstream.
9
10 When building each sit entry in cache, firstly, we will load it from
11 sit page, and then check all entries in sit journal, if there is one
12 updated entry in journal, cover cached entry with the journaled one.
13
14 Actually, most of check operation is unneeded since we only need
15 to update cached entries with journaled entries in batch, so
16 changing the flow as below for more efficient:
17 1. load all sit entries into cache from sit pages;
18 2. update sit entries with journal.
19
20 Signed-off-by: Chao Yu <yuchao0@huawei.com>
21 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
22 [bwh: Backported to 4.4:
23 - Keep using curseg->curseg_mutex for serialisation
24 - Use sum instead of journal
25 - Don't add f2fs_discard_en() condition]
26 Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 fs/f2fs/segment.c | 44 ++++++++++++++++++++++++++++----------------
30 1 file changed, 28 insertions(+), 16 deletions(-)
31
32 --- a/fs/f2fs/segment.c
33 +++ b/fs/f2fs/segment.c
34 @@ -2145,22 +2145,11 @@ static void build_sit_entries(struct f2f
35 struct f2fs_sit_entry sit;
36 struct page *page;
37
38 - mutex_lock(&curseg->curseg_mutex);
39 - for (i = 0; i < sits_in_cursum(sum); i++) {
40 - if (le32_to_cpu(segno_in_journal(sum, i))
41 - == start) {
42 - sit = sit_in_journal(sum, i);
43 - mutex_unlock(&curseg->curseg_mutex);
44 - goto got_it;
45 - }
46 - }
47 - mutex_unlock(&curseg->curseg_mutex);
48 -
49 page = get_current_sit_page(sbi, start);
50 sit_blk = (struct f2fs_sit_block *)page_address(page);
51 sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)];
52 f2fs_put_page(page, 1);
53 -got_it:
54 +
55 check_block_count(sbi, start, &sit);
56 seg_info_from_raw_sit(se, &sit);
57
58 @@ -2168,13 +2157,36 @@ got_it:
59 memcpy(se->discard_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
60 sbi->discard_blks += sbi->blocks_per_seg - se->valid_blocks;
61
62 - if (sbi->segs_per_sec > 1) {
63 - struct sec_entry *e = get_sec_entry(sbi, start);
64 - e->valid_blocks += se->valid_blocks;
65 - }
66 + if (sbi->segs_per_sec > 1)
67 + get_sec_entry(sbi, start)->valid_blocks +=
68 + se->valid_blocks;
69 }
70 start_blk += readed;
71 } while (start_blk < sit_blk_cnt);
72 +
73 + mutex_lock(&curseg->curseg_mutex);
74 + for (i = 0; i < sits_in_cursum(sum); i++) {
75 + struct f2fs_sit_entry sit;
76 + struct seg_entry *se;
77 + unsigned int old_valid_blocks;
78 +
79 + start = le32_to_cpu(segno_in_journal(sum, i));
80 + se = &sit_i->sentries[start];
81 + sit = sit_in_journal(sum, i);
82 +
83 + old_valid_blocks = se->valid_blocks;
84 +
85 + check_block_count(sbi, start, &sit);
86 + seg_info_from_raw_sit(se, &sit);
87 +
88 + memcpy(se->discard_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
89 + sbi->discard_blks += old_valid_blocks - se->valid_blocks;
90 +
91 + if (sbi->segs_per_sec > 1)
92 + get_sec_entry(sbi, start)->valid_blocks +=
93 + se->valid_blocks - old_valid_blocks;
94 + }
95 + mutex_unlock(&curseg->curseg_mutex);
96 }
97
98 static void init_free_segmap(struct f2fs_sb_info *sbi)