1. 31 Mar, 2021 3 commits
    • Yi Zhuang's avatar
      f2fs: Fix a hungtask problem in atomic write · be1ee45d
      Yi Zhuang authored
      In the cache writing process, if it is an atomic file, increase the page
      count of F2FS_WB_CP_DATA, otherwise increase the page count of
      F2FS_WB_DATA.
      
      When you step into the hook branch due to insufficient memory in
      f2fs_write_begin, f2fs_drop_inmem_pages_all will be called to traverse
      all atomic inodes and clear the FI_ATOMIC_FILE mark of all atomic files.
      
      In f2fs_drop_inmem_pages,first acquire the inmem_lock , revoke all the
      inmem_pages, and then clear the FI_ATOMIC_FILE mark. Before this mark is
      cleared, other threads may hold inmem_lock to add inmem_pages to the inode
      that has just been emptied inmem_pages, and increase the page count of
      F2FS_WB_CP_DATA.
      
      When the IO returns, it is found that the FI_ATOMIC_FILE flag is cleared
      by f2fs_drop_inmem_pages_all, and f2fs_is_atomic_file returns false,which
      causes the page count of F2FS_WB_DATA to be decremented. The page count of
      F2FS_WB_CP_DATA cannot be cleared. Finally, hungtask is triggered in
      f2fs_wait_on_all_pages because get_pages will never return zero.
      
      process A:				process B:
      f2fs_drop_inmem_pages_all
      ->f2fs_drop_inmem_pages of inode#1
          ->mutex_lock(&fi->inmem_lock)
          ->__revoke_inmem_pages of inode#1	f2fs_ioc_commit_atomic_write
          ->mutex_unlock(&fi->inmem_lock)	->f2fs_commit_inmem_pages of inode#1
      					->mutex_lock(&fi->inmem_lock)
      					->__f2fs_commit_inmem_pages
      					    ->f2fs_do_write_data_page
      					        ->f2fs_outplace_write_data
      					            ->do_write_page
      					                ->f2fs_submit_page_write
      					                    ->inc_page_count(sbi, F2FS_WB_CP_DATA )
      					->mutex_unlock(&fi->inmem_lock)
          ->spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
          ->clear_inode_flag(inode, FI_ATOMIC_FILE)
          ->spin_unlock(&sbi->inode_lock[ATOMIC_FILE])
      					f2fs_write_end_io
      					->dec_page_count(sbi, F2FS_WB_DATA );
      
      We can fix the problem by putting the action of clearing the FI_ATOMIC_FILE
      mark into the inmem_lock lock. This operation can ensure that no one will
      submit the inmem pages before the FI_ATOMIC_FILE mark is cleared, so that
      there will be no atomic writes waiting for writeback.
      
      Fixes: 57864ae5 ("f2fs: limit # of inmemory pages")
      Signed-off-by: default avatarYi Zhuang <zhuangyi1@huawei.com>
      Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      be1ee45d
    • Chao Yu's avatar
      f2fs: fix to restrict mount condition on readonly block device · 23738e74
      Chao Yu authored
      When we mount an unclean f2fs image in a readonly block device, let's
      make mount() succeed only when there is no recoverable data in that
      image, otherwise after mount(), file fsyned won't be recovered as user
      expected.
      
      Fixes: 938a1842 ("f2fs: give a warning only for readonly partition")
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      23738e74
    • Chao Yu's avatar
      f2fs: introduce gc_merge mount option · 5911d2d1
      Chao Yu authored
      In this patch, we will add two new mount options: "gc_merge" and
      "nogc_merge", when background_gc is on, "gc_merge" option can be
      set to let background GC thread to handle foreground GC requests,
      it can eliminate the sluggish issue caused by slow foreground GC
      operation when GC is triggered from a process with limited I/O
      and CPU resources.
      
      Original idea is from Xiang.
      Signed-off-by: default avatarGao Xiang <xiang@kernel.org>
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      5911d2d1
  2. 26 Mar, 2021 14 commits
  3. 23 Mar, 2021 1 commit
    • Chao Yu's avatar
      f2fs: fix to align to section for fallocate() on pinned file · e1175f02
      Chao Yu authored
      Now, fallocate() on a pinned file only allocates blocks which aligns
      to segment rather than section, so GC may try to migrate pinned file's
      block, and after several times of failure, pinned file's block could
      be migrated to other place, however user won't be aware of such
      condition, and then old obsolete block address may be readed/written
      incorrectly.
      
      To avoid such condition, let's try to allocate pinned file's blocks
      with section alignment.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      e1175f02
  4. 12 Mar, 2021 22 commits