1 ext4: move handling of list of shrinkable inodes 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 the list of inodes with freeable extents. This
7 is error prone and puts list handling in unnecessarily many places.
9 Just add inode to the list automatically when the first non-delay extent
10 is added to the tree and remove inode from the list when the last
11 non-delay extent is removed.
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 | 10 ++++++----
18 fs/ext4/extents_status.h | 2 --
19 fs/ext4/inode.c | 2 --
20 fs/ext4/ioctl.c | 2 --
22 6 files changed, 6 insertions(+), 13 deletions(-)
24 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
25 index 60569277584a..293762ec307a 100644
26 --- a/fs/ext4/extents.c
27 +++ b/fs/ext4/extents.c
28 @@ -4618,7 +4618,6 @@ out2:
30 trace_ext4_ext_map_blocks_exit(inode, flags, map,
31 err ? err : allocated);
32 - ext4_es_list_add(inode);
33 return err ? err : allocated;
36 @@ -5177,7 +5176,6 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
37 error = ext4_fill_fiemap_extents(inode, start_blk,
40 - ext4_es_list_add(inode);
44 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
45 index 0193ca107396..de2d9d8bf22f 100644
46 --- a/fs/ext4/extents_status.c
47 +++ b/fs/ext4/extents_status.c
48 @@ -298,7 +298,7 @@ out:
49 trace_ext4_es_find_delayed_extent_range_exit(inode, es);
52 -void ext4_es_list_add(struct inode *inode)
53 +static void ext4_es_list_add(struct inode *inode)
55 struct ext4_inode_info *ei = EXT4_I(inode);
56 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
57 @@ -314,7 +314,7 @@ void ext4_es_list_add(struct inode *inode)
58 spin_unlock(&sbi->s_es_lock);
61 -void ext4_es_list_del(struct inode *inode)
62 +static void ext4_es_list_del(struct inode *inode)
64 struct ext4_inode_info *ei = EXT4_I(inode);
65 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
66 @@ -344,7 +344,8 @@ ext4_es_alloc_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len,
67 * We don't count delayed extent because we never try to reclaim them
69 if (!ext4_es_is_delayed(es)) {
70 - EXT4_I(inode)->i_es_shk_nr++;
71 + if (!EXT4_I(inode)->i_es_shk_nr++)
72 + ext4_es_list_add(inode);
73 percpu_counter_inc(&EXT4_SB(inode->i_sb)->
74 s_es_stats.es_stats_shk_cnt);
76 @@ -363,7 +364,8 @@ static void ext4_es_free_extent(struct inode *inode, struct extent_status *es)
77 /* Decrease the shrink counter when this es is not delayed */
78 if (!ext4_es_is_delayed(es)) {
79 BUG_ON(EXT4_I(inode)->i_es_shk_nr == 0);
80 - EXT4_I(inode)->i_es_shk_nr--;
81 + if (!--EXT4_I(inode)->i_es_shk_nr)
82 + ext4_es_list_del(inode);
83 percpu_counter_dec(&EXT4_SB(inode->i_sb)->
84 s_es_stats.es_stats_shk_cnt);
86 diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
87 index 0e6a33e81e5f..b0b78b95f481 100644
88 --- a/fs/ext4/extents_status.h
89 +++ b/fs/ext4/extents_status.h
90 @@ -150,7 +150,5 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
92 extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
93 extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
94 -extern void ext4_es_list_add(struct inode *inode);
95 -extern void ext4_es_list_del(struct inode *inode);
97 #endif /* _EXT4_EXTENTS_STATUS_H */
98 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
99 index dd21ab011a2a..1ab52bf5698f 100644
100 --- a/fs/ext4/inode.c
101 +++ b/fs/ext4/inode.c
102 @@ -486,7 +486,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
104 /* Lookup extent status tree firstly */
105 if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) {
106 - ext4_es_list_add(inode);
107 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) {
108 map->m_pblk = ext4_es_pblock(&es) +
109 map->m_lblk - es.es_lblk;
110 @@ -1388,7 +1387,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
112 /* Lookup extent status tree firstly */
113 if (ext4_es_lookup_extent(inode, iblock, &es)) {
114 - ext4_es_list_add(inode);
115 if (ext4_es_is_hole(&es)) {
117 down_read(&EXT4_I(inode)->i_data_sem);
118 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
119 index 7b377c41dd81..f58a0d106726 100644
120 --- a/fs/ext4/ioctl.c
121 +++ b/fs/ext4/ioctl.c
122 @@ -78,8 +78,6 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
123 memswap(&ei1->i_disksize, &ei2->i_disksize, sizeof(ei1->i_disksize));
124 ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
125 ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
126 - ext4_es_list_del(inode1);
127 - ext4_es_list_del(inode2);
129 isize = i_size_read(inode1);
130 i_size_write(inode1, i_size_read(inode2));
131 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
132 index 6f64086ac495..f108d84e7da2 100644
133 --- a/fs/ext4/super.c
134 +++ b/fs/ext4/super.c
135 @@ -971,7 +971,6 @@ void ext4_clear_inode(struct inode *inode)
137 ext4_discard_preallocations(inode);
138 ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
139 - ext4_es_list_del(inode);
140 if (EXT4_I(inode)->jinode) {
141 jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode),
142 EXT4_I(inode)->jinode);