Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+1170 -497
+56 -1
Documentation/ABI/testing/sysfs-fs-f2fs
··· 203 203 What: /sys/fs/f2fs/<disk>/features 204 204 Date: July 2017 205 205 Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 206 - Description: Shows all enabled features in current device. 206 + Description: <deprecated: should use /sys/fs/f2fs/<disk>/feature_list/ 207 + Shows all enabled features in current device. 208 + Supported features: 209 + encryption, blkzoned, extra_attr, projquota, inode_checksum, 210 + flexible_inline_xattr, quota_ino, inode_crtime, lost_found, 211 + verity, sb_checksum, casefold, readonly, compression, pin_file. 212 + 213 + What: /sys/fs/f2fs/<disk>/feature_list/ 214 + Date: June 2021 215 + Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 216 + Description: Expand /sys/fs/f2fs/<disk>/features to meet sysfs rule. 217 + Supported on-disk features: 218 + encryption, block_zoned (aka blkzoned), extra_attr, 219 + project_quota (aka projquota), inode_checksum, 220 + flexible_inline_xattr, quota_ino, inode_crtime, lost_found, 221 + verity, sb_checksum, casefold, readonly, compression. 222 + Note that, pin_file is moved into /sys/fs/f2fs/features/. 223 + 224 + What: /sys/fs/f2fs/features/ 225 + Date: July 2017 226 + Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 227 + Description: Shows all enabled kernel features. 228 + Supported features: 229 + encryption, block_zoned, extra_attr, project_quota, 230 + inode_checksum, flexible_inline_xattr, quota_ino, 231 + inode_crtime, lost_found, verity, sb_checksum, 232 + casefold, readonly, compression, test_dummy_encryption_v2, 233 + atomic_write, pin_file, encrypted_casefold. 207 234 208 235 What: /sys/fs/f2fs/<disk>/inject_rate 209 236 Date: May 2016 ··· 465 438 Note that when the compression is disabled for the files, this count 466 439 doesn't decrease. If you write "0" here, you can initialize 467 440 compr_new_inode to "0". 441 + 442 + What: /sys/fs/f2fs/<disk>/atgc_candidate_ratio 443 + Date: May 2021 444 + Contact: "Chao Yu" <yuchao0@huawei.com> 445 + Description: When ATGC is on, it controls candidate ratio in order to limit total 446 + number of potential victim in all candidates, the value should be in 447 + range of [0, 100], by default it was initialized as 20(%). 448 + 449 + What: /sys/fs/f2fs/<disk>/atgc_candidate_count 450 + Date: May 2021 451 + Contact: "Chao Yu" <yuchao0@huawei.com> 452 + Description: When ATGC is on, it controls candidate count in order to limit total 453 + number of potential victim in all candidates, by default it was 454 + initialized as 10 (sections). 455 + 456 + What: /sys/fs/f2fs/<disk>/atgc_age_weight 457 + Date: May 2021 458 + Contact: "Chao Yu" <yuchao0@huawei.com> 459 + Description: When ATGC is on, it controls age weight to balance weight proportion 460 + in between aging and valid blocks, the value should be in range of 461 + [0, 100], by default it was initialized as 60(%). 462 + 463 + What: /sys/fs/f2fs/<disk>/atgc_age_threshold 464 + Date: May 2021 465 + Contact: "Chao Yu" <yuchao0@huawei.com> 466 + Description: When ATGC is on, it controls age threshold to bypass GCing young 467 + candidates whose age is not beyond the threshold, by default it was 468 + initialized as 604800 seconds (equals to 7 days).
+41 -9
Documentation/filesystems/f2fs.rst
··· 281 281 For other files, we can still enable compression via ioctl. 282 282 Note that, there is one reserved special extension '*', it 283 283 can be set to enable compression for all files. 284 + nocompress_extension=%s Support adding specified extension, so that f2fs can disable 285 + compression on those corresponding files, just contrary to compression extension. 286 + If you know exactly which files cannot be compressed, you can use this. 287 + The same extension name can't appear in both compress and nocompress 288 + extension at the same time. 289 + If the compress extension specifies all files, the types specified by the 290 + nocompress extension will be treated as special cases and will not be compressed. 291 + Don't allow use '*' to specifie all file in nocompress extension. 292 + After add nocompress_extension, the priority should be: 293 + dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag. 294 + See more in compression sections. 295 + 284 296 compress_chksum Support verifying chksum of raw data in compressed cluster. 285 297 compress_mode=%s Control file compression mode. This supports "fs" and "user" 286 298 modes. In "fs" mode (default), f2fs does automatic compression ··· 301 289 choosing the target file and the timing. The user can do manual 302 290 compression/decompression on the compression enabled files using 303 291 ioctls. 292 + compress_cache Support to use address space of a filesystem managed inode to 293 + cache compressed block, in order to improve cache hit ratio of 294 + random read. 304 295 inlinecrypt When possible, encrypt/decrypt the contents of encrypted 305 296 files using the blk-crypto framework rather than 306 297 filesystem-layer encryption. This allows the use of ··· 732 717 ===================== ======================== =================== 733 718 User F2FS Block 734 719 ===================== ======================== =================== 735 - META WRITE_LIFE_NOT_SET 736 - HOT_NODE " 737 - WARM_NODE " 738 - COLD_NODE " 720 + N/A META WRITE_LIFE_NOT_SET 721 + N/A HOT_NODE " 722 + N/A WARM_NODE " 723 + N/A COLD_NODE " 739 724 ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME 740 725 extension list " " 741 726 ··· 761 746 ===================== ======================== =================== 762 747 User F2FS Block 763 748 ===================== ======================== =================== 764 - META WRITE_LIFE_MEDIUM; 765 - HOT_NODE WRITE_LIFE_NOT_SET 766 - WARM_NODE " 767 - COLD_NODE WRITE_LIFE_NONE 749 + N/A META WRITE_LIFE_MEDIUM; 750 + N/A HOT_NODE WRITE_LIFE_NOT_SET 751 + N/A WARM_NODE " 752 + N/A COLD_NODE WRITE_LIFE_NONE 768 753 ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME 769 754 extension list " " 770 755 ··· 829 814 all logical blocks in cluster contain valid data and compress ratio of 830 815 cluster data is lower than specified threshold. 831 816 832 - - To enable compression on regular inode, there are three ways: 817 + - To enable compression on regular inode, there are four ways: 833 818 834 819 * chattr +c file 835 820 * chattr +c dir; touch dir/file 836 821 * mount w/ -o compress_extension=ext; touch file.ext 837 822 * mount w/ -o compress_extension=*; touch any_file 823 + 824 + - To disable compression on regular inode, there are two ways: 825 + 826 + * chattr -c file 827 + * mount w/ -o nocompress_extension=ext; touch file.ext 828 + 829 + - Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions: 830 + 831 + * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch 832 + dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt 833 + should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip 834 + can enable compress on bar.zip. 835 + * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch 836 + dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be 837 + compresse, bar.zip and baz.txt should be non-compressed. 838 + chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip 839 + and baz.txt. 838 840 839 841 - At this point, compression feature doesn't expose compressed space to user 840 842 directly in order to guarantee potential data updates later to the space.
+1 -1
MAINTAINERS
··· 7010 7010 7011 7011 F2FS FILE SYSTEM 7012 7012 M: Jaegeuk Kim <jaegeuk@kernel.org> 7013 - M: Chao Yu <yuchao0@huawei.com> 7013 + M: Chao Yu <chao@kernel.org> 7014 7014 L: linux-f2fs-devel@lists.sourceforge.net 7015 7015 S: Maintained 7016 7016 W: https://f2fs.wiki.kernel.org/
+2 -2
fs/f2fs/checkpoint.c
··· 444 444 if (!PageDirty(page)) { 445 445 __set_page_dirty_nobuffers(page); 446 446 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META); 447 - f2fs_set_page_private(page, 0); 447 + set_page_private_reference(page); 448 448 return 1; 449 449 } 450 450 return 0; ··· 1018 1018 inode_inc_dirty_pages(inode); 1019 1019 spin_unlock(&sbi->inode_lock[type]); 1020 1020 1021 - f2fs_set_page_private(page, 0); 1021 + set_page_private_reference(page); 1022 1022 } 1023 1023 1024 1024 void f2fs_remove_dirty_inode(struct inode *inode)
+197 -58
fs/f2fs/compress.c
··· 12 12 #include <linux/lzo.h> 13 13 #include <linux/lz4.h> 14 14 #include <linux/zstd.h> 15 + #include <linux/pagevec.h> 15 16 16 17 #include "f2fs.h" 17 18 #include "node.h" 19 + #include "segment.h" 18 20 #include <trace/events/f2fs.h> 19 21 20 22 static struct kmem_cache *cic_entry_slab; ··· 76 74 return false; 77 75 if (!page_private(page)) 78 76 return false; 79 - if (IS_ATOMIC_WRITTEN_PAGE(page) || IS_DUMMY_WRITTEN_PAGE(page)) 77 + if (page_private_nonpointer(page)) 80 78 return false; 81 79 82 80 f2fs_bug_on(F2FS_M_SB(page->mapping), ··· 87 85 static void f2fs_set_compressed_page(struct page *page, 88 86 struct inode *inode, pgoff_t index, void *data) 89 87 { 90 - SetPagePrivate(page); 91 - set_page_private(page, (unsigned long)data); 88 + attach_page_private(page, (void *)data); 92 89 93 90 /* i_crypto_info and iv index */ 94 91 page->index = index; ··· 590 589 { 591 590 if (!page) 592 591 return; 593 - set_page_private(page, (unsigned long)NULL); 594 - ClearPagePrivate(page); 592 + detach_page_private(page); 595 593 page->mapping = NULL; 596 594 unlock_page(page); 597 595 mempool_free(page, compress_page_pool); ··· 738 738 return ret; 739 739 } 740 740 741 - static void f2fs_decompress_cluster(struct decompress_io_ctx *dic) 741 + void f2fs_decompress_cluster(struct decompress_io_ctx *dic) 742 742 { 743 743 struct f2fs_sb_info *sbi = F2FS_I_SB(dic->inode); 744 744 struct f2fs_inode_info *fi = F2FS_I(dic->inode); ··· 837 837 * page being waited on in the cluster, and if so, it decompresses the cluster 838 838 * (or in the case of a failure, cleans up without actually decompressing). 839 839 */ 840 - void f2fs_end_read_compressed_page(struct page *page, bool failed) 840 + void f2fs_end_read_compressed_page(struct page *page, bool failed, 841 + block_t blkaddr) 841 842 { 842 843 struct decompress_io_ctx *dic = 843 844 (struct decompress_io_ctx *)page_private(page); ··· 848 847 849 848 if (failed) 850 849 WRITE_ONCE(dic->failed, true); 850 + else if (blkaddr) 851 + f2fs_cache_compressed_page(sbi, page, 852 + dic->inode->i_ino, blkaddr); 851 853 852 854 if (atomic_dec_and_test(&dic->remaining_pages)) 853 855 f2fs_decompress_cluster(dic); ··· 880 876 return is_page_in_cluster(cc, index); 881 877 } 882 878 883 - static bool __cluster_may_compress(struct compress_ctx *cc) 879 + static bool cluster_has_invalid_data(struct compress_ctx *cc) 884 880 { 885 881 loff_t i_size = i_size_read(cc->inode); 886 882 unsigned nr_pages = DIV_ROUND_UP(i_size, PAGE_SIZE); ··· 893 889 894 890 /* beyond EOF */ 895 891 if (page->index >= nr_pages) 896 - return false; 892 + return true; 897 893 } 898 - return true; 894 + return false; 899 895 } 900 896 901 - static int __f2fs_cluster_blocks(struct compress_ctx *cc, bool compr) 897 + static int __f2fs_cluster_blocks(struct inode *inode, 898 + unsigned int cluster_idx, bool compr) 902 899 { 903 900 struct dnode_of_data dn; 901 + unsigned int cluster_size = F2FS_I(inode)->i_cluster_size; 902 + unsigned int start_idx = cluster_idx << 903 + F2FS_I(inode)->i_log_cluster_size; 904 904 int ret; 905 905 906 - set_new_dnode(&dn, cc->inode, NULL, NULL, 0); 907 - ret = f2fs_get_dnode_of_data(&dn, start_idx_of_cluster(cc), 908 - LOOKUP_NODE); 906 + set_new_dnode(&dn, inode, NULL, NULL, 0); 907 + ret = f2fs_get_dnode_of_data(&dn, start_idx, LOOKUP_NODE); 909 908 if (ret) { 910 909 if (ret == -ENOENT) 911 910 ret = 0; ··· 919 912 int i; 920 913 921 914 ret = 1; 922 - for (i = 1; i < cc->cluster_size; i++) { 915 + for (i = 1; i < cluster_size; i++) { 923 916 block_t blkaddr; 924 917 925 918 blkaddr = data_blkaddr(dn.inode, ··· 932 925 ret++; 933 926 } 934 927 } 928 + 929 + f2fs_bug_on(F2FS_I_SB(inode), 930 + !compr && ret != cluster_size && 931 + !is_inode_flag_set(inode, FI_COMPRESS_RELEASED)); 935 932 } 936 933 fail: 937 934 f2fs_put_dnode(&dn); ··· 945 934 /* return # of compressed blocks in compressed cluster */ 946 935 static int f2fs_compressed_blocks(struct compress_ctx *cc) 947 936 { 948 - return __f2fs_cluster_blocks(cc, true); 937 + return __f2fs_cluster_blocks(cc->inode, cc->cluster_idx, true); 949 938 } 950 939 951 940 /* return # of valid blocks in compressed cluster */ 952 - static int f2fs_cluster_blocks(struct compress_ctx *cc) 953 - { 954 - return __f2fs_cluster_blocks(cc, false); 955 - } 956 - 957 941 int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index) 958 942 { 959 - struct compress_ctx cc = { 960 - .inode = inode, 961 - .log_cluster_size = F2FS_I(inode)->i_log_cluster_size, 962 - .cluster_size = F2FS_I(inode)->i_cluster_size, 963 - .cluster_idx = index >> F2FS_I(inode)->i_log_cluster_size, 964 - }; 965 - 966 - return f2fs_cluster_blocks(&cc); 943 + return __f2fs_cluster_blocks(inode, 944 + index >> F2FS_I(inode)->i_log_cluster_size, 945 + false); 967 946 } 968 947 969 948 static bool cluster_may_compress(struct compress_ctx *cc) ··· 962 961 return false; 963 962 if (f2fs_is_atomic_file(cc->inode)) 964 963 return false; 965 - if (f2fs_is_mmap_file(cc->inode)) 966 - return false; 967 964 if (!f2fs_cluster_is_full(cc)) 968 965 return false; 969 966 if (unlikely(f2fs_cp_error(F2FS_I_SB(cc->inode)))) 970 967 return false; 971 - return __cluster_may_compress(cc); 968 + return !cluster_has_invalid_data(cc); 972 969 } 973 970 974 971 static void set_cluster_writeback(struct compress_ctx *cc) ··· 994 995 struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode); 995 996 struct address_space *mapping = cc->inode->i_mapping; 996 997 struct page *page; 997 - struct dnode_of_data dn; 998 998 sector_t last_block_in_bio; 999 999 unsigned fgp_flag = FGP_LOCK | FGP_WRITE | FGP_CREAT; 1000 1000 pgoff_t start_idx = start_idx_of_cluster(cc); 1001 1001 int i, ret; 1002 - bool prealloc; 1003 1002 1004 1003 retry: 1005 - ret = f2fs_cluster_blocks(cc); 1004 + ret = f2fs_is_compressed_cluster(cc->inode, start_idx); 1006 1005 if (ret <= 0) 1007 1006 return ret; 1008 - 1009 - /* compressed case */ 1010 - prealloc = (ret < cc->cluster_size); 1011 1007 1012 1008 ret = f2fs_init_compress_ctx(cc); 1013 1009 if (ret) ··· 1059 1065 f2fs_destroy_compress_ctx(cc, true); 1060 1066 goto retry; 1061 1067 } 1062 - } 1063 - 1064 - if (prealloc) { 1065 - f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); 1066 - 1067 - set_new_dnode(&dn, cc->inode, NULL, NULL, 0); 1068 - 1069 - for (i = cc->cluster_size - 1; i > 0; i--) { 1070 - ret = f2fs_get_block(&dn, start_idx + i); 1071 - if (ret) { 1072 - i = cc->cluster_size; 1073 - break; 1074 - } 1075 - 1076 - if (dn.data_blkaddr != NEW_ADDR) 1077 - break; 1078 - } 1079 - 1080 - f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); 1081 1068 } 1082 1069 1083 1070 if (likely(!ret)) { ··· 1190 1215 unsigned int last_index = cc->cluster_size - 1; 1191 1216 loff_t psize; 1192 1217 int i, err; 1218 + 1219 + /* we should bypass data pages to proceed the kworkder jobs */ 1220 + if (unlikely(f2fs_cp_error(sbi))) { 1221 + mapping_set_error(cc->rpages[0]->mapping, -EIO); 1222 + goto out_free; 1223 + } 1193 1224 1194 1225 if (IS_NOQUOTA(inode)) { 1195 1226 /* ··· 1380 1399 1381 1400 for (i = 0; i < cic->nr_rpages; i++) { 1382 1401 WARN_ON(!cic->rpages[i]); 1383 - clear_cold_data(cic->rpages[i]); 1402 + clear_page_private_gcing(cic->rpages[i]); 1384 1403 end_page_writeback(cic->rpages[i]); 1385 1404 } 1386 1405 ··· 1664 1683 (struct decompress_io_ctx *)page_private(page); 1665 1684 1666 1685 f2fs_put_dic(dic); 1686 + } 1687 + 1688 + const struct address_space_operations f2fs_compress_aops = { 1689 + .releasepage = f2fs_release_page, 1690 + .invalidatepage = f2fs_invalidate_page, 1691 + }; 1692 + 1693 + struct address_space *COMPRESS_MAPPING(struct f2fs_sb_info *sbi) 1694 + { 1695 + return sbi->compress_inode->i_mapping; 1696 + } 1697 + 1698 + void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkaddr) 1699 + { 1700 + if (!sbi->compress_inode) 1701 + return; 1702 + invalidate_mapping_pages(COMPRESS_MAPPING(sbi), blkaddr, blkaddr); 1703 + } 1704 + 1705 + void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 1706 + nid_t ino, block_t blkaddr) 1707 + { 1708 + struct page *cpage; 1709 + int ret; 1710 + 1711 + if (!test_opt(sbi, COMPRESS_CACHE)) 1712 + return; 1713 + 1714 + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE_READ)) 1715 + return; 1716 + 1717 + if (!f2fs_available_free_memory(sbi, COMPRESS_PAGE)) 1718 + return; 1719 + 1720 + cpage = find_get_page(COMPRESS_MAPPING(sbi), blkaddr); 1721 + if (cpage) { 1722 + f2fs_put_page(cpage, 0); 1723 + return; 1724 + } 1725 + 1726 + cpage = alloc_page(__GFP_NOWARN | __GFP_IO); 1727 + if (!cpage) 1728 + return; 1729 + 1730 + ret = add_to_page_cache_lru(cpage, COMPRESS_MAPPING(sbi), 1731 + blkaddr, GFP_NOFS); 1732 + if (ret) { 1733 + f2fs_put_page(cpage, 0); 1734 + return; 1735 + } 1736 + 1737 + set_page_private_data(cpage, ino); 1738 + 1739 + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE_READ)) 1740 + goto out; 1741 + 1742 + memcpy(page_address(cpage), page_address(page), PAGE_SIZE); 1743 + SetPageUptodate(cpage); 1744 + out: 1745 + f2fs_put_page(cpage, 1); 1746 + } 1747 + 1748 + bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 1749 + block_t blkaddr) 1750 + { 1751 + struct page *cpage; 1752 + bool hitted = false; 1753 + 1754 + if (!test_opt(sbi, COMPRESS_CACHE)) 1755 + return false; 1756 + 1757 + cpage = f2fs_pagecache_get_page(COMPRESS_MAPPING(sbi), 1758 + blkaddr, FGP_LOCK | FGP_NOWAIT, GFP_NOFS); 1759 + if (cpage) { 1760 + if (PageUptodate(cpage)) { 1761 + atomic_inc(&sbi->compress_page_hit); 1762 + memcpy(page_address(page), 1763 + page_address(cpage), PAGE_SIZE); 1764 + hitted = true; 1765 + } 1766 + f2fs_put_page(cpage, 1); 1767 + } 1768 + 1769 + return hitted; 1770 + } 1771 + 1772 + void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, nid_t ino) 1773 + { 1774 + struct address_space *mapping = sbi->compress_inode->i_mapping; 1775 + struct pagevec pvec; 1776 + pgoff_t index = 0; 1777 + pgoff_t end = MAX_BLKADDR(sbi); 1778 + 1779 + if (!mapping->nrpages) 1780 + return; 1781 + 1782 + pagevec_init(&pvec); 1783 + 1784 + do { 1785 + unsigned int nr_pages; 1786 + int i; 1787 + 1788 + nr_pages = pagevec_lookup_range(&pvec, mapping, 1789 + &index, end - 1); 1790 + if (!nr_pages) 1791 + break; 1792 + 1793 + for (i = 0; i < nr_pages; i++) { 1794 + struct page *page = pvec.pages[i]; 1795 + 1796 + if (page->index > end) 1797 + break; 1798 + 1799 + lock_page(page); 1800 + if (page->mapping != mapping) { 1801 + unlock_page(page); 1802 + continue; 1803 + } 1804 + 1805 + if (ino != get_page_private_data(page)) { 1806 + unlock_page(page); 1807 + continue; 1808 + } 1809 + 1810 + generic_error_remove_page(mapping, page); 1811 + unlock_page(page); 1812 + } 1813 + pagevec_release(&pvec); 1814 + cond_resched(); 1815 + } while (index < end); 1816 + } 1817 + 1818 + int f2fs_init_compress_inode(struct f2fs_sb_info *sbi) 1819 + { 1820 + struct inode *inode; 1821 + 1822 + if (!test_opt(sbi, COMPRESS_CACHE)) 1823 + return 0; 1824 + 1825 + inode = f2fs_iget(sbi->sb, F2FS_COMPRESS_INO(sbi)); 1826 + if (IS_ERR(inode)) 1827 + return PTR_ERR(inode); 1828 + sbi->compress_inode = inode; 1829 + 1830 + sbi->compress_percent = COMPRESS_PERCENT; 1831 + sbi->compress_watermark = COMPRESS_WATERMARK; 1832 + 1833 + atomic_set(&sbi->compress_page_hit, 0); 1834 + 1835 + return 0; 1836 + } 1837 + 1838 + void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi) 1839 + { 1840 + if (!sbi->compress_inode) 1841 + return; 1842 + iput(sbi->compress_inode); 1843 + sbi->compress_inode = NULL; 1667 1844 } 1668 1845 1669 1846 int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi)
+159 -201
fs/f2fs/data.c
··· 58 58 if (!mapping) 59 59 return false; 60 60 61 - if (f2fs_is_compressed_page(page)) 62 - return false; 63 - 64 61 inode = mapping->host; 65 62 sbi = F2FS_I_SB(inode); 66 63 67 64 if (inode->i_ino == F2FS_META_INO(sbi) || 68 65 inode->i_ino == F2FS_NODE_INO(sbi) || 69 - S_ISDIR(inode->i_mode) || 70 - (S_ISREG(inode->i_mode) && 66 + S_ISDIR(inode->i_mode)) 67 + return true; 68 + 69 + if (f2fs_is_compressed_page(page)) 70 + return false; 71 + if ((S_ISREG(inode->i_mode) && 71 72 (f2fs_is_atomic_file(inode) || IS_NOQUOTA(inode))) || 72 - is_cold_data(page)) 73 + page_private_gcing(page)) 73 74 return true; 74 75 return false; 75 76 } ··· 132 131 133 132 if (f2fs_is_compressed_page(page)) { 134 133 if (bio->bi_status) 135 - f2fs_end_read_compressed_page(page, true); 134 + f2fs_end_read_compressed_page(page, true, 0); 136 135 f2fs_put_page_dic(page); 137 136 continue; 138 137 } ··· 228 227 struct bio_vec *bv; 229 228 struct bvec_iter_all iter_all; 230 229 bool all_compressed = true; 230 + block_t blkaddr = SECTOR_TO_BLOCK(ctx->bio->bi_iter.bi_sector); 231 231 232 232 bio_for_each_segment_all(bv, ctx->bio, iter_all) { 233 233 struct page *page = bv->bv_page; 234 234 235 235 /* PG_error was set if decryption failed. */ 236 236 if (f2fs_is_compressed_page(page)) 237 - f2fs_end_read_compressed_page(page, PageError(page)); 237 + f2fs_end_read_compressed_page(page, PageError(page), 238 + blkaddr); 238 239 else 239 240 all_compressed = false; 241 + 242 + blkaddr++; 240 243 } 241 244 242 245 /* ··· 304 299 struct page *page = bvec->bv_page; 305 300 enum count_type type = WB_DATA_TYPE(page); 306 301 307 - if (IS_DUMMY_WRITTEN_PAGE(page)) { 308 - set_page_private(page, (unsigned long)NULL); 309 - ClearPagePrivate(page); 302 + if (page_private_dummy(page)) { 303 + clear_page_private_dummy(page); 310 304 unlock_page(page); 311 305 mempool_free(page, sbi->write_io_dummy); 312 306 ··· 335 331 dec_page_count(sbi, type); 336 332 if (f2fs_in_warm_node_list(sbi, page)) 337 333 f2fs_del_fsync_node_entry(sbi, page); 338 - clear_cold_data(page); 334 + clear_page_private_gcing(page); 339 335 end_page_writeback(page); 340 336 } 341 337 if (!get_pages(sbi, F2FS_WB_CP_DATA) && ··· 459 455 GFP_NOIO | __GFP_NOFAIL); 460 456 f2fs_bug_on(sbi, !page); 461 457 462 - zero_user_segment(page, 0, PAGE_SIZE); 463 - SetPagePrivate(page); 464 - set_page_private(page, DUMMY_WRITTEN_PAGE); 465 458 lock_page(page); 459 + 460 + zero_user_segment(page, 0, PAGE_SIZE); 461 + set_page_private_dummy(page); 462 + 466 463 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) 467 464 f2fs_bug_on(sbi, 1); 468 465 } ··· 1356 1351 old_blkaddr = dn->data_blkaddr; 1357 1352 f2fs_allocate_data_block(sbi, NULL, old_blkaddr, &dn->data_blkaddr, 1358 1353 &sum, seg_type, NULL); 1359 - if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) 1354 + if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) { 1360 1355 invalidate_mapping_pages(META_MAPPING(sbi), 1361 1356 old_blkaddr, old_blkaddr); 1357 + f2fs_invalidate_compress_page(sbi, old_blkaddr); 1358 + } 1362 1359 f2fs_update_data_blkaddr(dn, dn->data_blkaddr); 1363 1360 1364 1361 /* ··· 2180 2173 goto out_put_dnode; 2181 2174 } 2182 2175 2183 - for (i = 0; i < dic->nr_cpages; i++) { 2176 + for (i = 0; i < cc->nr_cpages; i++) { 2184 2177 struct page *page = dic->cpages[i]; 2185 2178 block_t blkaddr; 2186 2179 struct bio_post_read_ctx *ctx; 2187 2180 2188 2181 blkaddr = data_blkaddr(dn.inode, dn.node_page, 2189 2182 dn.ofs_in_node + i + 1); 2183 + 2184 + f2fs_wait_on_block_writeback(inode, blkaddr); 2185 + 2186 + if (f2fs_load_compressed_page(sbi, page, blkaddr)) { 2187 + if (atomic_dec_and_test(&dic->remaining_pages)) 2188 + f2fs_decompress_cluster(dic); 2189 + continue; 2190 + } 2190 2191 2191 2192 if (bio && (!page_is_mergeable(sbi, bio, 2192 2193 *last_block_in_bio, blkaddr) || ··· 2216 2201 return ret; 2217 2202 } 2218 2203 } 2219 - 2220 - f2fs_wait_on_block_writeback(inode, blkaddr); 2221 2204 2222 2205 if (bio_add_page(bio, page, blocksize, 0) < blocksize) 2223 2206 goto submit_and_realloc; ··· 2472 2459 2473 2460 bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio) 2474 2461 { 2462 + /* swap file is migrating in aligned write mode */ 2463 + if (is_inode_flag_set(inode, FI_ALIGNED_WRITE)) 2464 + return false; 2465 + 2475 2466 if (f2fs_is_pinned_file(inode)) 2476 2467 return true; 2477 2468 ··· 2498 2481 return true; 2499 2482 if (f2fs_is_atomic_file(inode)) 2500 2483 return true; 2484 + 2485 + /* swap file is migrating in aligned write mode */ 2486 + if (is_inode_flag_set(inode, FI_ALIGNED_WRITE)) 2487 + return true; 2488 + 2501 2489 if (fio) { 2502 - if (is_cold_data(fio->page)) 2490 + if (page_private_gcing(fio->page)) 2503 2491 return true; 2504 - if (IS_ATOMIC_WRITTEN_PAGE(fio->page)) 2492 + if (page_private_dummy(fio->page)) 2505 2493 return true; 2506 2494 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED) && 2507 2495 f2fs_is_checkpointed_data(sbi, fio->old_blkaddr))) ··· 2562 2540 /* This page is already truncated */ 2563 2541 if (fio->old_blkaddr == NULL_ADDR) { 2564 2542 ClearPageUptodate(page); 2565 - clear_cold_data(page); 2543 + clear_page_private_gcing(page); 2566 2544 goto out_writepage; 2567 2545 } 2568 2546 got_it: ··· 2772 2750 inode_dec_dirty_pages(inode); 2773 2751 if (err) { 2774 2752 ClearPageUptodate(page); 2775 - clear_cold_data(page); 2753 + clear_page_private_gcing(page); 2776 2754 } 2777 2755 2778 2756 if (wbc->for_reclaim) { ··· 3246 3224 f2fs_do_read_inline_data(page, ipage); 3247 3225 set_inode_flag(inode, FI_DATA_EXIST); 3248 3226 if (inode->i_nlink) 3249 - set_inline_node(ipage); 3227 + set_page_private_inline(ipage); 3250 3228 } else { 3251 3229 err = f2fs_convert_inline_page(&dn, page); 3252 3230 if (err) ··· 3637 3615 } 3638 3616 } 3639 3617 3640 - clear_cold_data(page); 3618 + clear_page_private_gcing(page); 3641 3619 3642 - if (IS_ATOMIC_WRITTEN_PAGE(page)) 3620 + if (test_opt(sbi, COMPRESS_CACHE)) { 3621 + if (f2fs_compressed_file(inode)) 3622 + f2fs_invalidate_compress_pages(sbi, inode->i_ino); 3623 + if (inode->i_ino == F2FS_COMPRESS_INO(sbi)) 3624 + clear_page_private_data(page); 3625 + } 3626 + 3627 + if (page_private_atomic(page)) 3643 3628 return f2fs_drop_inmem_page(inode, page); 3644 3629 3645 - f2fs_clear_page_private(page); 3630 + detach_page_private(page); 3631 + set_page_private(page, 0); 3646 3632 } 3647 3633 3648 3634 int f2fs_release_page(struct page *page, gfp_t wait) ··· 3660 3630 return 0; 3661 3631 3662 3632 /* This is atomic written page, keep Private */ 3663 - if (IS_ATOMIC_WRITTEN_PAGE(page)) 3633 + if (page_private_atomic(page)) 3664 3634 return 0; 3665 3635 3666 - clear_cold_data(page); 3667 - f2fs_clear_page_private(page); 3636 + if (test_opt(F2FS_P_SB(page), COMPRESS_CACHE)) { 3637 + struct f2fs_sb_info *sbi = F2FS_P_SB(page); 3638 + struct inode *inode = page->mapping->host; 3639 + 3640 + if (f2fs_compressed_file(inode)) 3641 + f2fs_invalidate_compress_pages(sbi, inode->i_ino); 3642 + if (inode->i_ino == F2FS_COMPRESS_INO(sbi)) 3643 + clear_page_private_data(page); 3644 + } 3645 + 3646 + clear_page_private_gcing(page); 3647 + 3648 + detach_page_private(page); 3649 + set_page_private(page, 0); 3668 3650 return 1; 3669 3651 } 3670 3652 ··· 3692 3650 return __set_page_dirty_nobuffers(page); 3693 3651 3694 3652 if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) { 3695 - if (!IS_ATOMIC_WRITTEN_PAGE(page)) { 3653 + if (!page_private_atomic(page)) { 3696 3654 f2fs_register_inmem_page(inode, page); 3697 3655 return 1; 3698 3656 } ··· 3784 3742 { 3785 3743 int rc, extra_count; 3786 3744 struct f2fs_inode_info *fi = F2FS_I(mapping->host); 3787 - bool atomic_written = IS_ATOMIC_WRITTEN_PAGE(page); 3745 + bool atomic_written = page_private_atomic(page); 3788 3746 3789 3747 BUG_ON(PageWriteback(page)); 3790 3748 ··· 3819 3777 get_page(newpage); 3820 3778 } 3821 3779 3780 + /* guarantee to start from no stale private field */ 3781 + set_page_private(newpage, 0); 3822 3782 if (PagePrivate(page)) { 3823 - f2fs_set_page_private(newpage, page_private(page)); 3824 - f2fs_clear_page_private(page); 3783 + set_page_private(newpage, page_private(page)); 3784 + SetPagePrivate(newpage); 3785 + get_page(newpage); 3786 + 3787 + set_page_private(page, 0); 3788 + ClearPagePrivate(page); 3789 + put_page(page); 3825 3790 } 3826 3791 3827 3792 if (mode != MIGRATE_SYNC_NO_COPY) ··· 3841 3792 #endif 3842 3793 3843 3794 #ifdef CONFIG_SWAP 3844 - static int f2fs_is_file_aligned(struct inode *inode) 3795 + static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk, 3796 + unsigned int blkcnt) 3845 3797 { 3846 3798 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3847 - block_t main_blkaddr = SM_I(sbi)->main_blkaddr; 3848 - block_t cur_lblock; 3849 - block_t last_lblock; 3850 - block_t pblock; 3851 - unsigned long nr_pblocks; 3852 - unsigned int blocks_per_sec = BLKS_PER_SEC(sbi); 3853 - unsigned int not_aligned = 0; 3799 + unsigned int blkofs; 3800 + unsigned int blk_per_sec = BLKS_PER_SEC(sbi); 3801 + unsigned int secidx = start_blk / blk_per_sec; 3802 + unsigned int end_sec = secidx + blkcnt / blk_per_sec; 3854 3803 int ret = 0; 3855 3804 3856 - cur_lblock = 0; 3857 - last_lblock = bytes_to_blks(inode, i_size_read(inode)); 3805 + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3806 + down_write(&F2FS_I(inode)->i_mmap_sem); 3858 3807 3859 - while (cur_lblock < last_lblock) { 3860 - struct f2fs_map_blocks map; 3808 + set_inode_flag(inode, FI_ALIGNED_WRITE); 3861 3809 3862 - memset(&map, 0, sizeof(map)); 3863 - map.m_lblk = cur_lblock; 3864 - map.m_len = last_lblock - cur_lblock; 3865 - map.m_next_pgofs = NULL; 3866 - map.m_next_extent = NULL; 3867 - map.m_seg_type = NO_CHECK_TYPE; 3868 - map.m_may_create = false; 3810 + for (; secidx < end_sec; secidx++) { 3811 + down_write(&sbi->pin_sem); 3869 3812 3870 - ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP); 3871 - if (ret) 3872 - goto out; 3813 + f2fs_lock_op(sbi); 3814 + f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); 3815 + f2fs_unlock_op(sbi); 3873 3816 3874 - /* hole */ 3875 - if (!(map.m_flags & F2FS_MAP_FLAGS)) { 3876 - f2fs_err(sbi, "Swapfile has holes\n"); 3877 - ret = -ENOENT; 3878 - goto out; 3879 - } 3817 + set_inode_flag(inode, FI_DO_DEFRAG); 3880 3818 3881 - pblock = map.m_pblk; 3882 - nr_pblocks = map.m_len; 3819 + for (blkofs = 0; blkofs < blk_per_sec; blkofs++) { 3820 + struct page *page; 3821 + unsigned int blkidx = secidx * blk_per_sec + blkofs; 3883 3822 3884 - if ((pblock - main_blkaddr) & (blocks_per_sec - 1) || 3885 - nr_pblocks & (blocks_per_sec - 1)) { 3886 - if (f2fs_is_pinned_file(inode)) { 3887 - f2fs_err(sbi, "Swapfile does not align to section"); 3888 - ret = -EINVAL; 3889 - goto out; 3823 + page = f2fs_get_lock_data_page(inode, blkidx, true); 3824 + if (IS_ERR(page)) { 3825 + up_write(&sbi->pin_sem); 3826 + ret = PTR_ERR(page); 3827 + goto done; 3890 3828 } 3891 - not_aligned++; 3829 + 3830 + set_page_dirty(page); 3831 + f2fs_put_page(page, 1); 3892 3832 } 3893 3833 3894 - cur_lblock += nr_pblocks; 3834 + clear_inode_flag(inode, FI_DO_DEFRAG); 3835 + 3836 + ret = filemap_fdatawrite(inode->i_mapping); 3837 + 3838 + up_write(&sbi->pin_sem); 3839 + 3840 + if (ret) 3841 + break; 3895 3842 } 3896 - if (not_aligned) 3897 - f2fs_warn(sbi, "Swapfile (%u) is not align to section: \n" 3898 - "\t1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate()", 3899 - not_aligned); 3900 - out: 3843 + 3844 + done: 3845 + clear_inode_flag(inode, FI_DO_DEFRAG); 3846 + clear_inode_flag(inode, FI_ALIGNED_WRITE); 3847 + 3848 + up_write(&F2FS_I(inode)->i_mmap_sem); 3849 + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3850 + 3901 3851 return ret; 3902 3852 } 3903 3853 3904 - static int check_swap_activate_fast(struct swap_info_struct *sis, 3854 + static int check_swap_activate(struct swap_info_struct *sis, 3905 3855 struct file *swap_file, sector_t *span) 3906 3856 { 3907 3857 struct address_space *mapping = swap_file->f_mapping; ··· 3913 3865 sector_t highest_pblock = 0; 3914 3866 int nr_extents = 0; 3915 3867 unsigned long nr_pblocks; 3916 - unsigned int blocks_per_sec = BLKS_PER_SEC(sbi); 3868 + unsigned int blks_per_sec = BLKS_PER_SEC(sbi); 3869 + unsigned int sec_blks_mask = BLKS_PER_SEC(sbi) - 1; 3917 3870 unsigned int not_aligned = 0; 3918 3871 int ret = 0; 3919 3872 ··· 3927 3878 3928 3879 while (cur_lblock < last_lblock && cur_lblock < sis->max) { 3929 3880 struct f2fs_map_blocks map; 3930 - 3881 + retry: 3931 3882 cond_resched(); 3932 3883 3933 3884 memset(&map, 0, sizeof(map)); ··· 3944 3895 3945 3896 /* hole */ 3946 3897 if (!(map.m_flags & F2FS_MAP_FLAGS)) { 3947 - f2fs_err(sbi, "Swapfile has holes\n"); 3898 + f2fs_err(sbi, "Swapfile has holes"); 3948 3899 ret = -EINVAL; 3949 3900 goto out; 3950 3901 } ··· 3952 3903 pblock = map.m_pblk; 3953 3904 nr_pblocks = map.m_len; 3954 3905 3955 - if ((pblock - SM_I(sbi)->main_blkaddr) & (blocks_per_sec - 1) || 3956 - nr_pblocks & (blocks_per_sec - 1)) { 3957 - if (f2fs_is_pinned_file(inode)) { 3958 - f2fs_err(sbi, "Swapfile does not align to section"); 3959 - ret = -EINVAL; 3960 - goto out; 3961 - } 3906 + if ((pblock - SM_I(sbi)->main_blkaddr) & sec_blks_mask || 3907 + nr_pblocks & sec_blks_mask) { 3962 3908 not_aligned++; 3963 - } 3964 3909 3910 + nr_pblocks = roundup(nr_pblocks, blks_per_sec); 3911 + if (cur_lblock + nr_pblocks > sis->max) 3912 + nr_pblocks -= blks_per_sec; 3913 + 3914 + if (!nr_pblocks) { 3915 + /* this extent is last one */ 3916 + nr_pblocks = map.m_len; 3917 + f2fs_warn(sbi, "Swapfile: last extent is not aligned to section"); 3918 + goto next; 3919 + } 3920 + 3921 + ret = f2fs_migrate_blocks(inode, cur_lblock, 3922 + nr_pblocks); 3923 + if (ret) 3924 + goto out; 3925 + goto retry; 3926 + } 3927 + next: 3965 3928 if (cur_lblock + nr_pblocks >= sis->max) 3966 3929 nr_pblocks = sis->max - cur_lblock; 3967 3930 ··· 4000 3939 sis->max = cur_lblock; 4001 3940 sis->pages = cur_lblock - 1; 4002 3941 sis->highest_bit = cur_lblock - 1; 4003 - 3942 + out: 4004 3943 if (not_aligned) 4005 - f2fs_warn(sbi, "Swapfile (%u) is not align to section: \n" 4006 - "\t1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate()", 4007 - not_aligned); 4008 - out: 3944 + f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%u * N)", 3945 + not_aligned, blks_per_sec * F2FS_BLKSIZE); 4009 3946 return ret; 4010 - } 4011 - 4012 - /* Copied from generic_swapfile_activate() to check any holes */ 4013 - static int check_swap_activate(struct swap_info_struct *sis, 4014 - struct file *swap_file, sector_t *span) 4015 - { 4016 - struct address_space *mapping = swap_file->f_mapping; 4017 - struct inode *inode = mapping->host; 4018 - struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4019 - unsigned blocks_per_page; 4020 - unsigned long page_no; 4021 - sector_t probe_block; 4022 - sector_t last_block; 4023 - sector_t lowest_block = -1; 4024 - sector_t highest_block = 0; 4025 - int nr_extents = 0; 4026 - int ret = 0; 4027 - 4028 - if (PAGE_SIZE == F2FS_BLKSIZE) 4029 - return check_swap_activate_fast(sis, swap_file, span); 4030 - 4031 - ret = f2fs_is_file_aligned(inode); 4032 - if (ret) 4033 - goto out; 4034 - 4035 - blocks_per_page = bytes_to_blks(inode, PAGE_SIZE); 4036 - 4037 - /* 4038 - * Map all the blocks into the extent list. This code doesn't try 4039 - * to be very smart. 4040 - */ 4041 - probe_block = 0; 4042 - page_no = 0; 4043 - last_block = bytes_to_blks(inode, i_size_read(inode)); 4044 - while ((probe_block + blocks_per_page) <= last_block && 4045 - page_no < sis->max) { 4046 - unsigned block_in_page; 4047 - sector_t first_block; 4048 - sector_t block = 0; 4049 - 4050 - cond_resched(); 4051 - 4052 - block = probe_block; 4053 - ret = bmap(inode, &block); 4054 - if (ret) 4055 - goto out; 4056 - if (!block) 4057 - goto bad_bmap; 4058 - first_block = block; 4059 - 4060 - /* 4061 - * It must be PAGE_SIZE aligned on-disk 4062 - */ 4063 - if (first_block & (blocks_per_page - 1)) { 4064 - probe_block++; 4065 - goto reprobe; 4066 - } 4067 - 4068 - for (block_in_page = 1; block_in_page < blocks_per_page; 4069 - block_in_page++) { 4070 - 4071 - block = probe_block + block_in_page; 4072 - ret = bmap(inode, &block); 4073 - if (ret) 4074 - goto out; 4075 - if (!block) 4076 - goto bad_bmap; 4077 - 4078 - if (block != first_block + block_in_page) { 4079 - /* Discontiguity */ 4080 - probe_block++; 4081 - goto reprobe; 4082 - } 4083 - } 4084 - 4085 - first_block >>= (PAGE_SHIFT - inode->i_blkbits); 4086 - if (page_no) { /* exclude the header page */ 4087 - if (first_block < lowest_block) 4088 - lowest_block = first_block; 4089 - if (first_block > highest_block) 4090 - highest_block = first_block; 4091 - } 4092 - 4093 - /* 4094 - * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks 4095 - */ 4096 - ret = add_swap_extent(sis, page_no, 1, first_block); 4097 - if (ret < 0) 4098 - goto out; 4099 - nr_extents += ret; 4100 - page_no++; 4101 - probe_block += blocks_per_page; 4102 - reprobe: 4103 - continue; 4104 - } 4105 - ret = nr_extents; 4106 - *span = 1 + highest_block - lowest_block; 4107 - if (page_no == 0) 4108 - page_no = 1; /* force Empty message */ 4109 - sis->max = page_no; 4110 - sis->pages = page_no - 1; 4111 - sis->highest_bit = page_no - 1; 4112 - out: 4113 - return ret; 4114 - bad_bmap: 4115 - f2fs_err(sbi, "Swapfile has holes\n"); 4116 - return -EINVAL; 4117 3947 } 4118 3948 4119 3949 static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file, ··· 4018 4066 4019 4067 if (f2fs_readonly(F2FS_I_SB(inode)->sb)) 4020 4068 return -EROFS; 4069 + 4070 + if (f2fs_lfs_mode(F2FS_I_SB(inode))) { 4071 + f2fs_err(F2FS_I_SB(inode), 4072 + "Swapfile not supported in LFS mode"); 4073 + return -EINVAL; 4074 + } 4021 4075 4022 4076 ret = f2fs_convert_inline_inode(inode); 4023 4077 if (ret)
+13
fs/f2fs/debug.c
··· 152 152 si->node_pages = NODE_MAPPING(sbi)->nrpages; 153 153 if (sbi->meta_inode) 154 154 si->meta_pages = META_MAPPING(sbi)->nrpages; 155 + #ifdef CONFIG_F2FS_FS_COMPRESSION 156 + if (sbi->compress_inode) { 157 + si->compress_pages = COMPRESS_MAPPING(sbi)->nrpages; 158 + si->compress_page_hit = atomic_read(&sbi->compress_page_hit); 159 + } 160 + #endif 155 161 si->nats = NM_I(sbi)->nat_cnt[TOTAL_NAT]; 156 162 si->dirty_nats = NM_I(sbi)->nat_cnt[DIRTY_NAT]; 157 163 si->sits = MAIN_SEGS(sbi); ··· 315 309 316 310 si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 317 311 } 312 + #ifdef CONFIG_F2FS_FS_COMPRESSION 313 + if (sbi->compress_inode) { 314 + unsigned npages = COMPRESS_MAPPING(sbi)->nrpages; 315 + si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 316 + } 317 + #endif 318 318 } 319 319 320 320 static int stat_show(struct seq_file *s, void *v) ··· 488 476 "volatile IO: %4d (Max. %4d)\n", 489 477 si->inmem_pages, si->aw_cnt, si->max_aw_cnt, 490 478 si->vw_cnt, si->max_vw_cnt); 479 + seq_printf(s, " - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit); 491 480 seq_printf(s, " - nodes: %4d in %4d\n", 492 481 si->ndirty_node, si->node_pages); 493 482 seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n",
+17 -8
fs/f2fs/dir.c
··· 16 16 #include "xattr.h" 17 17 #include <trace/events/f2fs.h> 18 18 19 + #ifdef CONFIG_UNICODE 20 + extern struct kmem_cache *f2fs_cf_name_slab; 21 + #endif 22 + 19 23 static unsigned long dir_blocks(struct inode *inode) 20 24 { 21 25 return ((unsigned long long) (i_size_read(inode) + PAGE_SIZE - 1)) ··· 81 77 { 82 78 #ifdef CONFIG_UNICODE 83 79 struct super_block *sb = dir->i_sb; 84 - struct f2fs_sb_info *sbi = F2FS_SB(sb); 85 80 86 81 if (IS_CASEFOLDED(dir)) { 87 - fname->cf_name.name = f2fs_kmalloc(sbi, F2FS_NAME_LEN, 88 - GFP_NOFS); 82 + fname->cf_name.name = kmem_cache_alloc(f2fs_cf_name_slab, 83 + GFP_NOFS); 89 84 if (!fname->cf_name.name) 90 85 return -ENOMEM; 91 86 fname->cf_name.len = utf8_casefold(sb->s_encoding, ··· 92 89 fname->cf_name.name, 93 90 F2FS_NAME_LEN); 94 91 if ((int)fname->cf_name.len <= 0) { 95 - kfree(fname->cf_name.name); 92 + kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); 96 93 fname->cf_name.name = NULL; 97 94 if (sb_has_strict_encoding(sb)) 98 95 return -EINVAL; ··· 175 172 fname->crypto_buf.name = NULL; 176 173 #endif 177 174 #ifdef CONFIG_UNICODE 178 - kfree(fname->cf_name.name); 179 - fname->cf_name.name = NULL; 175 + if (fname->cf_name.name) { 176 + kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); 177 + fname->cf_name.name = NULL; 178 + } 180 179 #endif 181 180 } 182 181 ··· 934 929 !f2fs_truncate_hole(dir, page->index, page->index + 1)) { 935 930 f2fs_clear_page_cache_dirty_tag(page); 936 931 clear_page_dirty_for_io(page); 937 - f2fs_clear_page_private(page); 938 932 ClearPageUptodate(page); 939 - clear_cold_data(page); 933 + 934 + clear_page_private_gcing(page); 935 + 940 936 inode_dec_dirty_pages(dir); 941 937 f2fs_remove_dirty_inode(dir); 938 + 939 + detach_page_private(page); 940 + set_page_private(page, 0); 942 941 } 943 942 f2fs_put_page(page, 1); 944 943
+186 -46
fs/f2fs/f2fs.h
··· 98 98 #define F2FS_MOUNT_ATGC 0x08000000 99 99 #define F2FS_MOUNT_MERGE_CHECKPOINT 0x10000000 100 100 #define F2FS_MOUNT_GC_MERGE 0x20000000 101 + #define F2FS_MOUNT_COMPRESS_CACHE 0x40000000 101 102 102 103 #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 103 104 #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) ··· 151 150 unsigned char compress_level; /* compress level */ 152 151 bool compress_chksum; /* compressed data chksum */ 153 152 unsigned char compress_ext_cnt; /* extension count */ 153 + unsigned char nocompress_ext_cnt; /* nocompress extension count */ 154 154 int compress_mode; /* compression mode */ 155 155 unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 156 + unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 156 157 }; 157 158 158 159 #define F2FS_FEATURE_ENCRYPT 0x0001 ··· 171 168 #define F2FS_FEATURE_SB_CHKSUM 0x0800 172 169 #define F2FS_FEATURE_CASEFOLD 0x1000 173 170 #define F2FS_FEATURE_COMPRESSION 0x2000 171 + #define F2FS_FEATURE_RO 0x4000 174 172 175 173 #define __F2FS_HAS_FEATURE(raw_super, mask) \ 176 174 ((raw_super->feature & cpu_to_le32(mask)) != 0) ··· 710 706 FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 711 707 FI_MMAP_FILE, /* indicate file was mmapped */ 712 708 FI_ENABLE_COMPRESS, /* enable compression in "user" compression mode */ 709 + FI_COMPRESS_RELEASED, /* compressed blocks were released */ 710 + FI_ALIGNED_WRITE, /* enable aligned write */ 713 711 FI_MAX, /* max flag, never be used */ 714 712 }; 715 713 ··· 945 939 #define NR_CURSEG_DATA_TYPE (3) 946 940 #define NR_CURSEG_NODE_TYPE (3) 947 941 #define NR_CURSEG_INMEM_TYPE (2) 942 + #define NR_CURSEG_RO_TYPE (2) 948 943 #define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 949 944 #define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE) 950 945 ··· 1298 1291 */ 1299 1292 }; 1300 1293 1301 - /* 1302 - * this value is set in page as a private data which indicate that 1303 - * the page is atomically written, and it is in inmem_pages list. 1304 - */ 1305 - #define ATOMIC_WRITTEN_PAGE ((unsigned long)-1) 1306 - #define DUMMY_WRITTEN_PAGE ((unsigned long)-2) 1294 + static inline int f2fs_test_bit(unsigned int nr, char *addr); 1295 + static inline void f2fs_set_bit(unsigned int nr, char *addr); 1296 + static inline void f2fs_clear_bit(unsigned int nr, char *addr); 1307 1297 1308 - #define IS_ATOMIC_WRITTEN_PAGE(page) \ 1309 - (page_private(page) == ATOMIC_WRITTEN_PAGE) 1310 - #define IS_DUMMY_WRITTEN_PAGE(page) \ 1311 - (page_private(page) == DUMMY_WRITTEN_PAGE) 1298 + /* 1299 + * Layout of f2fs page.private: 1300 + * 1301 + * Layout A: lowest bit should be 1 1302 + * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... | 1303 + * bit 0 PAGE_PRIVATE_NOT_POINTER 1304 + * bit 1 PAGE_PRIVATE_ATOMIC_WRITE 1305 + * bit 2 PAGE_PRIVATE_DUMMY_WRITE 1306 + * bit 3 PAGE_PRIVATE_ONGOING_MIGRATION 1307 + * bit 4 PAGE_PRIVATE_INLINE_INODE 1308 + * bit 5 PAGE_PRIVATE_REF_RESOURCE 1309 + * bit 6- f2fs private data 1310 + * 1311 + * Layout B: lowest bit should be 0 1312 + * page.private is a wrapped pointer. 1313 + */ 1314 + enum { 1315 + PAGE_PRIVATE_NOT_POINTER, /* private contains non-pointer data */ 1316 + PAGE_PRIVATE_ATOMIC_WRITE, /* data page from atomic write path */ 1317 + PAGE_PRIVATE_DUMMY_WRITE, /* data page for padding aligned IO */ 1318 + PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */ 1319 + PAGE_PRIVATE_INLINE_INODE, /* inode page contains inline data */ 1320 + PAGE_PRIVATE_REF_RESOURCE, /* dirty page has referenced resources */ 1321 + PAGE_PRIVATE_MAX 1322 + }; 1323 + 1324 + #define PAGE_PRIVATE_GET_FUNC(name, flagname) \ 1325 + static inline bool page_private_##name(struct page *page) \ 1326 + { \ 1327 + return PagePrivate(page) && \ 1328 + test_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)) && \ 1329 + test_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1330 + } 1331 + 1332 + #define PAGE_PRIVATE_SET_FUNC(name, flagname) \ 1333 + static inline void set_page_private_##name(struct page *page) \ 1334 + { \ 1335 + if (!PagePrivate(page)) { \ 1336 + get_page(page); \ 1337 + SetPagePrivate(page); \ 1338 + set_page_private(page, 0); \ 1339 + } \ 1340 + set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \ 1341 + set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1342 + } 1343 + 1344 + #define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \ 1345 + static inline void clear_page_private_##name(struct page *page) \ 1346 + { \ 1347 + clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1348 + if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { \ 1349 + set_page_private(page, 0); \ 1350 + if (PagePrivate(page)) { \ 1351 + ClearPagePrivate(page); \ 1352 + put_page(page); \ 1353 + }\ 1354 + } \ 1355 + } 1356 + 1357 + PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER); 1358 + PAGE_PRIVATE_GET_FUNC(reference, REF_RESOURCE); 1359 + PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE); 1360 + PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION); 1361 + PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE); 1362 + PAGE_PRIVATE_GET_FUNC(dummy, DUMMY_WRITE); 1363 + 1364 + PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE); 1365 + PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE); 1366 + PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION); 1367 + PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE); 1368 + PAGE_PRIVATE_SET_FUNC(dummy, DUMMY_WRITE); 1369 + 1370 + PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE); 1371 + PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE); 1372 + PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION); 1373 + PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE); 1374 + PAGE_PRIVATE_CLEAR_FUNC(dummy, DUMMY_WRITE); 1375 + 1376 + static inline unsigned long get_page_private_data(struct page *page) 1377 + { 1378 + unsigned long data = page_private(page); 1379 + 1380 + if (!test_bit(PAGE_PRIVATE_NOT_POINTER, &data)) 1381 + return 0; 1382 + return data >> PAGE_PRIVATE_MAX; 1383 + } 1384 + 1385 + static inline void set_page_private_data(struct page *page, unsigned long data) 1386 + { 1387 + if (!PagePrivate(page)) { 1388 + get_page(page); 1389 + SetPagePrivate(page); 1390 + set_page_private(page, 0); 1391 + } 1392 + set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); 1393 + page_private(page) |= data << PAGE_PRIVATE_MAX; 1394 + } 1395 + 1396 + static inline void clear_page_private_data(struct page *page) 1397 + { 1398 + page_private(page) &= (1 << PAGE_PRIVATE_MAX) - 1; 1399 + if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { 1400 + set_page_private(page, 0); 1401 + if (PagePrivate(page)) { 1402 + ClearPagePrivate(page); 1403 + put_page(page); 1404 + } 1405 + } 1406 + } 1312 1407 1313 1408 /* For compression */ 1314 1409 enum compress_algorithm_type { ··· 1425 1316 COMPRESS_CHKSUM, 1426 1317 COMPRESS_MAX_FLAG, 1427 1318 }; 1319 + 1320 + #define COMPRESS_WATERMARK 20 1321 + #define COMPRESS_PERCENT 20 1428 1322 1429 1323 #define COMPRESS_DATA_RESERVED_SIZE 4 1430 1324 struct compress_data { ··· 1706 1594 struct kobject s_stat_kobj; /* /sys/fs/f2fs/<devname>/stat */ 1707 1595 struct completion s_stat_kobj_unregister; 1708 1596 1597 + struct kobject s_feature_list_kobj; /* /sys/fs/f2fs/<devname>/feature_list */ 1598 + struct completion s_feature_list_kobj_unregister; 1599 + 1709 1600 /* For shrinker support */ 1710 1601 struct list_head s_list; 1711 1602 int s_ndevs; /* number of devices */ ··· 1741 1626 u64 compr_written_block; 1742 1627 u64 compr_saved_block; 1743 1628 u32 compr_new_inode; 1629 + 1630 + /* For compressed block cache */ 1631 + struct inode *compress_inode; /* cache compressed blocks */ 1632 + unsigned int compress_percent; /* cache page percentage */ 1633 + unsigned int compress_watermark; /* cache page watermark */ 1634 + atomic_t compress_page_hit; /* cache hit count */ 1744 1635 #endif 1745 1636 }; 1746 1637 ··· 2799 2678 case FI_DATA_EXIST: 2800 2679 case FI_INLINE_DOTS: 2801 2680 case FI_PIN_FILE: 2681 + case FI_COMPRESS_RELEASED: 2802 2682 f2fs_mark_inode_dirty_sync(inode, true); 2803 2683 } 2804 2684 } ··· 2921 2799 set_bit(FI_EXTRA_ATTR, fi->flags); 2922 2800 if (ri->i_inline & F2FS_PIN_FILE) 2923 2801 set_bit(FI_PIN_FILE, fi->flags); 2802 + if (ri->i_inline & F2FS_COMPRESS_RELEASED) 2803 + set_bit(FI_COMPRESS_RELEASED, fi->flags); 2924 2804 } 2925 2805 2926 2806 static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) ··· 2943 2819 ri->i_inline |= F2FS_EXTRA_ATTR; 2944 2820 if (is_inode_flag_set(inode, FI_PIN_FILE)) 2945 2821 ri->i_inline |= F2FS_PIN_FILE; 2822 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) 2823 + ri->i_inline |= F2FS_COMPRESS_RELEASED; 2946 2824 } 2947 2825 2948 2826 static inline int f2fs_has_extra_attr(struct inode *inode) ··· 3153 3027 return false; 3154 3028 } 3155 3029 3156 - static inline bool f2fs_may_extent_tree(struct inode *inode) 3157 - { 3158 - struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3159 - 3160 - if (!test_opt(sbi, EXTENT_CACHE) || 3161 - is_inode_flag_set(inode, FI_NO_EXTENT) || 3162 - is_inode_flag_set(inode, FI_COMPRESSED_FILE)) 3163 - return false; 3164 - 3165 - /* 3166 - * for recovered files during mount do not create extents 3167 - * if shrinker is not registered. 3168 - */ 3169 - if (list_empty(&sbi->s_list)) 3170 - return false; 3171 - 3172 - return S_ISREG(inode->i_mode); 3173 - } 3174 - 3175 3030 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 3176 3031 size_t size, gfp_t flags) 3177 3032 { ··· 3274 3167 blkaddr == COMPRESS_ADDR) 3275 3168 return false; 3276 3169 return true; 3277 - } 3278 - 3279 - static inline void f2fs_set_page_private(struct page *page, 3280 - unsigned long data) 3281 - { 3282 - if (PagePrivate(page)) 3283 - return; 3284 - 3285 - attach_page_private(page, (void *)data); 3286 - } 3287 - 3288 - static inline void f2fs_clear_page_private(struct page *page) 3289 - { 3290 - detach_page_private(page); 3291 3170 } 3292 3171 3293 3172 /* ··· 3659 3566 */ 3660 3567 int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 3661 3568 bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 3569 + int __init f2fs_create_recovery_cache(void); 3570 + void f2fs_destroy_recovery_cache(void); 3662 3571 3663 3572 /* 3664 3573 * debug.c ··· 3699 3604 unsigned int bimodal, avg_vblocks; 3700 3605 int util_free, util_valid, util_invalid; 3701 3606 int rsvd_segs, overp_segs; 3702 - int dirty_count, node_pages, meta_pages; 3607 + int dirty_count, node_pages, meta_pages, compress_pages; 3608 + int compress_page_hit; 3703 3609 int prefree_count, call_count, cp_count, bg_cp_count; 3704 3610 int tot_segs, node_segs, data_segs, free_segs, free_secs; 3705 3611 int bg_node_segs, bg_data_segs; ··· 4036 3940 bool f2fs_is_compress_backend_ready(struct inode *inode); 4037 3941 int f2fs_init_compress_mempool(void); 4038 3942 void f2fs_destroy_compress_mempool(void); 4039 - void f2fs_end_read_compressed_page(struct page *page, bool failed); 3943 + void f2fs_decompress_cluster(struct decompress_io_ctx *dic); 3944 + void f2fs_end_read_compressed_page(struct page *page, bool failed, 3945 + block_t blkaddr); 4040 3946 bool f2fs_cluster_is_empty(struct compress_ctx *cc); 4041 3947 bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 4042 3948 void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); ··· 4056 3958 int f2fs_init_compress_ctx(struct compress_ctx *cc); 4057 3959 void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse); 4058 3960 void f2fs_init_compress_info(struct f2fs_sb_info *sbi); 3961 + int f2fs_init_compress_inode(struct f2fs_sb_info *sbi); 3962 + void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi); 4059 3963 int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); 4060 3964 void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); 4061 3965 int __init f2fs_init_compress_cache(void); 4062 3966 void f2fs_destroy_compress_cache(void); 3967 + struct address_space *COMPRESS_MAPPING(struct f2fs_sb_info *sbi); 3968 + void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkaddr); 3969 + void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 3970 + nid_t ino, block_t blkaddr); 3971 + bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 3972 + block_t blkaddr); 3973 + void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, nid_t ino); 4063 3974 #define inc_compr_inode_stat(inode) \ 4064 3975 do { \ 4065 3976 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ ··· 4097 3990 } 4098 3991 static inline int f2fs_init_compress_mempool(void) { return 0; } 4099 3992 static inline void f2fs_destroy_compress_mempool(void) { } 4100 - static inline void f2fs_end_read_compressed_page(struct page *page, bool failed) 3993 + static inline void f2fs_decompress_cluster(struct decompress_io_ctx *dic) { } 3994 + static inline void f2fs_end_read_compressed_page(struct page *page, 3995 + bool failed, block_t blkaddr) 4101 3996 { 4102 3997 WARN_ON_ONCE(1); 4103 3998 } ··· 4107 3998 { 4108 3999 WARN_ON_ONCE(1); 4109 4000 } 4001 + static inline int f2fs_init_compress_inode(struct f2fs_sb_info *sbi) { return 0; } 4002 + static inline void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi) { } 4110 4003 static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } 4111 4004 static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } 4112 4005 static inline int __init f2fs_init_compress_cache(void) { return 0; } 4113 4006 static inline void f2fs_destroy_compress_cache(void) { } 4007 + static inline void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, 4008 + block_t blkaddr) { } 4009 + static inline void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, 4010 + struct page *page, nid_t ino, block_t blkaddr) { } 4011 + static inline bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, 4012 + struct page *page, block_t blkaddr) { return false; } 4013 + static inline void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, 4014 + nid_t ino) { } 4114 4015 #define inc_compr_inode_stat(inode) do { } while (0) 4115 4016 #endif 4116 4017 ··· 4185 4066 F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 4186 4067 F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 4187 4068 F2FS_FEATURE_FUNCS(compression, COMPRESSION); 4069 + F2FS_FEATURE_FUNCS(readonly, RO); 4070 + 4071 + static inline bool f2fs_may_extent_tree(struct inode *inode) 4072 + { 4073 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4074 + 4075 + if (!test_opt(sbi, EXTENT_CACHE) || 4076 + is_inode_flag_set(inode, FI_NO_EXTENT) || 4077 + (is_inode_flag_set(inode, FI_COMPRESSED_FILE) && 4078 + !f2fs_sb_has_readonly(sbi))) 4079 + return false; 4080 + 4081 + /* 4082 + * for recovered files during mount do not create extents 4083 + * if shrinker is not registered. 4084 + */ 4085 + if (list_empty(&sbi->s_list)) 4086 + return false; 4087 + 4088 + return S_ISREG(inode->i_mode); 4089 + } 4188 4090 4189 4091 #ifdef CONFIG_BLK_DEV_ZONED 4190 4092 static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
+18 -19
fs/f2fs/file.c
··· 63 63 if (unlikely(IS_IMMUTABLE(inode))) 64 64 return VM_FAULT_SIGBUS; 65 65 66 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) 67 + return VM_FAULT_SIGBUS; 68 + 66 69 if (unlikely(f2fs_cp_error(sbi))) { 67 70 err = -EIO; 68 71 goto err; ··· 88 85 err = ret; 89 86 goto err; 90 87 } else if (ret) { 91 - if (ret < F2FS_I(inode)->i_cluster_size) { 92 - err = -EAGAIN; 93 - goto err; 94 - } 95 88 need_alloc = false; 96 89 } 97 90 } ··· 116 117 f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); 117 118 set_new_dnode(&dn, inode, NULL, NULL, 0); 118 119 err = f2fs_get_block(&dn, page->index); 119 - f2fs_put_dnode(&dn); 120 120 f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); 121 121 } 122 122 ··· 3201 3203 map.m_lblk = m_next_extent; 3202 3204 } 3203 3205 3204 - return err; 3206 + return 0; 3205 3207 } 3206 3208 3207 3209 static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg) ··· 3235 3237 3236 3238 if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) { 3237 3239 f2fs_warn(F2FS_I_SB(inode), 3238 - "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem.\n", 3240 + "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem", 3239 3241 inode->i_ino); 3240 3242 return -EOPNOTSUPP; 3241 3243 } ··· 3423 3425 goto out; 3424 3426 } 3425 3427 3426 - if (IS_IMMUTABLE(inode)) { 3428 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3427 3429 ret = -EINVAL; 3428 3430 goto out; 3429 3431 } ··· 3432 3434 if (ret) 3433 3435 goto out; 3434 3436 3435 - F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; 3436 - f2fs_set_inode_flags(inode); 3437 + set_inode_flag(inode, FI_COMPRESS_RELEASED); 3437 3438 inode->i_ctime = current_time(inode); 3438 3439 f2fs_mark_inode_dirty_sync(inode, true); 3439 3440 ··· 3587 3590 3588 3591 inode_lock(inode); 3589 3592 3590 - if (!IS_IMMUTABLE(inode)) { 3593 + if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3591 3594 ret = -EINVAL; 3592 3595 goto unlock_inode; 3593 3596 } ··· 3632 3635 up_write(&F2FS_I(inode)->i_mmap_sem); 3633 3636 3634 3637 if (ret >= 0) { 3635 - F2FS_I(inode)->i_flags &= ~F2FS_IMMUTABLE_FL; 3636 - f2fs_set_inode_flags(inode); 3638 + clear_inode_flag(inode, FI_COMPRESS_RELEASED); 3637 3639 inode->i_ctime = current_time(inode); 3638 3640 f2fs_mark_inode_dirty_sync(inode, true); 3639 3641 } ··· 4019 4023 LLONG_MAX); 4020 4024 4021 4025 if (ret) 4022 - f2fs_warn(sbi, "%s: The file might be partially decompressed " 4023 - "(errno=%d). Please delete the file.\n", 4024 - __func__, ret); 4026 + f2fs_warn(sbi, "%s: The file might be partially decompressed (errno=%d). Please delete the file.", 4027 + __func__, ret); 4025 4028 out: 4026 4029 inode_unlock(inode); 4027 4030 file_end_write(filp); ··· 4092 4097 clear_inode_flag(inode, FI_ENABLE_COMPRESS); 4093 4098 4094 4099 if (ret) 4095 - f2fs_warn(sbi, "%s: The file might be partially compressed " 4096 - "(errno=%d). Please delete the file.\n", 4097 - __func__, ret); 4100 + f2fs_warn(sbi, "%s: The file might be partially compressed (errno=%d). Please delete the file.", 4101 + __func__, ret); 4098 4102 out: 4099 4103 inode_unlock(inode); 4100 4104 file_end_write(filp); ··· 4244 4250 } 4245 4251 4246 4252 if (unlikely(IS_IMMUTABLE(inode))) { 4253 + ret = -EPERM; 4254 + goto unlock; 4255 + } 4256 + 4257 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 4247 4258 ret = -EPERM; 4248 4259 goto unlock; 4249 4260 }
+8 -8
fs/f2fs/gc.c
··· 1031 1031 1032 1032 if (unlikely(check_valid_map(sbi, segno, offset))) { 1033 1033 if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { 1034 - f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u\n", 1035 - blkaddr, source_blkaddr, segno); 1034 + f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u", 1035 + blkaddr, source_blkaddr, segno); 1036 1036 f2fs_bug_on(sbi, 1); 1037 1037 } 1038 1038 } ··· 1261 1261 f2fs_put_page(mpage, 1); 1262 1262 invalidate_mapping_pages(META_MAPPING(fio.sbi), 1263 1263 fio.old_blkaddr, fio.old_blkaddr); 1264 + f2fs_invalidate_compress_page(fio.sbi, fio.old_blkaddr); 1264 1265 1265 1266 set_page_dirty(fio.encrypted_page); 1266 1267 if (clear_page_dirty_for_io(fio.encrypted_page)) ··· 1337 1336 goto out; 1338 1337 } 1339 1338 set_page_dirty(page); 1340 - set_cold_data(page); 1339 + set_page_private_gcing(page); 1341 1340 } else { 1342 1341 struct f2fs_io_info fio = { 1343 1342 .sbi = F2FS_I_SB(inode), ··· 1363 1362 f2fs_remove_dirty_inode(inode); 1364 1363 } 1365 1364 1366 - set_cold_data(page); 1365 + set_page_private_gcing(page); 1367 1366 1368 1367 err = f2fs_do_write_data_page(&fio); 1369 1368 if (err) { 1370 - clear_cold_data(page); 1369 + clear_page_private_gcing(page); 1371 1370 if (err == -ENOMEM) { 1372 1371 congestion_wait(BLK_RW_ASYNC, 1373 1372 DEFAULT_IO_TIMEOUT); ··· 1451 1450 1452 1451 if (phase == 3) { 1453 1452 inode = f2fs_iget(sb, dni.ino); 1454 - if (IS_ERR(inode) || is_bad_inode(inode)) { 1455 - set_sbi_flag(sbi, SBI_NEED_FSCK); 1453 + if (IS_ERR(inode) || is_bad_inode(inode)) 1456 1454 continue; 1457 - } 1458 1455 1459 1456 if (!down_write_trylock( 1460 1457 &F2FS_I(inode)->i_gc_rwsem[WRITE])) { ··· 1821 1822 am->candidate_ratio = DEF_GC_THREAD_CANDIDATE_RATIO; 1822 1823 am->max_candidate_count = DEF_GC_THREAD_MAX_CANDIDATE_COUNT; 1823 1824 am->age_weight = DEF_GC_THREAD_AGE_WEIGHT; 1825 + am->age_threshold = DEF_GC_THREAD_AGE_THRESHOLD; 1824 1826 } 1825 1827 1826 1828 void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
+2 -2
fs/f2fs/inline.c
··· 173 173 174 174 /* clear inline data and flag after data writeback */ 175 175 f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0); 176 - clear_inline_node(dn->inode_page); 176 + clear_page_private_inline(dn->inode_page); 177 177 clear_out: 178 178 stat_dec_inline_inode(dn->inode); 179 179 clear_inode_flag(dn->inode, FI_INLINE_DATA); ··· 255 255 set_inode_flag(inode, FI_APPEND_WRITE); 256 256 set_inode_flag(inode, FI_DATA_EXIST); 257 257 258 - clear_inline_node(dn.inode_page); 258 + clear_page_private_inline(dn.inode_page); 259 259 f2fs_put_dnode(&dn); 260 260 return 0; 261 261 }
+21 -2
fs/f2fs/inode.c
··· 18 18 19 19 #include <trace/events/f2fs.h> 20 20 21 + #ifdef CONFIG_F2FS_FS_COMPRESSION 22 + extern const struct address_space_operations f2fs_compress_aops; 23 + #endif 24 + 21 25 void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) 22 26 { 23 27 if (is_inode_flag_set(inode, FI_NEW_INODE)) ··· 498 494 if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi)) 499 495 goto make_now; 500 496 497 + #ifdef CONFIG_F2FS_FS_COMPRESSION 498 + if (ino == F2FS_COMPRESS_INO(sbi)) 499 + goto make_now; 500 + #endif 501 + 501 502 ret = do_read_inode(inode); 502 503 if (ret) 503 504 goto bad_inode; ··· 513 504 } else if (ino == F2FS_META_INO(sbi)) { 514 505 inode->i_mapping->a_ops = &f2fs_meta_aops; 515 506 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); 507 + } else if (ino == F2FS_COMPRESS_INO(sbi)) { 508 + #ifdef CONFIG_F2FS_FS_COMPRESSION 509 + inode->i_mapping->a_ops = &f2fs_compress_aops; 510 + #endif 511 + mapping_set_gfp_mask(inode->i_mapping, 512 + GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); 516 513 } else if (S_ISREG(inode->i_mode)) { 517 514 inode->i_op = &f2fs_file_inode_operations; 518 515 inode->i_fop = &f2fs_file_operations; ··· 661 646 662 647 /* deleted inode */ 663 648 if (inode->i_nlink == 0) 664 - clear_inline_node(node_page); 649 + clear_page_private_inline(node_page); 665 650 666 651 F2FS_I(inode)->i_disk_time[0] = inode->i_atime; 667 652 F2FS_I(inode)->i_disk_time[1] = inode->i_ctime; ··· 738 723 trace_f2fs_evict_inode(inode); 739 724 truncate_inode_pages_final(&inode->i_data); 740 725 726 + if (test_opt(sbi, COMPRESS_CACHE) && f2fs_compressed_file(inode)) 727 + f2fs_invalidate_compress_pages(sbi, inode->i_ino); 728 + 741 729 if (inode->i_ino == F2FS_NODE_INO(sbi) || 742 - inode->i_ino == F2FS_META_INO(sbi)) 730 + inode->i_ino == F2FS_META_INO(sbi) || 731 + inode->i_ino == F2FS_COMPRESS_INO(sbi)) 743 732 goto out_clear; 744 733 745 734 f2fs_bug_on(sbi, get_dirty_pages(inode));
+27 -9
fs/f2fs/namei.c
··· 153 153 return ERR_PTR(err); 154 154 } 155 155 156 - static inline int is_extension_exist(const unsigned char *s, const char *sub) 156 + static inline int is_extension_exist(const unsigned char *s, const char *sub, 157 + bool tmp_ext) 157 158 { 158 159 size_t slen = strlen(s); 159 160 size_t sublen = strlen(sub); ··· 169 168 */ 170 169 if (slen < sublen + 2) 171 170 return 0; 171 + 172 + if (!tmp_ext) { 173 + /* file has no temp extension */ 174 + if (s[slen - sublen - 1] != '.') 175 + return 0; 176 + return !strncasecmp(s + slen - sublen, sub, sublen); 177 + } 172 178 173 179 for (i = 1; i < slen - sublen; i++) { 174 180 if (s[i] != '.') ··· 202 194 hot_count = sbi->raw_super->hot_ext_count; 203 195 204 196 for (i = 0; i < cold_count + hot_count; i++) { 205 - if (is_extension_exist(name, extlist[i])) 197 + if (is_extension_exist(name, extlist[i], true)) 206 198 break; 207 199 } 208 200 ··· 287 279 const unsigned char *name) 288 280 { 289 281 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; 290 - unsigned char (*ext)[F2FS_EXTENSION_LEN]; 291 - unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; 282 + unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions; 283 + unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions; 284 + unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; 285 + unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; 292 286 int i, cold_count, hot_count; 293 287 294 288 if (!f2fs_sb_has_compression(sbi) || 295 - is_inode_flag_set(inode, FI_COMPRESSED_FILE) || 296 289 F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || 297 - !f2fs_may_compress(inode)) 290 + !f2fs_may_compress(inode) || 291 + (!ext_cnt && !noext_cnt)) 298 292 return; 299 293 300 294 down_read(&sbi->sb_lock); ··· 305 295 hot_count = sbi->raw_super->hot_ext_count; 306 296 307 297 for (i = cold_count; i < cold_count + hot_count; i++) { 308 - if (is_extension_exist(name, extlist[i])) { 298 + if (is_extension_exist(name, extlist[i], false)) { 309 299 up_read(&sbi->sb_lock); 310 300 return; 311 301 } ··· 313 303 314 304 up_read(&sbi->sb_lock); 315 305 316 - ext = F2FS_OPTION(sbi).extensions; 306 + for (i = 0; i < noext_cnt; i++) { 307 + if (is_extension_exist(name, noext[i], false)) { 308 + f2fs_disable_compressed_file(inode); 309 + return; 310 + } 311 + } 312 + 313 + if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) 314 + return; 317 315 318 316 for (i = 0; i < ext_cnt; i++) { 319 - if (!is_extension_exist(name, ext[i])) 317 + if (!is_extension_exist(name, ext[i], false)) 320 318 continue; 321 319 322 320 set_compress_context(inode);
+23 -12
fs/f2fs/node.c
··· 97 97 mem_size = (atomic_read(&dcc->discard_cmd_cnt) * 98 98 sizeof(struct discard_cmd)) >> PAGE_SHIFT; 99 99 res = mem_size < (avail_ram * nm_i->ram_thresh / 100); 100 + } else if (type == COMPRESS_PAGE) { 101 + #ifdef CONFIG_F2FS_FS_COMPRESSION 102 + unsigned long free_ram = val.freeram; 103 + 104 + /* 105 + * free memory is lower than watermark or cached page count 106 + * exceed threshold, deny caching compress page. 107 + */ 108 + res = (free_ram > avail_ram * sbi->compress_watermark / 100) && 109 + (COMPRESS_MAPPING(sbi)->nrpages < 110 + free_ram * sbi->compress_percent / 100); 111 + #else 112 + res = false; 113 + #endif 100 114 } else { 101 115 if (!sbi->sb->s_bdi->wb.dirty_exceeded) 102 116 return true; ··· 1549 1535 trace_f2fs_writepage(page, NODE); 1550 1536 1551 1537 if (unlikely(f2fs_cp_error(sbi))) { 1552 - if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) { 1553 - ClearPageUptodate(page); 1554 - dec_page_count(sbi, F2FS_DIRTY_NODES); 1555 - unlock_page(page); 1556 - return 0; 1557 - } 1558 - goto redirty_out; 1538 + ClearPageUptodate(page); 1539 + dec_page_count(sbi, F2FS_DIRTY_NODES); 1540 + unlock_page(page); 1541 + return 0; 1559 1542 } 1560 1543 1561 1544 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) ··· 1871 1860 } 1872 1861 1873 1862 /* flush inline_data, if it's async context. */ 1874 - if (is_inline_node(page)) { 1875 - clear_inline_node(page); 1863 + if (page_private_inline(page)) { 1864 + clear_page_private_inline(page); 1876 1865 unlock_page(page); 1877 1866 flush_inline_data(sbi, ino_of_node(page)); 1878 1867 continue; ··· 1952 1941 goto write_node; 1953 1942 1954 1943 /* flush inline_data */ 1955 - if (is_inline_node(page)) { 1956 - clear_inline_node(page); 1944 + if (page_private_inline(page)) { 1945 + clear_page_private_inline(page); 1957 1946 unlock_page(page); 1958 1947 flush_inline_data(sbi, ino_of_node(page)); 1959 1948 goto lock_node; ··· 2107 2096 if (!PageDirty(page)) { 2108 2097 __set_page_dirty_nobuffers(page); 2109 2098 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES); 2110 - f2fs_set_page_private(page, 0); 2099 + set_page_private_reference(page); 2111 2100 return 1; 2112 2101 } 2113 2102 return 0;
+4 -29
fs/f2fs/node.h
··· 38 38 /* return value for read_node_page */ 39 39 #define LOCKED_PAGE 1 40 40 41 + /* check pinned file's alignment status of physical blocks */ 42 + #define FILE_NOT_ALIGNED 1 43 + 41 44 /* For flag in struct node_info */ 42 45 enum { 43 46 IS_CHECKPOINTED, /* is it checkpointed before? */ ··· 151 148 EXTENT_CACHE, /* indicates extent cache */ 152 149 INMEM_PAGES, /* indicates inmemory pages */ 153 150 DISCARD_CACHE, /* indicates memory of cached discard cmds */ 151 + COMPRESS_PAGE, /* indicates memory of cached compressed pages */ 154 152 BASE_CHECK, /* check kernel status */ 155 153 }; 156 154 ··· 393 389 * - Mark cold node blocks in their node footer 394 390 * - Mark cold data pages in page cache 395 391 */ 396 - static inline int is_cold_data(struct page *page) 397 - { 398 - return PageChecked(page); 399 - } 400 - 401 - static inline void set_cold_data(struct page *page) 402 - { 403 - SetPageChecked(page); 404 - } 405 - 406 - static inline void clear_cold_data(struct page *page) 407 - { 408 - ClearPageChecked(page); 409 - } 410 392 411 393 static inline int is_node(struct page *page, int type) 412 394 { ··· 403 413 #define is_cold_node(page) is_node(page, COLD_BIT_SHIFT) 404 414 #define is_fsync_dnode(page) is_node(page, FSYNC_BIT_SHIFT) 405 415 #define is_dent_dnode(page) is_node(page, DENT_BIT_SHIFT) 406 - 407 - static inline int is_inline_node(struct page *page) 408 - { 409 - return PageChecked(page); 410 - } 411 - 412 - static inline void set_inline_node(struct page *page) 413 - { 414 - SetPageChecked(page); 415 - } 416 - 417 - static inline void clear_inline_node(struct page *page) 418 - { 419 - ClearPageChecked(page); 420 - } 421 416 422 417 static inline void set_cold_node(struct page *page, bool is_dir) 423 418 {
+19 -10
fs/f2fs/recovery.c
··· 45 45 46 46 static struct kmem_cache *fsync_entry_slab; 47 47 48 + #ifdef CONFIG_UNICODE 49 + extern struct kmem_cache *f2fs_cf_name_slab; 50 + #endif 51 + 48 52 bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi) 49 53 { 50 54 s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count); ··· 149 145 f2fs_hash_filename(dir, fname); 150 146 #ifdef CONFIG_UNICODE 151 147 /* Case-sensitive match is fine for recovery */ 152 - kfree(fname->cf_name.name); 148 + kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); 153 149 fname->cf_name.name = NULL; 154 150 #endif 155 151 } else { ··· 792 788 quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY); 793 789 #endif 794 790 795 - fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry", 796 - sizeof(struct fsync_inode_entry)); 797 - if (!fsync_entry_slab) { 798 - err = -ENOMEM; 799 - goto out; 800 - } 801 - 802 791 INIT_LIST_HEAD(&inode_list); 803 792 INIT_LIST_HEAD(&tmp_inode_list); 804 793 INIT_LIST_HEAD(&dir_list); ··· 864 867 } 865 868 } 866 869 867 - kmem_cache_destroy(fsync_entry_slab); 868 - out: 869 870 #ifdef CONFIG_QUOTA 870 871 /* Turn quotas off */ 871 872 if (quota_enabled) ··· 872 877 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ 873 878 874 879 return ret ? ret : err; 880 + } 881 + 882 + int __init f2fs_create_recovery_cache(void) 883 + { 884 + fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry", 885 + sizeof(struct fsync_inode_entry)); 886 + if (!fsync_entry_slab) 887 + return -ENOMEM; 888 + return 0; 889 + } 890 + 891 + void f2fs_destroy_recovery_cache(void) 892 + { 893 + kmem_cache_destroy(fsync_entry_slab); 875 894 }
+23 -11
fs/f2fs/segment.c
··· 186 186 { 187 187 struct inmem_pages *new; 188 188 189 - if (PagePrivate(page)) 190 - set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE); 191 - else 192 - f2fs_set_page_private(page, ATOMIC_WRITTEN_PAGE); 189 + set_page_private_atomic(page); 193 190 194 191 new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS); 195 192 ··· 269 272 /* we don't need to invalidate this in the sccessful status */ 270 273 if (drop || recover) { 271 274 ClearPageUptodate(page); 272 - clear_cold_data(page); 275 + clear_page_private_gcing(page); 273 276 } 274 - f2fs_clear_page_private(page); 277 + detach_page_private(page); 278 + set_page_private(page, 0); 275 279 f2fs_put_page(page, 1); 276 280 277 281 list_del(&cur->list); ··· 355 357 struct list_head *head = &fi->inmem_pages; 356 358 struct inmem_pages *cur = NULL; 357 359 358 - f2fs_bug_on(sbi, !IS_ATOMIC_WRITTEN_PAGE(page)); 360 + f2fs_bug_on(sbi, !page_private_atomic(page)); 359 361 360 362 mutex_lock(&fi->inmem_lock); 361 363 list_for_each_entry(cur, head, list) { ··· 371 373 kmem_cache_free(inmem_entry_slab, cur); 372 374 373 375 ClearPageUptodate(page); 374 - f2fs_clear_page_private(page); 376 + clear_page_private_atomic(page); 375 377 f2fs_put_page(page, 0); 378 + 379 + detach_page_private(page); 380 + set_page_private(page, 0); 376 381 377 382 trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE); 378 383 } ··· 2322 2321 return; 2323 2322 2324 2323 invalidate_mapping_pages(META_MAPPING(sbi), addr, addr); 2324 + f2fs_invalidate_compress_page(sbi, addr); 2325 2325 2326 2326 /* add it into sit main buffer */ 2327 2327 down_write(&sit_i->sentry_lock); ··· 3291 3289 if (fio->type == DATA) { 3292 3290 struct inode *inode = fio->page->mapping->host; 3293 3291 3294 - if (is_cold_data(fio->page)) { 3292 + if (is_inode_flag_set(inode, FI_ALIGNED_WRITE)) 3293 + return CURSEG_COLD_DATA_PINNED; 3294 + 3295 + if (page_private_gcing(fio->page)) { 3295 3296 if (fio->sbi->am.atgc_enabled && 3296 3297 (fio->io_type == FS_DATA_IO) && 3297 3298 (fio->sbi->gc_mode != GC_URGENT_HIGH)) ··· 3473 3468 reallocate: 3474 3469 f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, 3475 3470 &fio->new_blkaddr, sum, type, fio); 3476 - if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO) 3471 + if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO) { 3477 3472 invalidate_mapping_pages(META_MAPPING(fio->sbi), 3478 3473 fio->old_blkaddr, fio->old_blkaddr); 3474 + f2fs_invalidate_compress_page(fio->sbi, fio->old_blkaddr); 3475 + } 3479 3476 3480 3477 /* writeout dirty page into bdev */ 3481 3478 f2fs_submit_page_write(fio); ··· 3667 3660 if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) { 3668 3661 invalidate_mapping_pages(META_MAPPING(sbi), 3669 3662 old_blkaddr, old_blkaddr); 3663 + f2fs_invalidate_compress_page(sbi, old_blkaddr); 3670 3664 if (!from_gc) 3671 3665 update_segment_mtime(sbi, old_blkaddr, 0); 3672 3666 update_sit_entry(sbi, old_blkaddr, -1); ··· 3927 3919 /* sanity check for summary blocks */ 3928 3920 if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES || 3929 3921 sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES) { 3930 - f2fs_err(sbi, "invalid journal entries nats %u sits %u\n", 3922 + f2fs_err(sbi, "invalid journal entries nats %u sits %u", 3931 3923 nats_in_cursum(nat_j), sits_in_cursum(sit_j)); 3932 3924 return -EINVAL; 3933 3925 } ··· 4689 4681 struct curseg_info *curseg = CURSEG_I(sbi, i); 4690 4682 struct seg_entry *se = get_seg_entry(sbi, curseg->segno); 4691 4683 unsigned int blkofs = curseg->next_blkoff; 4684 + 4685 + if (f2fs_sb_has_readonly(sbi) && 4686 + i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE) 4687 + continue; 4692 4688 4693 4689 sanity_check_seg_type(sbi, curseg->seg_type); 4694 4690
+177 -11
fs/f2fs/super.c
··· 148 148 Opt_compress_algorithm, 149 149 Opt_compress_log_size, 150 150 Opt_compress_extension, 151 + Opt_nocompress_extension, 151 152 Opt_compress_chksum, 152 153 Opt_compress_mode, 154 + Opt_compress_cache, 153 155 Opt_atgc, 154 156 Opt_gc_merge, 155 157 Opt_nogc_merge, ··· 224 222 {Opt_compress_algorithm, "compress_algorithm=%s"}, 225 223 {Opt_compress_log_size, "compress_log_size=%u"}, 226 224 {Opt_compress_extension, "compress_extension=%s"}, 225 + {Opt_nocompress_extension, "nocompress_extension=%s"}, 227 226 {Opt_compress_chksum, "compress_chksum"}, 228 227 {Opt_compress_mode, "compress_mode=%s"}, 228 + {Opt_compress_cache, "compress_cache"}, 229 229 {Opt_atgc, "atgc"}, 230 230 {Opt_gc_merge, "gc_merge"}, 231 231 {Opt_nogc_merge, "nogc_merge"}, ··· 279 275 280 276 return 0; 281 277 } 278 + 279 + struct kmem_cache *f2fs_cf_name_slab; 280 + static int __init f2fs_create_casefold_cache(void) 281 + { 282 + f2fs_cf_name_slab = f2fs_kmem_cache_create("f2fs_casefolded_name", 283 + F2FS_NAME_LEN); 284 + if (!f2fs_cf_name_slab) 285 + return -ENOMEM; 286 + return 0; 287 + } 288 + 289 + static void f2fs_destroy_casefold_cache(void) 290 + { 291 + kmem_cache_destroy(f2fs_cf_name_slab); 292 + } 293 + #else 294 + static int __init f2fs_create_casefold_cache(void) { return 0; } 295 + static void f2fs_destroy_casefold_cache(void) { } 282 296 #endif 283 297 284 298 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) ··· 495 473 } 496 474 497 475 #ifdef CONFIG_F2FS_FS_COMPRESSION 476 + /* 477 + * 1. The same extension name cannot not appear in both compress and non-compress extension 478 + * at the same time. 479 + * 2. If the compress extension specifies all files, the types specified by the non-compress 480 + * extension will be treated as special cases and will not be compressed. 481 + * 3. Don't allow the non-compress extension specifies all files. 482 + */ 483 + static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi) 484 + { 485 + unsigned char (*ext)[F2FS_EXTENSION_LEN]; 486 + unsigned char (*noext)[F2FS_EXTENSION_LEN]; 487 + int ext_cnt, noext_cnt, index = 0, no_index = 0; 488 + 489 + ext = F2FS_OPTION(sbi).extensions; 490 + ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; 491 + noext = F2FS_OPTION(sbi).noextensions; 492 + noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; 493 + 494 + if (!noext_cnt) 495 + return 0; 496 + 497 + for (no_index = 0; no_index < noext_cnt; no_index++) { 498 + if (!strcasecmp("*", noext[no_index])) { 499 + f2fs_info(sbi, "Don't allow the nocompress extension specifies all files"); 500 + return -EINVAL; 501 + } 502 + for (index = 0; index < ext_cnt; index++) { 503 + if (!strcasecmp(ext[index], noext[no_index])) { 504 + f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension", 505 + ext[index]); 506 + return -EINVAL; 507 + } 508 + } 509 + } 510 + return 0; 511 + } 512 + 498 513 #ifdef CONFIG_F2FS_FS_LZ4 499 514 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) 500 515 { ··· 605 546 substring_t args[MAX_OPT_ARGS]; 606 547 #ifdef CONFIG_F2FS_FS_COMPRESSION 607 548 unsigned char (*ext)[F2FS_EXTENSION_LEN]; 608 - int ext_cnt; 549 + unsigned char (*noext)[F2FS_EXTENSION_LEN]; 550 + int ext_cnt, noext_cnt; 609 551 #endif 610 552 char *p, *name; 611 553 int arg = 0; ··· 615 555 int ret; 616 556 617 557 if (!options) 618 - return 0; 558 + goto default_check; 619 559 620 560 while ((p = strsep(&options, ",")) != NULL) { 621 561 int token; ··· 1109 1049 F2FS_OPTION(sbi).compress_ext_cnt++; 1110 1050 kfree(name); 1111 1051 break; 1052 + case Opt_nocompress_extension: 1053 + if (!f2fs_sb_has_compression(sbi)) { 1054 + f2fs_info(sbi, "Image doesn't support compression"); 1055 + break; 1056 + } 1057 + name = match_strdup(&args[0]); 1058 + if (!name) 1059 + return -ENOMEM; 1060 + 1061 + noext = F2FS_OPTION(sbi).noextensions; 1062 + noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; 1063 + 1064 + if (strlen(name) >= F2FS_EXTENSION_LEN || 1065 + noext_cnt >= COMPRESS_EXT_NUM) { 1066 + f2fs_err(sbi, 1067 + "invalid extension length/number"); 1068 + kfree(name); 1069 + return -EINVAL; 1070 + } 1071 + 1072 + strcpy(noext[noext_cnt], name); 1073 + F2FS_OPTION(sbi).nocompress_ext_cnt++; 1074 + kfree(name); 1075 + break; 1112 1076 case Opt_compress_chksum: 1113 1077 F2FS_OPTION(sbi).compress_chksum = true; 1114 1078 break; ··· 1150 1066 } 1151 1067 kfree(name); 1152 1068 break; 1069 + case Opt_compress_cache: 1070 + set_opt(sbi, COMPRESS_CACHE); 1071 + break; 1153 1072 #else 1154 1073 case Opt_compress_algorithm: 1155 1074 case Opt_compress_log_size: 1156 1075 case Opt_compress_extension: 1076 + case Opt_nocompress_extension: 1157 1077 case Opt_compress_chksum: 1158 1078 case Opt_compress_mode: 1079 + case Opt_compress_cache: 1159 1080 f2fs_info(sbi, "compression options not supported"); 1160 1081 break; 1161 1082 #endif ··· 1179 1090 return -EINVAL; 1180 1091 } 1181 1092 } 1093 + default_check: 1182 1094 #ifdef CONFIG_QUOTA 1183 1095 if (f2fs_check_quota_options(sbi)) 1184 1096 return -EINVAL; ··· 1208 1118 #ifndef CONFIG_BLK_DEV_ZONED 1209 1119 if (f2fs_sb_has_blkzoned(sbi)) { 1210 1120 f2fs_err(sbi, "Zoned block device support is not enabled"); 1121 + return -EINVAL; 1122 + } 1123 + #endif 1124 + 1125 + #ifdef CONFIG_F2FS_FS_COMPRESSION 1126 + if (f2fs_test_compress_extension(sbi)) { 1127 + f2fs_err(sbi, "invalid compress or nocompress extension"); 1211 1128 return -EINVAL; 1212 1129 } 1213 1130 #endif ··· 1250 1153 } 1251 1154 1252 1155 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { 1253 - f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n"); 1156 + f2fs_err(sbi, "LFS not compatible with checkpoint=disable"); 1254 1157 return -EINVAL; 1255 1158 } 1256 1159 ··· 1259 1162 */ 1260 1163 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE) 1261 1164 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; 1165 + 1166 + if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { 1167 + f2fs_err(sbi, "Allow to mount readonly mode only"); 1168 + return -EROFS; 1169 + } 1262 1170 return 0; 1263 1171 } 1264 1172 ··· 1504 1402 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); 1505 1403 1506 1404 f2fs_bug_on(sbi, sbi->fsync_node_num); 1405 + 1406 + f2fs_destroy_compress_inode(sbi); 1507 1407 1508 1408 iput(sbi->node_inode); 1509 1409 sbi->node_inode = NULL; ··· 1769 1665 F2FS_OPTION(sbi).extensions[i]); 1770 1666 } 1771 1667 1668 + for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) { 1669 + seq_printf(seq, ",nocompress_extension=%s", 1670 + F2FS_OPTION(sbi).noextensions[i]); 1671 + } 1672 + 1772 1673 if (F2FS_OPTION(sbi).compress_chksum) 1773 1674 seq_puts(seq, ",compress_chksum"); 1774 1675 ··· 1781 1672 seq_printf(seq, ",compress_mode=%s", "fs"); 1782 1673 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) 1783 1674 seq_printf(seq, ",compress_mode=%s", "user"); 1675 + 1676 + if (test_opt(sbi, COMPRESS_CACHE)) 1677 + seq_puts(seq, ",compress_cache"); 1784 1678 } 1785 1679 #endif 1786 1680 ··· 1931 1819 static void default_options(struct f2fs_sb_info *sbi) 1932 1820 { 1933 1821 /* init some FS parameters */ 1934 - F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; 1822 + if (f2fs_sb_has_readonly(sbi)) 1823 + F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; 1824 + else 1825 + F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; 1826 + 1935 1827 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; 1936 1828 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; 1937 1829 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; ··· 2065 1949 bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); 2066 1950 bool no_io_align = !F2FS_IO_ALIGNED(sbi); 2067 1951 bool no_atgc = !test_opt(sbi, ATGC); 1952 + bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); 2068 1953 bool checkpoint_changed; 2069 1954 #ifdef CONFIG_QUOTA 2070 1955 int i, j; ··· 2121 2004 if (f2fs_readonly(sb) && (*flags & SB_RDONLY)) 2122 2005 goto skip; 2123 2006 2007 + if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { 2008 + err = -EROFS; 2009 + goto restore_opts; 2010 + } 2011 + 2124 2012 #ifdef CONFIG_QUOTA 2125 2013 if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) { 2126 2014 err = dquot_suspend(sb, -1); ··· 2160 2038 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { 2161 2039 err = -EINVAL; 2162 2040 f2fs_warn(sbi, "switch io_bits option is not allowed"); 2041 + goto restore_opts; 2042 + } 2043 + 2044 + if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { 2045 + err = -EINVAL; 2046 + f2fs_warn(sbi, "switch compress_cache option is not allowed"); 2163 2047 goto restore_opts; 2164 2048 } 2165 2049 ··· 3265 3137 ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); 3266 3138 reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); 3267 3139 3268 - if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS || 3140 + if (!f2fs_sb_has_readonly(sbi) && 3141 + unlikely(fsmeta < F2FS_MIN_META_SEGMENTS || 3269 3142 ovp_segments == 0 || reserved_segments == 0)) { 3270 3143 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); 3271 3144 return 1; 3272 3145 } 3273 - 3274 3146 user_block_count = le64_to_cpu(ckpt->user_block_count); 3275 - segment_count_main = le32_to_cpu(raw_super->segment_count_main); 3147 + segment_count_main = le32_to_cpu(raw_super->segment_count_main) + 3148 + (f2fs_sb_has_readonly(sbi) ? 1 : 0); 3276 3149 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); 3277 3150 if (!user_block_count || user_block_count >= 3278 3151 segment_count_main << log_blocks_per_seg) { ··· 3304 3175 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || 3305 3176 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) 3306 3177 return 1; 3178 + 3179 + if (f2fs_sb_has_readonly(sbi)) 3180 + goto check_data; 3181 + 3307 3182 for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) { 3308 3183 if (le32_to_cpu(ckpt->cur_node_segno[i]) == 3309 3184 le32_to_cpu(ckpt->cur_node_segno[j])) { ··· 3318 3185 } 3319 3186 } 3320 3187 } 3188 + check_data: 3321 3189 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { 3322 3190 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || 3323 3191 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) 3324 3192 return 1; 3193 + 3194 + if (f2fs_sb_has_readonly(sbi)) 3195 + goto skip_cross; 3196 + 3325 3197 for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) { 3326 3198 if (le32_to_cpu(ckpt->cur_data_segno[i]) == 3327 3199 le32_to_cpu(ckpt->cur_data_segno[j])) { ··· 3348 3210 } 3349 3211 } 3350 3212 } 3351 - 3213 + skip_cross: 3352 3214 sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 3353 3215 nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 3354 3216 ··· 3693 3555 #ifdef CONFIG_BLK_DEV_ZONED 3694 3556 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM && 3695 3557 !f2fs_sb_has_blkzoned(sbi)) { 3696 - f2fs_err(sbi, "Zoned block device feature not enabled\n"); 3558 + f2fs_err(sbi, "Zoned block device feature not enabled"); 3697 3559 return -EINVAL; 3698 3560 } 3699 3561 if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) { ··· 4078 3940 goto free_node_inode; 4079 3941 } 4080 3942 4081 - err = f2fs_register_sysfs(sbi); 3943 + err = f2fs_init_compress_inode(sbi); 4082 3944 if (err) 4083 3945 goto free_root_inode; 3946 + 3947 + err = f2fs_register_sysfs(sbi); 3948 + if (err) 3949 + goto free_compress_inode; 4084 3950 4085 3951 #ifdef CONFIG_QUOTA 4086 3952 /* Enable quota usage during mount */ ··· 4226 4084 /* evict some inodes being cached by GC */ 4227 4085 evict_inodes(sb); 4228 4086 f2fs_unregister_sysfs(sbi); 4087 + free_compress_inode: 4088 + f2fs_destroy_compress_inode(sbi); 4229 4089 free_root_inode: 4230 4090 dput(sb->s_root); 4231 4091 sb->s_root = NULL; ··· 4306 4162 f2fs_stop_gc_thread(sbi); 4307 4163 f2fs_stop_discard_thread(sbi); 4308 4164 4165 + #ifdef CONFIG_F2FS_FS_COMPRESSION 4166 + /* 4167 + * latter evict_inode() can bypass checking and invalidating 4168 + * compress inode cache. 4169 + */ 4170 + if (test_opt(sbi, COMPRESS_CACHE)) 4171 + truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); 4172 + #endif 4173 + 4309 4174 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || 4310 4175 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { 4311 4176 struct cp_control cpc = { ··· 4380 4227 err = f2fs_create_checkpoint_caches(); 4381 4228 if (err) 4382 4229 goto free_segment_manager_caches; 4383 - err = f2fs_create_extent_cache(); 4230 + err = f2fs_create_recovery_cache(); 4384 4231 if (err) 4385 4232 goto free_checkpoint_caches; 4233 + err = f2fs_create_extent_cache(); 4234 + if (err) 4235 + goto free_recovery_cache; 4386 4236 err = f2fs_create_garbage_collection_cache(); 4387 4237 if (err) 4388 4238 goto free_extent_cache; ··· 4414 4258 err = f2fs_init_compress_cache(); 4415 4259 if (err) 4416 4260 goto free_compress_mempool; 4261 + err = f2fs_create_casefold_cache(); 4262 + if (err) 4263 + goto free_compress_cache; 4417 4264 return 0; 4265 + free_compress_cache: 4266 + f2fs_destroy_compress_cache(); 4418 4267 free_compress_mempool: 4419 4268 f2fs_destroy_compress_mempool(); 4420 4269 free_bioset: ··· 4439 4278 f2fs_destroy_garbage_collection_cache(); 4440 4279 free_extent_cache: 4441 4280 f2fs_destroy_extent_cache(); 4281 + free_recovery_cache: 4282 + f2fs_destroy_recovery_cache(); 4442 4283 free_checkpoint_caches: 4443 4284 f2fs_destroy_checkpoint_caches(); 4444 4285 free_segment_manager_caches: ··· 4455 4292 4456 4293 static void __exit exit_f2fs_fs(void) 4457 4294 { 4295 + f2fs_destroy_casefold_cache(); 4458 4296 f2fs_destroy_compress_cache(); 4459 4297 f2fs_destroy_compress_mempool(); 4460 4298 f2fs_destroy_bioset(); ··· 4467 4303 f2fs_exit_sysfs(); 4468 4304 f2fs_destroy_garbage_collection_cache(); 4469 4305 f2fs_destroy_extent_cache(); 4306 + f2fs_destroy_recovery_cache(); 4470 4307 f2fs_destroy_checkpoint_caches(); 4471 4308 f2fs_destroy_segment_manager_caches(); 4472 4309 f2fs_destroy_node_manager_caches(); ··· 4480 4315 MODULE_AUTHOR("Samsung Electronics's Praesto Team"); 4481 4316 MODULE_DESCRIPTION("Flash Friendly File System"); 4482 4317 MODULE_LICENSE("GPL"); 4318 + MODULE_SOFTDEP("pre: crc32"); 4483 4319
+174 -58
fs/f2fs/sysfs.c
··· 37 37 #endif 38 38 RESERVED_BLOCKS, /* struct f2fs_sb_info */ 39 39 CPRC_INFO, /* struct ckpt_req_control */ 40 + ATGC_INFO, /* struct atgc_management */ 40 41 }; 41 42 42 43 struct f2fs_attr { ··· 76 75 #endif 77 76 else if (struct_type == CPRC_INFO) 78 77 return (unsigned char *)&sbi->cprc_info; 78 + else if (struct_type == ATGC_INFO) 79 + return (unsigned char *)&sbi->am; 79 80 return NULL; 80 81 } 81 82 ··· 158 155 if (f2fs_sb_has_casefold(sbi)) 159 156 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 160 157 len ? ", " : "", "casefold"); 158 + if (f2fs_sb_has_readonly(sbi)) 159 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 160 + len ? ", " : "", "readonly"); 161 161 if (f2fs_sb_has_compression(sbi)) 162 162 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 163 163 len ? ", " : "", "compression"); ··· 501 495 } 502 496 #endif 503 497 498 + if (!strcmp(a->attr.name, "atgc_candidate_ratio")) { 499 + if (t > 100) 500 + return -EINVAL; 501 + sbi->am.candidate_ratio = t; 502 + return count; 503 + } 504 + 505 + if (!strcmp(a->attr.name, "atgc_age_weight")) { 506 + if (t > 100) 507 + return -EINVAL; 508 + sbi->am.age_weight = t; 509 + return count; 510 + } 511 + 504 512 *ui = (unsigned int)t; 505 513 506 514 return count; ··· 566 546 complete(&sbi->s_kobj_unregister); 567 547 } 568 548 569 - enum feat_id { 570 - FEAT_CRYPTO = 0, 571 - FEAT_BLKZONED, 572 - FEAT_ATOMIC_WRITE, 573 - FEAT_EXTRA_ATTR, 574 - FEAT_PROJECT_QUOTA, 575 - FEAT_INODE_CHECKSUM, 576 - FEAT_FLEXIBLE_INLINE_XATTR, 577 - FEAT_QUOTA_INO, 578 - FEAT_INODE_CRTIME, 579 - FEAT_LOST_FOUND, 580 - FEAT_VERITY, 581 - FEAT_SB_CHECKSUM, 582 - FEAT_CASEFOLD, 583 - FEAT_COMPRESSION, 584 - FEAT_TEST_DUMMY_ENCRYPTION_V2, 585 - }; 586 - 549 + /* 550 + * Note that there are three feature list entries: 551 + * 1) /sys/fs/f2fs/features 552 + * : shows runtime features supported by in-kernel f2fs along with Kconfig. 553 + * - ref. F2FS_FEATURE_RO_ATTR() 554 + * 555 + * 2) /sys/fs/f2fs/$s_id/features <deprecated> 556 + * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This 557 + * won't add new feature anymore, and thus, users should check entries in 3) 558 + * instead of this 2). 559 + * 560 + * 3) /sys/fs/f2fs/$s_id/feature_list 561 + * : shows on-disk features enabled by mkfs.f2fs per instance, which follows 562 + * sysfs entry rule where each entry should expose single value. 563 + * This list covers old feature list provided by 2) and beyond. Therefore, 564 + * please add new on-disk feature in this list only. 565 + * - ref. F2FS_SB_FEATURE_RO_ATTR() 566 + */ 587 567 static ssize_t f2fs_feature_show(struct f2fs_attr *a, 588 568 struct f2fs_sb_info *sbi, char *buf) 589 569 { 590 - switch (a->id) { 591 - case FEAT_CRYPTO: 592 - case FEAT_BLKZONED: 593 - case FEAT_ATOMIC_WRITE: 594 - case FEAT_EXTRA_ATTR: 595 - case FEAT_PROJECT_QUOTA: 596 - case FEAT_INODE_CHECKSUM: 597 - case FEAT_FLEXIBLE_INLINE_XATTR: 598 - case FEAT_QUOTA_INO: 599 - case FEAT_INODE_CRTIME: 600 - case FEAT_LOST_FOUND: 601 - case FEAT_VERITY: 602 - case FEAT_SB_CHECKSUM: 603 - case FEAT_CASEFOLD: 604 - case FEAT_COMPRESSION: 605 - case FEAT_TEST_DUMMY_ENCRYPTION_V2: 570 + return sprintf(buf, "supported\n"); 571 + } 572 + 573 + #define F2FS_FEATURE_RO_ATTR(_name) \ 574 + static struct f2fs_attr f2fs_attr_##_name = { \ 575 + .attr = {.name = __stringify(_name), .mode = 0444 }, \ 576 + .show = f2fs_feature_show, \ 577 + } 578 + 579 + static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a, 580 + struct f2fs_sb_info *sbi, char *buf) 581 + { 582 + if (F2FS_HAS_FEATURE(sbi, a->id)) 606 583 return sprintf(buf, "supported\n"); 607 - } 608 - return 0; 584 + return sprintf(buf, "unsupported\n"); 585 + } 586 + 587 + #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \ 588 + static struct f2fs_attr f2fs_attr_sb_##_name = { \ 589 + .attr = {.name = __stringify(_name), .mode = 0444 }, \ 590 + .show = f2fs_sb_feature_show, \ 591 + .id = F2FS_FEATURE_##_feat, \ 609 592 } 610 593 611 594 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ ··· 627 604 628 605 #define F2FS_GENERAL_RO_ATTR(name) \ 629 606 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) 630 - 631 - #define F2FS_FEATURE_RO_ATTR(_name, _id) \ 632 - static struct f2fs_attr f2fs_attr_##_name = { \ 633 - .attr = {.name = __stringify(_name), .mode = 0444 }, \ 634 - .show = f2fs_feature_show, \ 635 - .id = _id, \ 636 - } 637 607 638 608 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \ 639 609 static struct f2fs_attr f2fs_attr_##_name = { \ ··· 701 685 #endif 702 686 703 687 #ifdef CONFIG_FS_ENCRYPTION 704 - F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); 705 - F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2, FEAT_TEST_DUMMY_ENCRYPTION_V2); 688 + F2FS_FEATURE_RO_ATTR(encryption); 689 + F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2); 690 + #ifdef CONFIG_UNICODE 691 + F2FS_FEATURE_RO_ATTR(encrypted_casefold); 706 692 #endif 693 + #endif /* CONFIG_FS_ENCRYPTION */ 707 694 #ifdef CONFIG_BLK_DEV_ZONED 708 - F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED); 695 + F2FS_FEATURE_RO_ATTR(block_zoned); 709 696 #endif 710 - F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE); 711 - F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR); 712 - F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA); 713 - F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM); 714 - F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); 715 - F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); 716 - F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); 717 - F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); 697 + F2FS_FEATURE_RO_ATTR(atomic_write); 698 + F2FS_FEATURE_RO_ATTR(extra_attr); 699 + F2FS_FEATURE_RO_ATTR(project_quota); 700 + F2FS_FEATURE_RO_ATTR(inode_checksum); 701 + F2FS_FEATURE_RO_ATTR(flexible_inline_xattr); 702 + F2FS_FEATURE_RO_ATTR(quota_ino); 703 + F2FS_FEATURE_RO_ATTR(inode_crtime); 704 + F2FS_FEATURE_RO_ATTR(lost_found); 718 705 #ifdef CONFIG_FS_VERITY 719 - F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY); 706 + F2FS_FEATURE_RO_ATTR(verity); 720 707 #endif 721 - F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); 722 - F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD); 708 + F2FS_FEATURE_RO_ATTR(sb_checksum); 709 + #ifdef CONFIG_UNICODE 710 + F2FS_FEATURE_RO_ATTR(casefold); 711 + #endif 712 + F2FS_FEATURE_RO_ATTR(readonly); 723 713 #ifdef CONFIG_F2FS_FS_COMPRESSION 724 - F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION); 714 + F2FS_FEATURE_RO_ATTR(compression); 725 715 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block); 726 716 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block); 727 717 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode); 728 718 #endif 719 + F2FS_FEATURE_RO_ATTR(pin_file); 720 + 721 + /* For ATGC */ 722 + F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio); 723 + F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count); 724 + F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight); 725 + F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold); 729 726 730 727 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 731 728 static struct attribute *f2fs_attrs[] = { ··· 807 778 ATTR_LIST(compr_saved_block), 808 779 ATTR_LIST(compr_new_inode), 809 780 #endif 781 + /* For ATGC */ 782 + ATTR_LIST(atgc_candidate_ratio), 783 + ATTR_LIST(atgc_candidate_count), 784 + ATTR_LIST(atgc_age_weight), 785 + ATTR_LIST(atgc_age_threshold), 810 786 NULL, 811 787 }; 812 788 ATTRIBUTE_GROUPS(f2fs); ··· 820 786 #ifdef CONFIG_FS_ENCRYPTION 821 787 ATTR_LIST(encryption), 822 788 ATTR_LIST(test_dummy_encryption_v2), 789 + #ifdef CONFIG_UNICODE 790 + ATTR_LIST(encrypted_casefold), 823 791 #endif 792 + #endif /* CONFIG_FS_ENCRYPTION */ 824 793 #ifdef CONFIG_BLK_DEV_ZONED 825 794 ATTR_LIST(block_zoned), 826 795 #endif ··· 839 802 ATTR_LIST(verity), 840 803 #endif 841 804 ATTR_LIST(sb_checksum), 805 + #ifdef CONFIG_UNICODE 842 806 ATTR_LIST(casefold), 807 + #endif 808 + ATTR_LIST(readonly), 843 809 #ifdef CONFIG_F2FS_FS_COMPRESSION 844 810 ATTR_LIST(compression), 845 811 #endif 812 + ATTR_LIST(pin_file), 846 813 NULL, 847 814 }; 848 815 ATTRIBUTE_GROUPS(f2fs_feat); ··· 857 816 NULL, 858 817 }; 859 818 ATTRIBUTE_GROUPS(f2fs_stat); 819 + 820 + F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT); 821 + F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED); 822 + F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR); 823 + F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA); 824 + F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM); 825 + F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 826 + F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO); 827 + F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME); 828 + F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND); 829 + F2FS_SB_FEATURE_RO_ATTR(verity, VERITY); 830 + F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM); 831 + F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD); 832 + F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION); 833 + F2FS_SB_FEATURE_RO_ATTR(readonly, RO); 834 + 835 + static struct attribute *f2fs_sb_feat_attrs[] = { 836 + ATTR_LIST(sb_encryption), 837 + ATTR_LIST(sb_block_zoned), 838 + ATTR_LIST(sb_extra_attr), 839 + ATTR_LIST(sb_project_quota), 840 + ATTR_LIST(sb_inode_checksum), 841 + ATTR_LIST(sb_flexible_inline_xattr), 842 + ATTR_LIST(sb_quota_ino), 843 + ATTR_LIST(sb_inode_crtime), 844 + ATTR_LIST(sb_lost_found), 845 + ATTR_LIST(sb_verity), 846 + ATTR_LIST(sb_sb_checksum), 847 + ATTR_LIST(sb_casefold), 848 + ATTR_LIST(sb_compression), 849 + ATTR_LIST(sb_readonly), 850 + NULL, 851 + }; 852 + ATTRIBUTE_GROUPS(f2fs_sb_feat); 860 853 861 854 static const struct sysfs_ops f2fs_attr_ops = { 862 855 .show = f2fs_attr_show, ··· 956 881 .default_groups = f2fs_stat_groups, 957 882 .sysfs_ops = &f2fs_stat_attr_ops, 958 883 .release = f2fs_stat_kobj_release, 884 + }; 885 + 886 + static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj, 887 + struct attribute *attr, char *buf) 888 + { 889 + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 890 + s_feature_list_kobj); 891 + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 892 + 893 + return a->show ? a->show(a, sbi, buf) : 0; 894 + } 895 + 896 + static void f2fs_feature_list_kobj_release(struct kobject *kobj) 897 + { 898 + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 899 + s_feature_list_kobj); 900 + complete(&sbi->s_feature_list_kobj_unregister); 901 + } 902 + 903 + static const struct sysfs_ops f2fs_feature_list_attr_ops = { 904 + .show = f2fs_sb_feat_attr_show, 905 + }; 906 + 907 + static struct kobj_type f2fs_feature_list_ktype = { 908 + .default_groups = f2fs_sb_feat_groups, 909 + .sysfs_ops = &f2fs_feature_list_attr_ops, 910 + .release = f2fs_feature_list_kobj_release, 959 911 }; 960 912 961 913 static int __maybe_unused segment_info_seq_show(struct seq_file *seq, ··· 1201 1099 if (err) 1202 1100 goto put_stat_kobj; 1203 1101 1102 + sbi->s_feature_list_kobj.kset = &f2fs_kset; 1103 + init_completion(&sbi->s_feature_list_kobj_unregister); 1104 + err = kobject_init_and_add(&sbi->s_feature_list_kobj, 1105 + &f2fs_feature_list_ktype, 1106 + &sbi->s_kobj, "feature_list"); 1107 + if (err) 1108 + goto put_feature_list_kobj; 1109 + 1204 1110 if (f2fs_proc_root) 1205 1111 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1206 1112 ··· 1223 1113 victim_bits_seq_show, sb); 1224 1114 } 1225 1115 return 0; 1116 + put_feature_list_kobj: 1117 + kobject_put(&sbi->s_feature_list_kobj); 1118 + wait_for_completion(&sbi->s_feature_list_kobj_unregister); 1226 1119 put_stat_kobj: 1227 1120 kobject_put(&sbi->s_stat_kobj); 1228 1121 wait_for_completion(&sbi->s_stat_kobj_unregister); ··· 1248 1135 kobject_del(&sbi->s_stat_kobj); 1249 1136 kobject_put(&sbi->s_stat_kobj); 1250 1137 wait_for_completion(&sbi->s_stat_kobj_unregister); 1138 + kobject_del(&sbi->s_feature_list_kobj); 1139 + kobject_put(&sbi->s_feature_list_kobj); 1140 + wait_for_completion(&sbi->s_feature_list_kobj_unregister); 1251 1141 1252 1142 kobject_del(&sbi->s_kobj); 1253 1143 kobject_put(&sbi->s_kobj);
+2
include/linux/f2fs_fs.h
··· 34 34 #define F2FS_ROOT_INO(sbi) ((sbi)->root_ino_num) 35 35 #define F2FS_NODE_INO(sbi) ((sbi)->node_ino_num) 36 36 #define F2FS_META_INO(sbi) ((sbi)->meta_ino_num) 37 + #define F2FS_COMPRESS_INO(sbi) (NM_I(sbi)->max_nid) 37 38 38 39 #define F2FS_MAX_QUOTAS 3 39 40 ··· 230 229 #define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */ 231 230 #define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */ 232 231 #define F2FS_PIN_FILE 0x40 /* file should not be gced */ 232 + #define F2FS_COMPRESS_RELEASED 0x80 /* file released compressed blocks */ 233 233 234 234 struct f2fs_inode { 235 235 __le16 i_mode; /* file mode */