1 ext4: move LRU list handling into extent status code
3 From: Jan Kara <jack@suse.cz>
5 Currently callers adding extents to extent status tree were responsible
6 for adding the inode to LRU list. This is error prone and puts LRU list
7 handling in unnecessarily many places.
9 Just add inode to LRU automatically when the first non-delay extent is
10 added to the tree and remove inode from LRU when the last non-delay
13 Signed-off-by: Jan Kara <jack@suse.cz>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 fs/ext4/extents.c | 2 --
17 fs/ext4/extents_status.c | 12 ++++++++----
18 fs/ext4/extents_status.h | 2 --
19 fs/ext4/inode.c | 2 --
20 fs/ext4/ioctl.c | 2 --
22 6 files changed, 8 insertions(+), 13 deletions(-)
24 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
25 index c29cec0..bcb0e4a 100644
26 --- a/fs/ext4/extents.c
27 +++ b/fs/ext4/extents.c
28 @@ -4621,7 +4621,6 @@ out2:
30 trace_ext4_ext_map_blocks_exit(inode, flags, map,
31 err ? err : allocated);
32 - ext4_es_lru_add(inode);
33 return err ? err : allocated;
36 @@ -5180,7 +5179,6 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
37 error = ext4_fill_fiemap_extents(inode, start_blk,
40 - ext4_es_lru_add(inode);
44 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
45 index 94e7855..dba77c7 100644
46 --- a/fs/ext4/extents_status.c
47 +++ b/fs/ext4/extents_status.c
48 @@ -151,6 +151,8 @@ static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei,
50 static int __ext4_es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
51 struct ext4_inode_info *locked_ei);
52 +static void ext4_es_lru_add(struct inode *inode);
53 +static void ext4_es_lru_del(struct inode *inode);
55 int __init ext4_init_es(void)
57 @@ -314,7 +316,8 @@ ext4_es_alloc_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len,
58 * We don't count delayed extent because we never try to reclaim them
60 if (!ext4_es_is_delayed(es)) {
61 - EXT4_I(inode)->i_es_lru_nr++;
62 + if (!EXT4_I(inode)->i_es_lru_nr++)
63 + ext4_es_lru_add(inode);
64 percpu_counter_inc(&EXT4_SB(inode->i_sb)->
65 s_es_stats.es_stats_lru_cnt);
67 @@ -333,7 +336,8 @@ static void ext4_es_free_extent(struct inode *inode, struct extent_status *es)
68 /* Decrease the lru counter when this es is not delayed */
69 if (!ext4_es_is_delayed(es)) {
70 BUG_ON(EXT4_I(inode)->i_es_lru_nr == 0);
71 - EXT4_I(inode)->i_es_lru_nr--;
72 + if (!--EXT4_I(inode)->i_es_lru_nr)
73 + ext4_es_lru_del(inode);
74 percpu_counter_dec(&EXT4_SB(inode->i_sb)->
75 s_es_stats.es_stats_lru_cnt);
77 @@ -1225,7 +1229,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
78 unregister_shrinker(&sbi->s_es_shrinker);
81 -void ext4_es_lru_add(struct inode *inode)
82 +static void ext4_es_lru_add(struct inode *inode)
84 struct ext4_inode_info *ei = EXT4_I(inode);
85 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
86 @@ -1241,7 +1245,7 @@ void ext4_es_lru_add(struct inode *inode)
87 spin_unlock(&sbi->s_es_lru_lock);
90 -void ext4_es_lru_del(struct inode *inode)
91 +static void ext4_es_lru_del(struct inode *inode)
93 struct ext4_inode_info *ei = EXT4_I(inode);
94 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
95 diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
96 index efd5f97..9b5e761 100644
97 --- a/fs/ext4/extents_status.h
98 +++ b/fs/ext4/extents_status.h
99 @@ -151,7 +151,5 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
101 extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
102 extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
103 -extern void ext4_es_lru_add(struct inode *inode);
104 -extern void ext4_es_lru_del(struct inode *inode);
106 #endif /* _EXT4_EXTENTS_STATUS_H */
107 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
108 index e2d7547..8396ace 100644
109 --- a/fs/ext4/inode.c
110 +++ b/fs/ext4/inode.c
111 @@ -491,7 +491,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
113 /* Lookup extent status tree firstly */
114 if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) {
115 - ext4_es_lru_add(inode);
116 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) {
117 map->m_pblk = ext4_es_pblock(&es) +
118 map->m_lblk - es.es_lblk;
119 @@ -1393,7 +1392,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
121 /* Lookup extent status tree firstly */
122 if (ext4_es_lookup_extent(inode, iblock, &es)) {
123 - ext4_es_lru_add(inode);
124 if (ext4_es_is_hole(&es)) {
126 down_read(&EXT4_I(inode)->i_data_sem);
127 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
128 index bfda18a..f58a0d1 100644
129 --- a/fs/ext4/ioctl.c
130 +++ b/fs/ext4/ioctl.c
131 @@ -78,8 +78,6 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
132 memswap(&ei1->i_disksize, &ei2->i_disksize, sizeof(ei1->i_disksize));
133 ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
134 ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
135 - ext4_es_lru_del(inode1);
136 - ext4_es_lru_del(inode2);
138 isize = i_size_read(inode1);
139 i_size_write(inode1, i_size_read(inode2));
140 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
141 index 1ac1914..7dafd6b 100644
142 --- a/fs/ext4/super.c
143 +++ b/fs/ext4/super.c
144 @@ -963,7 +963,6 @@ void ext4_clear_inode(struct inode *inode)
146 ext4_discard_preallocations(inode);
147 ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
148 - ext4_es_lru_del(inode);
149 if (EXT4_I(inode)->jinode) {
150 jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode),
151 EXT4_I(inode)->jinode);