While on the LRU list we need to make sure the object itself does not disappear, so hold an i_obj_count reference. This is a little wonky currently as we're dropping the reference before we call evict(), because currently we drop the last reference right before we free the inode. This will be fixed in a future patch when the freeing of the inode is moved under the control of the i_obj_count reference. Signed-off-by: Josef Bacik --- fs/inode.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 0c063227d355..0ca0a1725b3c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -542,10 +542,12 @@ static void __inode_add_lru(struct inode *inode, bool rotate) if (!mapping_shrinkable(&inode->i_data)) return; - if (list_lru_add_obj(&inode->i_sb->s_inode_lru, &inode->i_lru)) + if (list_lru_add_obj(&inode->i_sb->s_inode_lru, &inode->i_lru)) { + iobj_get(inode); this_cpu_inc(nr_unused); - else if (rotate) + } else if (rotate) { inode->i_state |= I_REFERENCED; + } } struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe, @@ -571,8 +573,10 @@ void inode_add_lru(struct inode *inode) static void inode_lru_list_del(struct inode *inode) { - if (list_lru_del_obj(&inode->i_sb->s_inode_lru, &inode->i_lru)) + if (list_lru_del_obj(&inode->i_sb->s_inode_lru, &inode->i_lru)) { + iobj_put(inode); this_cpu_dec(nr_unused); + } } static void inode_pin_lru_isolating(struct inode *inode) @@ -861,6 +865,15 @@ static void dispose_list(struct list_head *head) inode = list_first_entry(head, struct inode, i_lru); list_del_init(&inode->i_lru); + /* + * This is going right here for now only because we are + * currently not using the i_obj_count reference for anything, + * and it needs to hit 0 when we call evict(). + * + * This will be moved when we change the lifetime rules in a + * future patch. + */ + iobj_put(inode); evict(inode); cond_resched(); } @@ -897,6 +910,7 @@ void evict_inodes(struct super_block *sb) } inode->i_state |= I_FREEING; + iobj_get(inode); inode_lru_list_del(inode); spin_unlock(&inode->i_lock); list_add(&inode->i_lru, &dispose); -- 2.49.0