OSDN Git Service

f2fs: split need_inplace_update
authorChao Yu <yuchao0@huawei.com>
Wed, 17 Jan 2018 08:31:38 +0000 (16:31 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 8 Feb 2018 02:06:03 +0000 (18:06 -0800)
This patch splits need_inplace_update to two functions:
a. should_update_inplace() includes all conditions that we must use IPU.
b. should_update_outplace() includes all conditions that we must use OPU.

So that, in f2fs_ioc_set_pin_file() and f2fs_defragment_range(), we can
use corresponding function to check whether we can trigger OPU/IPU or not.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/segment.h

index 5dc6e46..2003ebd 100644 (file)
@@ -1517,20 +1517,79 @@ retry_encrypt:
        return PTR_ERR(fio->encrypted_page);
 }
 
-static inline bool need_inplace_update(struct f2fs_io_info *fio)
+static inline bool check_inplace_update_policy(struct inode *inode,
+                               struct f2fs_io_info *fio)
 {
-       struct inode *inode = fio->page->mapping->host;
+       struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+       unsigned int policy = SM_I(sbi)->ipu_policy;
 
+       if (policy & (0x1 << F2FS_IPU_FORCE))
+               return true;
+       if (policy & (0x1 << F2FS_IPU_SSR) && need_SSR(sbi))
+               return true;
+       if (policy & (0x1 << F2FS_IPU_UTIL) &&
+                       utilization(sbi) > SM_I(sbi)->min_ipu_util)
+               return true;
+       if (policy & (0x1 << F2FS_IPU_SSR_UTIL) && need_SSR(sbi) &&
+                       utilization(sbi) > SM_I(sbi)->min_ipu_util)
+               return true;
+
+       /*
+        * IPU for rewrite async pages
+        */
+       if (policy & (0x1 << F2FS_IPU_ASYNC) &&
+                       fio && fio->op == REQ_OP_WRITE &&
+                       !(fio->op_flags & REQ_SYNC) &&
+                       !f2fs_encrypted_inode(inode))
+               return true;
+
+       /* this is only set during fdatasync */
+       if (policy & (0x1 << F2FS_IPU_FSYNC) &&
+                       is_inode_flag_set(inode, FI_NEED_IPU))
+               return true;
+
+       return false;
+}
+
+bool should_update_inplace(struct inode *inode, struct f2fs_io_info *fio)
+{
        if (f2fs_is_pinned_file(inode))
                return true;
-       if (S_ISDIR(inode->i_mode) || f2fs_is_atomic_file(inode))
-               return false;
-       if (is_cold_data(fio->page))
-               return false;
-       if (IS_ATOMIC_WRITTEN_PAGE(fio->page))
+
+       /* if this is cold file, we should overwrite to avoid fragmentation */
+       if (file_is_cold(inode))
+               return true;
+
+       return check_inplace_update_policy(inode, fio);
+}
+
+bool should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)
+{
+       struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+
+       if (test_opt(sbi, LFS))
+               return true;
+       if (S_ISDIR(inode->i_mode))
+               return true;
+       if (f2fs_is_atomic_file(inode))
+               return true;
+       if (fio) {
+               if (is_cold_data(fio->page))
+                       return true;
+               if (IS_ATOMIC_WRITTEN_PAGE(fio->page))
+                       return true;
+       }
+       return false;
+}
+
+static inline bool need_inplace_update(struct f2fs_io_info *fio)
+{
+       struct inode *inode = fio->page->mapping->host;
+
+       if (should_update_outplace(inode, fio))
                return false;
 
-       return need_inplace_update_policy(inode, fio);
+       return should_update_inplace(inode, fio);
 }
 
 static inline bool valid_ipu_blkaddr(struct f2fs_io_info *fio)
index 23944b3..29dad83 100644 (file)
@@ -2928,6 +2928,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
                        int create, int flag);
 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                        u64 start, u64 len);
+bool should_update_inplace(struct inode *inode, struct f2fs_io_info *fio);
+bool should_update_outplace(struct inode *inode, struct f2fs_io_info *fio);
 void f2fs_set_page_dirty_nobuffers(struct page *page);
 int __f2fs_write_data_pages(struct address_space *mapping,
                                                struct writeback_control *wbc,
index 02c20d5..2eb9710 100644 (file)
@@ -2058,7 +2058,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
        int err;
 
        /* if in-place-update policy is enabled, don't waste time here */
-       if (need_inplace_update_policy(inode, NULL))
+       if (should_update_inplace(inode, NULL))
                return -EINVAL;
 
        pg_start = range->start >> PAGE_SHIFT;
@@ -2498,6 +2498,11 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
 
        inode_lock(inode);
 
+       if (should_update_outplace(inode, NULL)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        if (!pin) {
                clear_inode_flag(inode, FI_PIN_FILE);
                F2FS_I(inode)->i_gc_failures = 1;
index 5c4d432..e123dd3 100644 (file)
@@ -580,47 +580,6 @@ enum {
        F2FS_IPU_ASYNC,
 };
 
-static inline bool need_inplace_update_policy(struct inode *inode,
-                               struct f2fs_io_info *fio)
-{
-       struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-       unsigned int policy = SM_I(sbi)->ipu_policy;
-
-       if (test_opt(sbi, LFS))
-               return false;
-
-       /* if this is cold file, we should overwrite to avoid fragmentation */
-       if (file_is_cold(inode))
-               return true;
-
-       if (policy & (0x1 << F2FS_IPU_FORCE))
-               return true;
-       if (policy & (0x1 << F2FS_IPU_SSR) && need_SSR(sbi))
-               return true;
-       if (policy & (0x1 << F2FS_IPU_UTIL) &&
-                       utilization(sbi) > SM_I(sbi)->min_ipu_util)
-               return true;
-       if (policy & (0x1 << F2FS_IPU_SSR_UTIL) && need_SSR(sbi) &&
-                       utilization(sbi) > SM_I(sbi)->min_ipu_util)
-               return true;
-
-       /*
-        * IPU for rewrite async pages
-        */
-       if (policy & (0x1 << F2FS_IPU_ASYNC) &&
-                       fio && fio->op == REQ_OP_WRITE &&
-                       !(fio->op_flags & REQ_SYNC) &&
-                       !f2fs_encrypted_inode(inode))
-               return true;
-
-       /* this is only set during fdatasync */
-       if (policy & (0x1 << F2FS_IPU_FSYNC) &&
-                       is_inode_flag_set(inode, FI_NEED_IPU))
-               return true;
-
-       return false;
-}
-
 static inline unsigned int curseg_segno(struct f2fs_sb_info *sbi,
                int type)
 {