f2fs: rename dio_rwsem to i_gc_rwsem

RW semphore dio_rwsem in struct f2fs_inode_info is introduced to avoid
race between dio and data gc, but now, it is more wildly used to avoid
foreground operation vs data gc. So rename it to i_gc_rwsem to improve
its readability.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2018-04-24 10:55:28 +08:00 committed by Jaegeuk Kim
parent b82f6e347b
commit b2532c6940
5 changed files with 29 additions and 27 deletions

View File

@ -2401,17 +2401,17 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
if (rw == WRITE && whint_mode == WHINT_MODE_OFF) if (rw == WRITE && whint_mode == WHINT_MODE_OFF)
iocb->ki_hint = WRITE_LIFE_NOT_SET; iocb->ki_hint = WRITE_LIFE_NOT_SET;
if (!down_read_trylock(&F2FS_I(inode)->dio_rwsem[rw])) { if (!down_read_trylock(&F2FS_I(inode)->i_gc_rwsem[rw])) {
if (iocb->ki_flags & IOCB_NOWAIT) { if (iocb->ki_flags & IOCB_NOWAIT) {
iocb->ki_hint = hint; iocb->ki_hint = hint;
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
} }
down_read(&F2FS_I(inode)->dio_rwsem[rw]); down_read(&F2FS_I(inode)->i_gc_rwsem[rw]);
} }
err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio);
up_read(&F2FS_I(inode)->dio_rwsem[rw]); up_read(&F2FS_I(inode)->i_gc_rwsem[rw]);
if (rw == WRITE) { if (rw == WRITE) {
if (whint_mode == WHINT_MODE_OFF) if (whint_mode == WHINT_MODE_OFF)

View File

@ -653,7 +653,9 @@ struct f2fs_inode_info {
struct task_struct *inmem_task; /* store inmemory task */ struct task_struct *inmem_task; /* store inmemory task */
struct mutex inmem_lock; /* lock for inmemory pages */ struct mutex inmem_lock; /* lock for inmemory pages */
struct extent_tree *extent_tree; /* cached extent_tree entry */ struct extent_tree *extent_tree; /* cached extent_tree entry */
struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
/* avoid racing between foreground op and gc */
struct rw_semaphore i_gc_rwsem[2];
struct rw_semaphore i_mmap_sem; struct rw_semaphore i_mmap_sem;
struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */

View File

@ -1187,7 +1187,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
pg_end = (offset + len) >> PAGE_SHIFT; pg_end = (offset + len) >> PAGE_SHIFT;
/* avoid gc operation during block exchange */ /* avoid gc operation during block exchange */
down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
down_write(&F2FS_I(inode)->i_mmap_sem); down_write(&F2FS_I(inode)->i_mmap_sem);
/* write out all dirty pages from offset */ /* write out all dirty pages from offset */
@ -1213,7 +1213,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
f2fs_i_size_write(inode, new_size); f2fs_i_size_write(inode, new_size);
out_unlock: out_unlock:
up_write(&F2FS_I(inode)->i_mmap_sem); up_write(&F2FS_I(inode)->i_mmap_sem);
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
return ret; return ret;
} }
@ -1389,7 +1389,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
f2fs_balance_fs(sbi, true); f2fs_balance_fs(sbi, true);
/* avoid gc operation during block exchange */ /* avoid gc operation during block exchange */
down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
down_write(&F2FS_I(inode)->i_mmap_sem); down_write(&F2FS_I(inode)->i_mmap_sem);
ret = truncate_blocks(inode, i_size_read(inode), true); ret = truncate_blocks(inode, i_size_read(inode), true);
@ -1430,7 +1430,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
f2fs_i_size_write(inode, new_size); f2fs_i_size_write(inode, new_size);
out: out:
up_write(&F2FS_I(inode)->i_mmap_sem); up_write(&F2FS_I(inode)->i_mmap_sem);
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
return ret; return ret;
} }
@ -1677,7 +1677,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
inode_lock(inode); inode_lock(inode);
down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
if (f2fs_is_atomic_file(inode)) if (f2fs_is_atomic_file(inode))
goto out; goto out;
@ -1704,7 +1704,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
stat_inc_atomic_write(inode); stat_inc_atomic_write(inode);
stat_update_max_atomic_write(inode); stat_update_max_atomic_write(inode);
out: out:
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
inode_unlock(inode); inode_unlock(inode);
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
return ret; return ret;
@ -1724,7 +1724,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
inode_lock(inode); inode_lock(inode);
down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
if (f2fs_is_volatile_file(inode)) { if (f2fs_is_volatile_file(inode)) {
ret = -EINVAL; ret = -EINVAL;
@ -1746,7 +1746,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
} }
err_out: err_out:
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
inode_unlock(inode); inode_unlock(inode);
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
return ret; return ret;
@ -2333,12 +2333,12 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
} }
inode_lock(src); inode_lock(src);
down_write(&F2FS_I(src)->dio_rwsem[WRITE]); down_write(&F2FS_I(src)->i_gc_rwsem[WRITE]);
if (src != dst) { if (src != dst) {
ret = -EBUSY; ret = -EBUSY;
if (!inode_trylock(dst)) if (!inode_trylock(dst))
goto out; goto out;
if (!down_write_trylock(&F2FS_I(dst)->dio_rwsem[WRITE])) { if (!down_write_trylock(&F2FS_I(dst)->i_gc_rwsem[WRITE])) {
inode_unlock(dst); inode_unlock(dst);
goto out; goto out;
} }
@ -2400,11 +2400,11 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
f2fs_unlock_op(sbi); f2fs_unlock_op(sbi);
out_unlock: out_unlock:
if (src != dst) { if (src != dst) {
up_write(&F2FS_I(dst)->dio_rwsem[WRITE]); up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
inode_unlock(dst); inode_unlock(dst);
} }
out: out:
up_write(&F2FS_I(src)->dio_rwsem[WRITE]); up_write(&F2FS_I(src)->i_gc_rwsem[WRITE]);
inode_unlock(src); inode_unlock(src);
return ret; return ret;
} }
@ -2814,9 +2814,9 @@ int f2fs_precache_extents(struct inode *inode)
while (map.m_lblk < end) { while (map.m_lblk < end) {
map.m_len = end - map.m_lblk; map.m_len = end - map.m_lblk;
down_write(&fi->dio_rwsem[WRITE]); down_write(&fi->i_gc_rwsem[WRITE]);
err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE); err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE);
up_write(&fi->dio_rwsem[WRITE]); up_write(&fi->i_gc_rwsem[WRITE]);
if (err) if (err)
return err; return err;

View File

@ -858,7 +858,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
} }
if (!down_write_trylock( if (!down_write_trylock(
&F2FS_I(inode)->dio_rwsem[WRITE])) { &F2FS_I(inode)->i_gc_rwsem[WRITE])) {
iput(inode); iput(inode);
continue; continue;
} }
@ -867,7 +867,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
data_page = get_read_data_page(inode, data_page = get_read_data_page(inode,
start_bidx + ofs_in_node, REQ_RAHEAD, start_bidx + ofs_in_node, REQ_RAHEAD,
true); true);
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
if (IS_ERR(data_page)) { if (IS_ERR(data_page)) {
iput(inode); iput(inode);
continue; continue;
@ -885,11 +885,11 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
bool locked = false; bool locked = false;
if (S_ISREG(inode->i_mode)) { if (S_ISREG(inode->i_mode)) {
if (!down_write_trylock(&fi->dio_rwsem[READ])) if (!down_write_trylock(&fi->i_gc_rwsem[READ]))
continue; continue;
if (!down_write_trylock( if (!down_write_trylock(
&fi->dio_rwsem[WRITE])) { &fi->i_gc_rwsem[WRITE])) {
up_write(&fi->dio_rwsem[READ]); up_write(&fi->i_gc_rwsem[READ]);
continue; continue;
} }
locked = true; locked = true;
@ -907,8 +907,8 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
segno, off); segno, off);
if (locked) { if (locked) {
up_write(&fi->dio_rwsem[WRITE]); up_write(&fi->i_gc_rwsem[WRITE]);
up_write(&fi->dio_rwsem[READ]); up_write(&fi->i_gc_rwsem[READ]);
} }
stat_inc_data_blk_count(sbi, 1, gc_type); stat_inc_data_blk_count(sbi, 1, gc_type);

View File

@ -837,8 +837,8 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
INIT_LIST_HEAD(&fi->inmem_ilist); INIT_LIST_HEAD(&fi->inmem_ilist);
INIT_LIST_HEAD(&fi->inmem_pages); INIT_LIST_HEAD(&fi->inmem_pages);
mutex_init(&fi->inmem_lock); mutex_init(&fi->inmem_lock);
init_rwsem(&fi->dio_rwsem[READ]); init_rwsem(&fi->i_gc_rwsem[READ]);
init_rwsem(&fi->dio_rwsem[WRITE]); init_rwsem(&fi->i_gc_rwsem[WRITE]);
init_rwsem(&fi->i_mmap_sem); init_rwsem(&fi->i_mmap_sem);
init_rwsem(&fi->i_xattr_sem); init_rwsem(&fi->i_xattr_sem);