Commit 227c4d50 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'f2fs-for-5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim:
 "In this round, we've improved the compression support especially for
  Android such as allowing compression for mmap files, replacing the
  immutable bit with internal bit to prohibits data writes explicitly,
  and adding a mount option, "compress_cache", to improve random reads.
  And, we added "readonly" feature to compact the partition w/
  compression enabled, which will be useful for Android RO partitions.

  Enhancements:
   - support compression for mmap file
   - use an f2fs flag instead of IMMUTABLE bit for compression
   - support RO feature w/ extent_cache
   - fully support swapfile with file pinning
   - improve atgc tunability
   - add nocompress extensions to unselect files for compression

  Bug fixes:
   - fix false alaram on iget failure during GC
   - fix race condition on global pointers when there are multiple f2fs
     instances
   - add MODULE_SOFTDEP for initramfs

  As usual, we've also cleaned up some places for better code
  readability (e.g., sysfs/feature, debugging messages, slab cache
  name, and docs)"

* tag 'f2fs-for-5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (32 commits)
  f2fs: drop dirty node pages when cp is in error status
  f2fs: initialize page->private when using for our internal use
  f2fs: compress: add nocompress extensions support
  MAINTAINERS: f2fs: update my email address
  f2fs: remove false alarm on iget failure during GC
  f2fs: enable extent cache for compression files in read-only
  f2fs: fix to avoid adding tab before doc section
  f2fs: introduce f2fs_casefolded_name slab cache
  f2fs: swap: support migrating swapfile in aligned write mode
  f2fs: swap: remove dead codes
  f2fs: compress: add compress_inode to cache compressed blocks
  f2fs: clean up /sys/fs/f2fs/<disk>/features
  f2fs: add pin_file in feature list
  f2fs: Advertise encrypted casefolding in sysfs
  f2fs: Show casefolding support only when supported
  f2fs: support RO feature
  f2fs: logging neatening
  f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  f2fs: compress: remove unneeded preallocation
  f2fs: atgc: export entries for better tunability via sysfs
  ...
parents bd9c3506 28607bf3
...@@ -203,7 +203,34 @@ Description: Shows total written kbytes issued to disk. ...@@ -203,7 +203,34 @@ Description: Shows total written kbytes issued to disk.
What: /sys/fs/f2fs/<disk>/features What: /sys/fs/f2fs/<disk>/features
Date: July 2017 Date: July 2017
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
Description: Shows all enabled features in current device. Description: <deprecated: should use /sys/fs/f2fs/<disk>/feature_list/
Shows all enabled features in current device.
Supported features:
encryption, blkzoned, extra_attr, projquota, inode_checksum,
flexible_inline_xattr, quota_ino, inode_crtime, lost_found,
verity, sb_checksum, casefold, readonly, compression, pin_file.
What: /sys/fs/f2fs/<disk>/feature_list/
Date: June 2021
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
Description: Expand /sys/fs/f2fs/<disk>/features to meet sysfs rule.
Supported on-disk features:
encryption, block_zoned (aka blkzoned), extra_attr,
project_quota (aka projquota), inode_checksum,
flexible_inline_xattr, quota_ino, inode_crtime, lost_found,
verity, sb_checksum, casefold, readonly, compression.
Note that, pin_file is moved into /sys/fs/f2fs/features/.
What: /sys/fs/f2fs/features/
Date: July 2017
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
Description: Shows all enabled kernel features.
Supported features:
encryption, block_zoned, extra_attr, project_quota,
inode_checksum, flexible_inline_xattr, quota_ino,
inode_crtime, lost_found, verity, sb_checksum,
casefold, readonly, compression, test_dummy_encryption_v2,
atomic_write, pin_file, encrypted_casefold.
What: /sys/fs/f2fs/<disk>/inject_rate What: /sys/fs/f2fs/<disk>/inject_rate
Date: May 2016 Date: May 2016
...@@ -438,3 +465,31 @@ Description: Show the count of inode newly enabled for compression since mount. ...@@ -438,3 +465,31 @@ Description: Show the count of inode newly enabled for compression since mount.
Note that when the compression is disabled for the files, this count Note that when the compression is disabled for the files, this count
doesn't decrease. If you write "0" here, you can initialize doesn't decrease. If you write "0" here, you can initialize
compr_new_inode to "0". compr_new_inode to "0".
What: /sys/fs/f2fs/<disk>/atgc_candidate_ratio
Date: May 2021
Contact: "Chao Yu" <yuchao0@huawei.com>
Description: When ATGC is on, it controls candidate ratio in order to limit total
number of potential victim in all candidates, the value should be in
range of [0, 100], by default it was initialized as 20(%).
What: /sys/fs/f2fs/<disk>/atgc_candidate_count
Date: May 2021
Contact: "Chao Yu" <yuchao0@huawei.com>
Description: When ATGC is on, it controls candidate count in order to limit total
number of potential victim in all candidates, by default it was
initialized as 10 (sections).
What: /sys/fs/f2fs/<disk>/atgc_age_weight
Date: May 2021
Contact: "Chao Yu" <yuchao0@huawei.com>
Description: When ATGC is on, it controls age weight to balance weight proportion
in between aging and valid blocks, the value should be in range of
[0, 100], by default it was initialized as 60(%).
What: /sys/fs/f2fs/<disk>/atgc_age_threshold
Date: May 2021
Contact: "Chao Yu" <yuchao0@huawei.com>
Description: When ATGC is on, it controls age threshold to bypass GCing young
candidates whose age is not beyond the threshold, by default it was
initialized as 604800 seconds (equals to 7 days).
...@@ -281,6 +281,18 @@ compress_extension=%s Support adding specified extension, so that f2fs can enab ...@@ -281,6 +281,18 @@ compress_extension=%s Support adding specified extension, so that f2fs can enab
For other files, we can still enable compression via ioctl. For other files, we can still enable compression via ioctl.
Note that, there is one reserved special extension '*', it Note that, there is one reserved special extension '*', it
can be set to enable compression for all files. can be set to enable compression for all files.
nocompress_extension=%s Support adding specified extension, so that f2fs can disable
compression on those corresponding files, just contrary to compression extension.
If you know exactly which files cannot be compressed, you can use this.
The same extension name can't appear in both compress and nocompress
extension at the same time.
If the compress extension specifies all files, the types specified by the
nocompress extension will be treated as special cases and will not be compressed.
Don't allow use '*' to specifie all file in nocompress extension.
After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
See more in compression sections.
compress_chksum Support verifying chksum of raw data in compressed cluster. compress_chksum Support verifying chksum of raw data in compressed cluster.
compress_mode=%s Control file compression mode. This supports "fs" and "user" compress_mode=%s Control file compression mode. This supports "fs" and "user"
modes. In "fs" mode (default), f2fs does automatic compression modes. In "fs" mode (default), f2fs does automatic compression
...@@ -289,6 +301,9 @@ compress_mode=%s Control file compression mode. This supports "fs" and "user" ...@@ -289,6 +301,9 @@ compress_mode=%s Control file compression mode. This supports "fs" and "user"
choosing the target file and the timing. The user can do manual choosing the target file and the timing. The user can do manual
compression/decompression on the compression enabled files using compression/decompression on the compression enabled files using
ioctls. ioctls.
compress_cache Support to use address space of a filesystem managed inode to
cache compressed block, in order to improve cache hit ratio of
random read.
inlinecrypt When possible, encrypt/decrypt the contents of encrypted inlinecrypt When possible, encrypt/decrypt the contents of encrypted
files using the blk-crypto framework rather than files using the blk-crypto framework rather than
filesystem-layer encryption. This allows the use of filesystem-layer encryption. This allows the use of
...@@ -717,10 +732,10 @@ users. ...@@ -717,10 +732,10 @@ users.
===================== ======================== =================== ===================== ======================== ===================
User F2FS Block User F2FS Block
===================== ======================== =================== ===================== ======================== ===================
META WRITE_LIFE_NOT_SET N/A META WRITE_LIFE_NOT_SET
HOT_NODE " N/A HOT_NODE "
WARM_NODE " N/A WARM_NODE "
COLD_NODE " N/A COLD_NODE "
ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
extension list " " extension list " "
...@@ -746,10 +761,10 @@ WRITE_LIFE_LONG " WRITE_LIFE_LONG ...@@ -746,10 +761,10 @@ WRITE_LIFE_LONG " WRITE_LIFE_LONG
===================== ======================== =================== ===================== ======================== ===================
User F2FS Block User F2FS Block
===================== ======================== =================== ===================== ======================== ===================
META WRITE_LIFE_MEDIUM; N/A META WRITE_LIFE_MEDIUM;
HOT_NODE WRITE_LIFE_NOT_SET N/A HOT_NODE WRITE_LIFE_NOT_SET
WARM_NODE " N/A WARM_NODE "
COLD_NODE WRITE_LIFE_NONE N/A COLD_NODE WRITE_LIFE_NONE
ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
extension list " " extension list " "
...@@ -814,13 +829,30 @@ Compression implementation ...@@ -814,13 +829,30 @@ Compression implementation
all logical blocks in cluster contain valid data and compress ratio of all logical blocks in cluster contain valid data and compress ratio of
cluster data is lower than specified threshold. cluster data is lower than specified threshold.
- To enable compression on regular inode, there are three ways: - To enable compression on regular inode, there are four ways:
* chattr +c file * chattr +c file
* chattr +c dir; touch dir/file * chattr +c dir; touch dir/file
* mount w/ -o compress_extension=ext; touch file.ext * mount w/ -o compress_extension=ext; touch file.ext
* mount w/ -o compress_extension=*; touch any_file * mount w/ -o compress_extension=*; touch any_file
- To disable compression on regular inode, there are two ways:
* chattr -c file
* mount w/ -o nocompress_extension=ext; touch file.ext
- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
* compress_extension=so; nocompress_extension=zip; chattr +c dir; touch
dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
can enable compress on bar.zip.
* compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
compresse, bar.zip and baz.txt should be non-compressed.
chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
and baz.txt.
- At this point, compression feature doesn't expose compressed space to user - At this point, compression feature doesn't expose compressed space to user
directly in order to guarantee potential data updates later to the space. directly in order to guarantee potential data updates later to the space.
Instead, the main goal is to reduce data writes to flash disk as much as Instead, the main goal is to reduce data writes to flash disk as much as
......
...@@ -7010,7 +7010,7 @@ F: drivers/iommu/exynos-iommu.c ...@@ -7010,7 +7010,7 @@ F: drivers/iommu/exynos-iommu.c
F2FS FILE SYSTEM F2FS FILE SYSTEM
M: Jaegeuk Kim <jaegeuk@kernel.org> M: Jaegeuk Kim <jaegeuk@kernel.org>
M: Chao Yu <yuchao0@huawei.com> M: Chao Yu <chao@kernel.org>
L: linux-f2fs-devel@lists.sourceforge.net L: linux-f2fs-devel@lists.sourceforge.net
S: Maintained S: Maintained
W: https://f2fs.wiki.kernel.org/ W: https://f2fs.wiki.kernel.org/
......
...@@ -444,7 +444,7 @@ static int f2fs_set_meta_page_dirty(struct page *page) ...@@ -444,7 +444,7 @@ static int f2fs_set_meta_page_dirty(struct page *page)
if (!PageDirty(page)) { if (!PageDirty(page)) {
__set_page_dirty_nobuffers(page); __set_page_dirty_nobuffers(page);
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META); inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
f2fs_set_page_private(page, 0); set_page_private_reference(page);
return 1; return 1;
} }
return 0; return 0;
...@@ -1018,7 +1018,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page) ...@@ -1018,7 +1018,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page)
inode_inc_dirty_pages(inode); inode_inc_dirty_pages(inode);
spin_unlock(&sbi->inode_lock[type]); spin_unlock(&sbi->inode_lock[type]);
f2fs_set_page_private(page, 0); set_page_private_reference(page);
} }
void f2fs_remove_dirty_inode(struct inode *inode) void f2fs_remove_dirty_inode(struct inode *inode)
......
This diff is collapsed.
This diff is collapsed.
...@@ -152,6 +152,12 @@ static void update_general_status(struct f2fs_sb_info *sbi) ...@@ -152,6 +152,12 @@ static void update_general_status(struct f2fs_sb_info *sbi)
si->node_pages = NODE_MAPPING(sbi)->nrpages; si->node_pages = NODE_MAPPING(sbi)->nrpages;
if (sbi->meta_inode) if (sbi->meta_inode)
si->meta_pages = META_MAPPING(sbi)->nrpages; si->meta_pages = META_MAPPING(sbi)->nrpages;
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (sbi->compress_inode) {
si->compress_pages = COMPRESS_MAPPING(sbi)->nrpages;
si->compress_page_hit = atomic_read(&sbi->compress_page_hit);
}
#endif
si->nats = NM_I(sbi)->nat_cnt[TOTAL_NAT]; si->nats = NM_I(sbi)->nat_cnt[TOTAL_NAT];
si->dirty_nats = NM_I(sbi)->nat_cnt[DIRTY_NAT]; si->dirty_nats = NM_I(sbi)->nat_cnt[DIRTY_NAT];
si->sits = MAIN_SEGS(sbi); si->sits = MAIN_SEGS(sbi);
...@@ -309,6 +315,12 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -309,6 +315,12 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
si->page_mem += (unsigned long long)npages << PAGE_SHIFT; si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
} }
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (sbi->compress_inode) {
unsigned npages = COMPRESS_MAPPING(sbi)->nrpages;
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
}
#endif
} }
static int stat_show(struct seq_file *s, void *v) static int stat_show(struct seq_file *s, void *v)
...@@ -476,6 +488,7 @@ static int stat_show(struct seq_file *s, void *v) ...@@ -476,6 +488,7 @@ static int stat_show(struct seq_file *s, void *v)
"volatile IO: %4d (Max. %4d)\n", "volatile IO: %4d (Max. %4d)\n",
si->inmem_pages, si->aw_cnt, si->max_aw_cnt, si->inmem_pages, si->aw_cnt, si->max_aw_cnt,
si->vw_cnt, si->max_vw_cnt); si->vw_cnt, si->max_vw_cnt);
seq_printf(s, " - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit);
seq_printf(s, " - nodes: %4d in %4d\n", seq_printf(s, " - nodes: %4d in %4d\n",
si->ndirty_node, si->node_pages); si->ndirty_node, si->node_pages);
seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n", seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n",
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "xattr.h" #include "xattr.h"
#include <trace/events/f2fs.h> #include <trace/events/f2fs.h>
#ifdef CONFIG_UNICODE
extern struct kmem_cache *f2fs_cf_name_slab;
#endif
static unsigned long dir_blocks(struct inode *inode) static unsigned long dir_blocks(struct inode *inode)
{ {
return ((unsigned long long) (i_size_read(inode) + PAGE_SIZE - 1)) return ((unsigned long long) (i_size_read(inode) + PAGE_SIZE - 1))
...@@ -77,10 +81,9 @@ int f2fs_init_casefolded_name(const struct inode *dir, ...@@ -77,10 +81,9 @@ int f2fs_init_casefolded_name(const struct inode *dir,
{ {
#ifdef CONFIG_UNICODE #ifdef CONFIG_UNICODE
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct f2fs_sb_info *sbi = F2FS_SB(sb);
if (IS_CASEFOLDED(dir)) { if (IS_CASEFOLDED(dir)) {
fname->cf_name.name = f2fs_kmalloc(sbi, F2FS_NAME_LEN, fname->cf_name.name = kmem_cache_alloc(f2fs_cf_name_slab,
GFP_NOFS); GFP_NOFS);
if (!fname->cf_name.name) if (!fname->cf_name.name)
return -ENOMEM; return -ENOMEM;
...@@ -89,7 +92,7 @@ int f2fs_init_casefolded_name(const struct inode *dir, ...@@ -89,7 +92,7 @@ int f2fs_init_casefolded_name(const struct inode *dir,
fname->cf_name.name, fname->cf_name.name,
F2FS_NAME_LEN); F2FS_NAME_LEN);
if ((int)fname->cf_name.len <= 0) { if ((int)fname->cf_name.len <= 0) {
kfree(fname->cf_name.name); kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
fname->cf_name.name = NULL; fname->cf_name.name = NULL;
if (sb_has_strict_encoding(sb)) if (sb_has_strict_encoding(sb))
return -EINVAL; return -EINVAL;
...@@ -172,8 +175,10 @@ void f2fs_free_filename(struct f2fs_filename *fname) ...@@ -172,8 +175,10 @@ void f2fs_free_filename(struct f2fs_filename *fname)
fname->crypto_buf.name = NULL; fname->crypto_buf.name = NULL;
#endif #endif
#ifdef CONFIG_UNICODE #ifdef CONFIG_UNICODE
kfree(fname->cf_name.name); if (fname->cf_name.name) {
kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
fname->cf_name.name = NULL; fname->cf_name.name = NULL;
}
#endif #endif
} }
...@@ -929,11 +934,15 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, ...@@ -929,11 +934,15 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
!f2fs_truncate_hole(dir, page->index, page->index + 1)) { !f2fs_truncate_hole(dir, page->index, page->index + 1)) {
f2fs_clear_page_cache_dirty_tag(page); f2fs_clear_page_cache_dirty_tag(page);
clear_page_dirty_for_io(page); clear_page_dirty_for_io(page);
f2fs_clear_page_private(page);
ClearPageUptodate(page); ClearPageUptodate(page);
clear_cold_data(page);
clear_page_private_gcing(page);
inode_dec_dirty_pages(dir); inode_dec_dirty_pages(dir);
f2fs_remove_dirty_inode(dir); f2fs_remove_dirty_inode(dir);
detach_page_private(page);
set_page_private(page, 0);
} }
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
......
This diff is collapsed.
...@@ -63,6 +63,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) ...@@ -63,6 +63,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
if (unlikely(IS_IMMUTABLE(inode))) if (unlikely(IS_IMMUTABLE(inode)))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
return VM_FAULT_SIGBUS;
if (unlikely(f2fs_cp_error(sbi))) { if (unlikely(f2fs_cp_error(sbi))) {
err = -EIO; err = -EIO;
goto err; goto err;
...@@ -85,10 +88,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) ...@@ -85,10 +88,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
err = ret; err = ret;
goto err; goto err;
} else if (ret) { } else if (ret) {
if (ret < F2FS_I(inode)->i_cluster_size) {
err = -EAGAIN;
goto err;
}
need_alloc = false; need_alloc = false;
} }
} }
...@@ -117,7 +116,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) ...@@ -117,7 +116,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
err = f2fs_get_block(&dn, page->index); err = f2fs_get_block(&dn, page->index);
f2fs_put_dnode(&dn);
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false);
} }
...@@ -3203,7 +3201,7 @@ int f2fs_precache_extents(struct inode *inode) ...@@ -3203,7 +3201,7 @@ int f2fs_precache_extents(struct inode *inode)
map.m_lblk = m_next_extent; map.m_lblk = m_next_extent;
} }
return err; return 0;
} }
static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg) static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg)
...@@ -3237,7 +3235,7 @@ static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg) ...@@ -3237,7 +3235,7 @@ static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg)
if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) { if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) {
f2fs_warn(F2FS_I_SB(inode), f2fs_warn(F2FS_I_SB(inode),
"Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem.\n", "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem",
inode->i_ino); inode->i_ino);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -3425,7 +3423,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) ...@@ -3425,7 +3423,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
goto out; goto out;
} }
if (IS_IMMUTABLE(inode)) { if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
...@@ -3434,8 +3432,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) ...@@ -3434,8 +3432,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
if (ret) if (ret)
goto out; goto out;
F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; set_inode_flag(inode, FI_COMPRESS_RELEASED);
f2fs_set_inode_flags(inode);
inode->i_ctime = current_time(inode); inode->i_ctime = current_time(inode);
f2fs_mark_inode_dirty_sync(inode, true); f2fs_mark_inode_dirty_sync(inode, true);
...@@ -3590,7 +3587,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) ...@@ -3590,7 +3587,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
inode_lock(inode); inode_lock(inode);
if (!IS_IMMUTABLE(inode)) { if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
ret = -EINVAL; ret = -EINVAL;
goto unlock_inode; goto unlock_inode;
} }
...@@ -3635,8 +3632,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) ...@@ -3635,8 +3632,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
up_write(&F2FS_I(inode)->i_mmap_sem); up_write(&F2FS_I(inode)->i_mmap_sem);
if (ret >= 0) { if (ret >= 0) {
F2FS_I(inode)->i_flags &= ~F2FS_IMMUTABLE_FL; clear_inode_flag(inode, FI_COMPRESS_RELEASED);
f2fs_set_inode_flags(inode);
inode->i_ctime = current_time(inode); inode->i_ctime = current_time(inode);
f2fs_mark_inode_dirty_sync(inode, true); f2fs_mark_inode_dirty_sync(inode, true);
} }
...@@ -4023,8 +4019,7 @@ static int f2fs_ioc_decompress_file(struct file *filp, unsigned long arg) ...@@ -4023,8 +4019,7 @@ static int f2fs_ioc_decompress_file(struct file *filp, unsigned long arg)
LLONG_MAX); LLONG_MAX);
if (ret) if (ret)
f2fs_warn(sbi, "%s: The file might be partially decompressed " f2fs_warn(sbi, "%s: The file might be partially decompressed (errno=%d). Please delete the file.",
"(errno=%d). Please delete the file.\n",
__func__, ret); __func__, ret);
out: out:
inode_unlock(inode); inode_unlock(inode);
...@@ -4097,8 +4092,7 @@ static int f2fs_ioc_compress_file(struct file *filp, unsigned long arg) ...@@ -4097,8 +4092,7 @@ static int f2fs_ioc_compress_file(struct file *filp, unsigned long arg)
clear_inode_flag(inode, FI_ENABLE_COMPRESS); clear_inode_flag(inode, FI_ENABLE_COMPRESS);
if (ret) if (ret)
f2fs_warn(sbi, "%s: The file might be partially compressed " f2fs_warn(sbi, "%s: The file might be partially compressed (errno=%d). Please delete the file.",
"(errno=%d). Please delete the file.\n",
__func__, ret); __func__, ret);
out: out:
inode_unlock(inode); inode_unlock(inode);
...@@ -4254,6 +4248,11 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -4254,6 +4248,11 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
goto unlock; goto unlock;
} }
if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
ret = -EPERM;
goto unlock;
}
ret = generic_write_checks(iocb, from); ret = generic_write_checks(iocb, from);
if (ret > 0) { if (ret > 0) {
bool preallocated = false; bool preallocated = false;
......
...@@ -1031,7 +1031,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -1031,7 +1031,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
if (unlikely(check_valid_map(sbi, segno, offset))) { if (unlikely(check_valid_map(sbi, segno, offset))) {
if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) {
f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u\n", f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u",
blkaddr, source_blkaddr, segno); blkaddr, source_blkaddr, segno);
f2fs_bug_on(sbi, 1); f2fs_bug_on(sbi, 1);
} }
...@@ -1261,6 +1261,7 @@ static int move_data_block(struct inode *inode, block_t bidx, ...@@ -1261,6 +1261,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
f2fs_put_page(mpage, 1); f2fs_put_page(mpage, 1);
invalidate_mapping_pages(META_MAPPING(fio.sbi), invalidate_mapping_pages(META_MAPPING(fio.sbi),
fio.old_blkaddr, fio.old_blkaddr); fio.old_blkaddr, fio.old_blkaddr);
f2fs_invalidate_compress_page(fio.sbi, fio.old_blkaddr);
set_page_dirty(fio.encrypted_page); set_page_dirty(fio.encrypted_page);
if (clear_page_dirty_for_io(fio.encrypted_page)) if (clear_page_dirty_for_io(fio.encrypted_page))
...@@ -1336,7 +1337,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type, ...@@ -1336,7 +1337,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
goto out; goto out;
} }
set_page_dirty(page); set_page_dirty(page);
set_cold_data(page); set_page_private_gcing(page);
} else { } else {
struct f2fs_io_info fio = { struct f2fs_io_info fio = {
.sbi = F2FS_I_SB(inode), .sbi = F2FS_I_SB(inode),
...@@ -1362,11 +1363,11 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type, ...@@ -1362,11 +1363,11 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
f2fs_remove_dirty_inode(inode); f2fs_remove_dirty_inode(inode);
} }
set_cold_data(page); set_page_private_gcing(page);
err = f2fs_do_write_data_page(&fio); err = f2fs_do_write_data_page(&fio);
if (err) { if (err) {
clear_cold_data(page); clear_page_private_gcing(page);
if (err == -ENOMEM) { if (err == -ENOMEM) {
congestion_wait(BLK_RW_ASYNC, congestion_wait(BLK_RW_ASYNC,
DEFAULT_IO_TIMEOUT); DEFAULT_IO_TIMEOUT);
...@@ -1450,10 +1451,8 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -1450,10 +1451,8 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
if (phase == 3) { if (phase == 3) {
inode = f2fs_iget(sb, dni.ino); inode = f2fs_iget(sb, dni.ino);
if (IS_ERR(inode) || is_bad_inode(inode)) { if (IS_ERR(inode) || is_bad_inode(inode))
set_sbi_flag(sbi, SBI_NEED_FSCK);
continue; continue;
}
if (!down_write_trylock( if (!down_write_trylock(
&F2FS_I(inode)->i_gc_rwsem[WRITE])) { &F2FS_I(inode)->i_gc_rwsem[WRITE])) {
...@@ -1822,6 +1821,7 @@ static void init_atgc_management(struct f2fs_sb_info *sbi) ...@@ -1822,6 +1821,7 @@ static void init_atgc_management(struct f2fs_sb_info *sbi)
am->candidate_ratio = DEF_GC_THREAD_CANDIDATE_RATIO; am->candidate_ratio = DEF_GC_THREAD_CANDIDATE_RATIO;
am->max_candidate_count = DEF_GC_THREAD_MAX_CANDIDATE_COUNT; am->max_candidate_count = DEF_GC_THREAD_MAX_CANDIDATE_COUNT;
am->age_weight = DEF_GC_THREAD_AGE_WEIGHT; am->age_weight = DEF_GC_THREAD_AGE_WEIGHT;
am->age_threshold = DEF_GC_THREAD_AGE_THRESHOLD;
} }
void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
......
...@@ -173,7 +173,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) ...@@ -173,7 +173,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
/* clear inline data and flag after data writeback */ /* clear inline data and flag after data writeback */
f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0); f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0);
clear_inline_node(dn->inode_page); clear_page_private_inline(dn->inode_page);
clear_out: clear_out:
stat_dec_inline_inode(dn->inode); stat_dec_inline_inode(dn->inode);
clear_inode_flag(dn->inode, FI_INLINE_DATA); clear_inode_flag(dn->inode, FI_INLINE_DATA);
...@@ -255,7 +255,7 @@ int f2fs_write_inline_data(struct inode *inode, struct page *page) ...@@ -255,7 +255,7 @@ int f2fs_write_inline_data(struct inode *inode, struct page *page)
set_inode_flag(inode, FI_APPEND_WRITE); set_inode_flag(inode, FI_APPEND_WRITE);
set_inode_flag(inode, FI_DATA_EXIST); set_inode_flag(inode, FI_DATA_EXIST);
clear_inline_node(dn.inode_page); clear_page_private_inline(dn.inode_page);
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
return 0; return 0;
} }
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include <trace/events/f2fs.h> #include <trace/events/f2fs.h>
#ifdef CONFIG_F2FS_FS_COMPRESSION
extern const struct address_space_operations f2fs_compress_aops;
#endif
void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
{ {
if (is_inode_flag_set(inode, FI_NEW_INODE)) if (is_inode_flag_set(inode, FI_NEW_INODE))
...@@ -494,6 +498,11 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) ...@@ -494,6 +498,11 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi)) if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi))
goto make_now; goto make_now;
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (ino == F2FS_COMPRESS_INO(sbi))
goto make_now;
#endif
ret = do_read_inode(inode); ret = do_read_inode(inode);
if (ret) if (ret)
goto bad_inode; goto bad_inode;
...@@ -504,6 +513,12 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) ...@@ -504,6 +513,12 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
} else if (ino == F2FS_META_INO(sbi)) { } else if (ino == F2FS_META_INO(sbi)) {
inode->i_mapping->a_ops = &f2fs_meta_aops; inode->i_mapping->a_ops = &f2fs_meta_aops;
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
} else if (ino == F2FS_COMPRESS_INO(sbi)) {
#ifdef CONFIG_F2FS_FS_COMPRESSION
inode->i_mapping->a_ops = &f2fs_compress_aops;
#endif
mapping_set_gfp_mask(inode->i_mapping,
GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
} else if (S_ISREG(inode->i_mode)) { } else if (S_ISREG(inode->i_mode)) {
inode->i_op = &f2fs_file_inode_operations; inode->i_op = &f2fs_file_inode_operations;
inode->i_fop = &f2fs_file_operations; inode->i_fop = &f2fs_file_operations;
...@@ -646,7 +661,7 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page) ...@@ -646,7 +661,7 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)
/* deleted inode */ /* deleted inode */
if (inode->i_nlink == 0) if (inode->i_nlink == 0)
clear_inline_node(node_page); clear_page_private_inline(node_page);
F2FS_I(inode)->i_disk_time[0] = inode->i_atime; F2FS_I(inode)->i_disk_time[0] = inode->i_atime;
F2FS_I(inode)->i_disk_time[1] = inode->i_ctime; F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
...@@ -723,8 +738,12 @@ void f2fs_evict_inode(struct inode *inode) ...@@ -723,8 +738,12 @@ void f2fs_evict_inode(struct inode *inode)
trace_f2fs_evict_inode(inode); trace_f2fs_evict_inode(inode);
truncate_inode_pages_final(&inode->i_data); truncate_inode_pages_final(&inode->i_data);
if (test_opt(sbi, COMPRESS_CACHE) && f2fs_compressed_file(inode))
f2fs_invalidate_compress_pages(sbi, inode->i_ino);
if (inode->i_ino == F2FS_NODE_INO(sbi) || if (inode->i_ino == F2FS_NODE_INO(sbi) ||
inode->i_ino == F2FS_META_INO(sbi)) inode->i_ino == F2FS_META_INO(sbi) ||
inode->i_ino == F2FS_COMPRESS_INO(sbi))
goto out_clear; goto out_clear;
f2fs_bug_on(sbi, get_dirty_pages(inode)); f2fs_bug_on(sbi, get_dirty_pages(inode));
......
...@@ -153,7 +153,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) ...@@ -153,7 +153,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
return ERR_PTR(err); return ERR_PTR(err);
} }
static inline int is_extension_exist(const unsigned char *s, const char *sub) static inline int is_extension_exist(const unsigned char *s, const char *sub,
bool tmp_ext)
{ {
size_t slen = strlen(s); size_t slen = strlen(s);
size_t sublen = strlen(sub); size_t sublen = strlen(sub);
...@@ -169,6 +170,13 @@ static inline int is_extension_exist(const unsigned char *s, const char *sub) ...@@ -169,6 +170,13 @@ static inline int is_extension_exist(const unsigned char *s, const char *sub)
if (slen < sublen + 2) if (slen < sublen + 2)
return 0; return 0;
if (!tmp_ext) {
/* file has no temp extension */
if (s[slen - sublen - 1] != '.')
return 0;
return !strncasecmp(s + slen - sublen, sub, sublen);
}
for (i = 1; i < slen - sublen; i++) { for (i = 1; i < slen - sublen; i++) {
if (s[i] != '.') if (s[i] != '.')
continue; continue;
...@@ -194,7 +202,7 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * ...@@ -194,7 +202,7 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *
hot_count = sbi->raw_super->hot_ext_count; hot_count = sbi->raw_super->hot_ext_count;
for (i = 0; i < cold_count + hot_count; i++) { for (i = 0; i < cold_count + hot_count; i++) {
if (is_extension_exist(name, extlist[i])) if (is_extension_exist(name, extlist[i], true))
break; break;
} }
...@@ -279,14 +287,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -279,14 +287,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
const unsigned char *name) const unsigned char *name)
{ {
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
unsigned char (*ext)[F2FS_EXTENSION_LEN]; unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions;
unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions;
unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
int i, cold_count, hot_count; int i, cold_count, hot_count;
if (!f2fs_sb_has_compression(sbi) || if (!f2fs_sb_has_compression(sbi) ||
is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
!f2fs_may_compress(inode)) !f2fs_may_compress(inode) ||
(!ext_cnt && !noext_cnt))
return; return;
down_read(&sbi->sb_lock); down_read(&sbi->sb_lock);
...@@ -295,7 +305,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -295,7 +305,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
hot_count = sbi->raw_super->hot_ext_count; hot_count = sbi->raw_super->hot_ext_count;
for (i = cold_count; i < cold_count + hot_count; i++) { for (i = cold_count; i < cold_count + hot_count; i++) {
if (is_extension_exist(name, extlist[i])) { if (is_extension_exist(name, extlist[i], false)) {
up_read(&sbi->sb_lock); up_read(&sbi->sb_lock);
return; return;
} }
...@@ -303,10 +313,18 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -303,10 +313,18 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
up_read(&sbi->sb_lock); up_read(&sbi->sb_lock);
ext = F2FS_OPTION(sbi).extensions; for (i = 0; i < noext_cnt; i++) {
if (is_extension_exist(name, noext[i], false)) {
f2fs_disable_compressed_file(inode);
return;
}
}
if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
return;
for (i = 0; i < ext_cnt; i++) { for (i = 0; i < ext_cnt; i++) {
if (!is_extension_exist(name, ext[i])) if (!is_extension_exist(name, ext[i], false))
continue; continue;
set_compress_context(inode); set_compress_context(inode);
......
...@@ -97,6 +97,20 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) ...@@ -97,6 +97,20 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
mem_size = (atomic_read(&dcc->discard_cmd_cnt) * mem_size = (atomic_read(&dcc->discard_cmd_cnt) *
sizeof(struct discard_cmd)) >> PAGE_SHIFT; sizeof(struct discard_cmd)) >> PAGE_SHIFT;
res = mem_size < (avail_ram * nm_i->ram_thresh / 100); res = mem_size < (avail_ram * nm_i->ram_thresh / 100);
} else if (type == COMPRESS_PAGE) {
#ifdef CONFIG_F2FS_FS_COMPRESSION
unsigned long free_ram = val.freeram;
/*
* free memory is lower than watermark or cached page count
* exceed threshold, deny caching compress page.
*/
res = (free_ram > avail_ram * sbi->compress_watermark / 100) &&
(COMPRESS_MAPPING(sbi)->nrpages <
free_ram * sbi->compress_percent / 100);
#else
res = false;
#endif
} else { } else {
if (!sbi->sb->s_bdi->wb.dirty_exceeded) if (!sbi->sb->s_bdi->wb.dirty_exceeded)
return true; return true;
...@@ -1535,14 +1549,11 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, ...@@ -1535,14 +1549,11 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted,
trace_f2fs_writepage(page, NODE); trace_f2fs_writepage(page, NODE);
if (unlikely(f2fs_cp_error(sbi))) { if (unlikely(f2fs_cp_error(sbi))) {
if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) {
ClearPageUptodate(page); ClearPageUptodate(page);
dec_page_count(sbi, F2FS_DIRTY_NODES); dec_page_count(sbi, F2FS_DIRTY_NODES);
unlock_page(page); unlock_page(page);
return 0; return 0;
} }
goto redirty_out;
}
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
goto redirty_out; goto redirty_out;
...@@ -1860,8 +1871,8 @@ void f2fs_flush_inline_data(struct f2fs_sb_info *sbi) ...@@ -1860,8 +1871,8 @@ void f2fs_flush_inline_data(struct f2fs_sb_info *sbi)
} }
/* flush inline_data, if it's async context. */ /* flush inline_data, if it's async context. */
if (is_inline_node(page)) { if (page_private_inline(page)) {
clear_inline_node(page); clear_page_private_inline(page);
unlock_page(page); unlock_page(page);
flush_inline_data(sbi, ino_of_node(page)); flush_inline_data(sbi, ino_of_node(page));
continue; continue;
...@@ -1941,8 +1952,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, ...@@ -1941,8 +1952,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
goto write_node; goto write_node;
/* flush inline_data */ /* flush inline_data */
if (is_inline_node(page)) { if (page_private_inline(page)) {
clear_inline_node(page); clear_page_private_inline(page);
unlock_page(page); unlock_page(page);
flush_inline_data(sbi, ino_of_node(page)); flush_inline_data(sbi, ino_of_node(page));
goto lock_node; goto lock_node;
...@@ -2096,7 +2107,7 @@ static int f2fs_set_node_page_dirty(struct page *page) ...@@ -2096,7 +2107,7 @@ static int f2fs_set_node_page_dirty(struct page *page)
if (!PageDirty(page)) { if (!PageDirty(page)) {
__set_page_dirty_nobuffers(page); __set_page_dirty_nobuffers(page);
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES); inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES);
f2fs_set_page_private(page, 0); set_page_private_reference(page);
return 1; return 1;
} }
return 0; return 0;
......
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
/* return value for read_node_page */ /* return value for read_node_page */
#define LOCKED_PAGE 1 #define LOCKED_PAGE 1
/* check pinned file's alignment status of physical blocks */
#define FILE_NOT_ALIGNED 1
/* For flag in struct node_info */ /* For flag in struct node_info */
enum { enum {
IS_CHECKPOINTED, /* is it checkpointed before? */ IS_CHECKPOINTED, /* is it checkpointed before? */
...@@ -148,6 +151,7 @@ enum mem_type { ...@@ -148,6 +151,7 @@ enum mem_type {
EXTENT_CACHE, /* indicates extent cache */ EXTENT_CACHE, /* indicates extent cache */
INMEM_PAGES, /* indicates inmemory pages */ INMEM_PAGES, /* indicates inmemory pages */
DISCARD_CACHE, /* indicates memory of cached discard cmds */ DISCARD_CACHE, /* indicates memory of cached discard cmds */
COMPRESS_PAGE, /* indicates memory of cached compressed pages */
BASE_CHECK, /* check kernel status */ BASE_CHECK, /* check kernel status */
}; };
...@@ -389,20 +393,6 @@ static inline nid_t get_nid(struct page *p, int off, bool i) ...@@ -389,20 +393,6 @@ static inline nid_t get_nid(struct page *p, int off, bool i)
* - Mark cold node blocks in their node footer * - Mark cold node blocks in their node footer
* - Mark cold data pages in page cache * - Mark cold data pages in page cache
*/ */
static inline int is_cold_data(struct page *page)
{
return PageChecked(page);
}
static inline void set_cold_data(struct page *page)
{
SetPageChecked(page);
}
static inline void clear_cold_data(struct page *page)
{
ClearPageChecked(page);
}
static inline int is_node(struct page *page, int type) static inline int is_node(struct page *page, int type)
{ {
...@@ -414,21 +404,6 @@ static inline int is_node(struct page *page, int type) ...@@ -414,21 +404,6 @@ static inline int is_node(struct page *page, int type)
#define is_fsync_dnode(page) is_node(page, FSYNC_BIT_SHIFT) #define is_fsync_dnode(page) is_node(page, FSYNC_BIT_SHIFT)
#define is_dent_dnode(page) is_node(page, DENT_BIT_SHIFT) #define is_dent_dnode(page) is_node(page, DENT_BIT_SHIFT)
static inline int is_inline_node(struct page *page)
{
return PageChecked(page);
}
static inline void set_inline_node(struct page *page)
{
SetPageChecked(page);
}
static inline void clear_inline_node(struct page *page)
{
ClearPageChecked(page);
}
static inline void set_cold_node(struct page *page, bool is_dir) static inline void set_cold_node(struct page *page, bool is_dir)
{ {
struct f2fs_node *rn = F2FS_NODE(page); struct f2fs_node *rn = F2FS_NODE(page);
......
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
static struct kmem_cache *fsync_entry_slab; static struct kmem_cache *fsync_entry_slab;
#ifdef CONFIG_UNICODE
extern struct kmem_cache *f2fs_cf_name_slab;
#endif
bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi) bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi)
{ {
s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count); s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count);
...@@ -145,7 +149,7 @@ static int init_recovered_filename(const struct inode *dir, ...@@ -145,7 +149,7 @@ static int init_recovered_filename(const struct inode *dir,
f2fs_hash_filename(dir, fname); f2fs_hash_filename(dir, fname);
#ifdef CONFIG_UNICODE #ifdef CONFIG_UNICODE
/* Case-sensitive match is fine for recovery */ /* Case-sensitive match is fine for recovery */
kfree(fname->cf_name.name); kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
fname->cf_name.name = NULL; fname->cf_name.name = NULL;
#endif #endif
} else { } else {
...@@ -788,13 +792,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) ...@@ -788,13 +792,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY); quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
#endif #endif
fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry",
sizeof(struct fsync_inode_entry));
if (!fsync_entry_slab) {
err = -ENOMEM;
goto out;
}
INIT_LIST_HEAD(&inode_list); INIT_LIST_HEAD(&inode_list);
INIT_LIST_HEAD(&tmp_inode_list); INIT_LIST_HEAD(&tmp_inode_list);
INIT_LIST_HEAD(&dir_list); INIT_LIST_HEAD(&dir_list);
...@@ -867,8 +864,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) ...@@ -867,8 +864,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
} }
} }
kmem_cache_destroy(fsync_entry_slab);
out:
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
/* Turn quotas off */ /* Turn quotas off */
if (quota_enabled) if (quota_enabled)
...@@ -878,3 +873,17 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) ...@@ -878,3 +873,17 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
return ret ? ret : err; return ret ? ret : err;
} }
int __init f2fs_create_recovery_cache(void)
{
fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry",
sizeof(struct fsync_inode_entry));
if (!fsync_entry_slab)
return -ENOMEM;
return 0;
}
void f2fs_destroy_recovery_cache(void)
{
kmem_cache_destroy(fsync_entry_slab);
}
...@@ -186,10 +186,7 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page) ...@@ -186,10 +186,7 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page)
{ {
struct inmem_pages *new; struct inmem_pages *new;
if (PagePrivate(page)) set_page_private_atomic(page);
set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE);
else
f2fs_set_page_private(page, ATOMIC_WRITTEN_PAGE);
new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS); new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
...@@ -272,9 +269,10 @@ static int __revoke_inmem_pages(struct inode *inode, ...@@ -272,9 +269,10 @@ static int __revoke_inmem_pages(struct inode *inode,
/* we don't need to invalidate this in the sccessful status */ /* we don't need to invalidate this in the sccessful status */
if (drop || recover) { if (drop || recover) {
ClearPageUptodate(page); ClearPageUptodate(page);
clear_cold_data(page); clear_page_private_gcing(page);
} }
f2fs_clear_page_private(page); detach_page_private(page);
set_page_private(page, 0);
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
list_del(&cur->list); list_del(&cur->list);
...@@ -357,7 +355,7 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page) ...@@ -357,7 +355,7 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)
struct list_head *head = &fi->inmem_pages; struct list_head *head = &fi->inmem_pages;
struct inmem_pages *cur = NULL; struct inmem_pages *cur = NULL;
f2fs_bug_on(sbi, !IS_ATOMIC_WRITTEN_PAGE(page)); f2fs_bug_on(sbi, !page_private_atomic(page));
mutex_lock(&fi->inmem_lock); mutex_lock(&fi->inmem_lock);
list_for_each_entry(cur, head, list) { list_for_each_entry(cur, head, list) {
...@@ -373,9 +371,12 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page) ...@@ -373,9 +371,12 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)
kmem_cache_free(inmem_entry_slab, cur); kmem_cache_free(inmem_entry_slab, cur);
ClearPageUptodate(page); ClearPageUptodate(page);
f2fs_clear_page_private(page); clear_page_private_atomic(page);
f2fs_put_page(page, 0); f2fs_put_page(page, 0);
detach_page_private(page);
set_page_private(page, 0);
trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE); trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE);
} }
...@@ -2321,6 +2322,7 @@ void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr) ...@@ -2321,6 +2322,7 @@ void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
return; return;
invalidate_mapping_pages(META_MAPPING(sbi), addr, addr); invalidate_mapping_pages(META_MAPPING(sbi), addr, addr);
f2fs_invalidate_compress_page(sbi, addr);
/* add it into sit main buffer */ /* add it into sit main buffer */
down_write(&sit_i->sentry_lock); down_write(&sit_i->sentry_lock);
...@@ -3289,7 +3291,10 @@ static int __get_segment_type_6(struct f2fs_io_info *fio) ...@@ -3289,7 +3291,10 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (fio->type == DATA) { if (fio->type == DATA) {
struct inode *inode = fio->page->mapping->host; struct inode *inode = fio->page->mapping->host;
if (is_cold_data(fio->page)) { if (is_inode_flag_set(inode, FI_ALIGNED_WRITE))
return CURSEG_COLD_DATA_PINNED;
if (page_private_gcing(fio->page)) {
if (fio->sbi->am.atgc_enabled && if (fio->sbi->am.atgc_enabled &&
(fio->io_type == FS_DATA_IO) && (fio->io_type == FS_DATA_IO) &&
(fio->sbi->gc_mode != GC_URGENT_HIGH)) (fio->sbi->gc_mode != GC_URGENT_HIGH))
...@@ -3468,9 +3473,11 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) ...@@ -3468,9 +3473,11 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
reallocate: reallocate:
f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr,
&fio->new_blkaddr, sum, type, fio); &fio->new_blkaddr, sum, type, fio);
if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO) if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO) {
invalidate_mapping_pages(META_MAPPING(fio->sbi), invalidate_mapping_pages(META_MAPPING(fio->sbi),
fio->old_blkaddr, fio->old_blkaddr); fio->old_blkaddr, fio->old_blkaddr);
f2fs_invalidate_compress_page(fio->sbi, fio->old_blkaddr);
}
/* writeout dirty page into bdev */ /* writeout dirty page into bdev */
f2fs_submit_page_write(fio); f2fs_submit_page_write(fio);
...@@ -3660,6 +3667,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -3660,6 +3667,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) { if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) {
invalidate_mapping_pages(META_MAPPING(sbi), invalidate_mapping_pages(META_MAPPING(sbi),
old_blkaddr, old_blkaddr); old_blkaddr, old_blkaddr);
f2fs_invalidate_compress_page(sbi, old_blkaddr);
if (!from_gc) if (!from_gc)
update_segment_mtime(sbi, old_blkaddr, 0); update_segment_mtime(sbi, old_blkaddr, 0);
update_sit_entry(sbi, old_blkaddr, -1); update_sit_entry(sbi, old_blkaddr, -1);
...@@ -3919,7 +3927,7 @@ static int restore_curseg_summaries(struct f2fs_sb_info *sbi) ...@@ -3919,7 +3927,7 @@ static int restore_curseg_summaries(struct f2fs_sb_info *sbi)
/* sanity check for summary blocks */ /* sanity check for summary blocks */
if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES || if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES ||
sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES) { sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES) {
f2fs_err(sbi, "invalid journal entries nats %u sits %u\n", f2fs_err(sbi, "invalid journal entries nats %u sits %u",
nats_in_cursum(nat_j), sits_in_cursum(sit_j)); nats_in_cursum(nat_j), sits_in_cursum(sit_j));
return -EINVAL; return -EINVAL;
} }
...@@ -4682,6 +4690,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi) ...@@ -4682,6 +4690,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
struct seg_entry *se = get_seg_entry(sbi, curseg->segno); struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
unsigned int blkofs = curseg->next_blkoff; unsigned int blkofs = curseg->next_blkoff;
if (f2fs_sb_has_readonly(sbi) &&
i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
continue;
sanity_check_seg_type(sbi, curseg->seg_type); sanity_check_seg_type(sbi, curseg->seg_type);
if (f2fs_test_bit(blkofs, se->cur_valid_map)) if (f2fs_test_bit(blkofs, se->cur_valid_map))
......
This diff is collapsed.
This diff is collapsed.
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define F2FS_ROOT_INO(sbi) ((sbi)->root_ino_num) #define F2FS_ROOT_INO(sbi) ((sbi)->root_ino_num)
#define F2FS_NODE_INO(sbi) ((sbi)->node_ino_num) #define F2FS_NODE_INO(sbi) ((sbi)->node_ino_num)
#define F2FS_META_INO(sbi) ((sbi)->meta_ino_num) #define F2FS_META_INO(sbi) ((sbi)->meta_ino_num)
#define F2FS_COMPRESS_INO(sbi) (NM_I(sbi)->max_nid)
#define F2FS_MAX_QUOTAS 3 #define F2FS_MAX_QUOTAS 3
...@@ -229,6 +230,7 @@ struct f2fs_extent { ...@@ -229,6 +230,7 @@ struct f2fs_extent {
#define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */ #define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */
#define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */ #define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */
#define F2FS_PIN_FILE 0x40 /* file should not be gced */ #define F2FS_PIN_FILE 0x40 /* file should not be gced */
#define F2FS_COMPRESS_RELEASED 0x80 /* file released compressed blocks */
struct f2fs_inode { struct f2fs_inode {
__le16 i_mode; /* file mode */ __le16 i_mode; /* file mode */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment