xref: /linux/Documentation/filesystems/f2fs.rst (revision 10a26878564f27327b12e8f4b4d8d7b43065fae5)
189272ca1SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
289272ca1SMauro Carvalho Chehab
389272ca1SMauro Carvalho Chehab==========================================
489272ca1SMauro Carvalho ChehabWHAT IS Flash-Friendly File System (F2FS)?
589272ca1SMauro Carvalho Chehab==========================================
689272ca1SMauro Carvalho Chehab
789272ca1SMauro Carvalho ChehabNAND flash memory-based storage devices, such as SSD, eMMC, and SD cards, have
889272ca1SMauro Carvalho Chehabbeen equipped on a variety systems ranging from mobile to server systems. Since
989272ca1SMauro Carvalho Chehabthey are known to have different characteristics from the conventional rotating
1089272ca1SMauro Carvalho Chehabdisks, a file system, an upper layer to the storage device, should adapt to the
1189272ca1SMauro Carvalho Chehabchanges from the sketch in the design level.
1289272ca1SMauro Carvalho Chehab
1389272ca1SMauro Carvalho ChehabF2FS is a file system exploiting NAND flash memory-based storage devices, which
1489272ca1SMauro Carvalho Chehabis based on Log-structured File System (LFS). The design has been focused on
1589272ca1SMauro Carvalho Chehabaddressing the fundamental issues in LFS, which are snowball effect of wandering
1689272ca1SMauro Carvalho Chehabtree and high cleaning overhead.
1789272ca1SMauro Carvalho Chehab
1889272ca1SMauro Carvalho ChehabSince a NAND flash memory-based storage device shows different characteristic
1989272ca1SMauro Carvalho Chehabaccording to its internal geometry or flash memory management scheme, namely FTL,
2089272ca1SMauro Carvalho ChehabF2FS and its tools support various parameters not only for configuring on-disk
2189272ca1SMauro Carvalho Chehablayout, but also for selecting allocation and cleaning algorithms.
2289272ca1SMauro Carvalho Chehab
2389272ca1SMauro Carvalho ChehabThe following git tree provides the file system formatting tool (mkfs.f2fs),
2489272ca1SMauro Carvalho Chehaba consistency checking tool (fsck.f2fs), and a debugging tool (dump.f2fs).
2589272ca1SMauro Carvalho Chehab
2689272ca1SMauro Carvalho Chehab- git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git
2789272ca1SMauro Carvalho Chehab
2889272ca1SMauro Carvalho ChehabFor reporting bugs and sending patches, please use the following mailing list:
2989272ca1SMauro Carvalho Chehab
3089272ca1SMauro Carvalho Chehab- linux-f2fs-devel@lists.sourceforge.net
3189272ca1SMauro Carvalho Chehab
3289272ca1SMauro Carvalho ChehabBackground and Design issues
3389272ca1SMauro Carvalho Chehab============================
3489272ca1SMauro Carvalho Chehab
3589272ca1SMauro Carvalho ChehabLog-structured File System (LFS)
3689272ca1SMauro Carvalho Chehab--------------------------------
3789272ca1SMauro Carvalho Chehab"A log-structured file system writes all modifications to disk sequentially in
3889272ca1SMauro Carvalho Chehaba log-like structure, thereby speeding up  both file writing and crash recovery.
3989272ca1SMauro Carvalho ChehabThe log is the only structure on disk; it contains indexing information so that
4089272ca1SMauro Carvalho Chehabfiles can be read back from the log efficiently. In order to maintain large free
4189272ca1SMauro Carvalho Chehabareas on disk for fast writing, we divide  the log into segments and use a
4289272ca1SMauro Carvalho Chehabsegment cleaner to compress the live information from heavily fragmented
4389272ca1SMauro Carvalho Chehabsegments." from Rosenblum, M. and Ousterhout, J. K., 1992, "The design and
4489272ca1SMauro Carvalho Chehabimplementation of a log-structured file system", ACM Trans. Computer Systems
4589272ca1SMauro Carvalho Chehab10, 1, 26–52.
4689272ca1SMauro Carvalho Chehab
4789272ca1SMauro Carvalho ChehabWandering Tree Problem
4889272ca1SMauro Carvalho Chehab----------------------
4989272ca1SMauro Carvalho ChehabIn LFS, when a file data is updated and written to the end of log, its direct
5089272ca1SMauro Carvalho Chehabpointer block is updated due to the changed location. Then the indirect pointer
5189272ca1SMauro Carvalho Chehabblock is also updated due to the direct pointer block update. In this manner,
5289272ca1SMauro Carvalho Chehabthe upper index structures such as inode, inode map, and checkpoint block are
5389272ca1SMauro Carvalho Chehabalso updated recursively. This problem is called as wandering tree problem [1],
5489272ca1SMauro Carvalho Chehaband in order to enhance the performance, it should eliminate or relax the update
5589272ca1SMauro Carvalho Chehabpropagation as much as possible.
5689272ca1SMauro Carvalho Chehab
5789272ca1SMauro Carvalho Chehab[1] Bityutskiy, A. 2005. JFFS3 design issues. http://www.linux-mtd.infradead.org/
5889272ca1SMauro Carvalho Chehab
5989272ca1SMauro Carvalho ChehabCleaning Overhead
6089272ca1SMauro Carvalho Chehab-----------------
6189272ca1SMauro Carvalho ChehabSince LFS is based on out-of-place writes, it produces so many obsolete blocks
6289272ca1SMauro Carvalho Chehabscattered across the whole storage. In order to serve new empty log space, it
6389272ca1SMauro Carvalho Chehabneeds to reclaim these obsolete blocks seamlessly to users. This job is called
6489272ca1SMauro Carvalho Chehabas a cleaning process.
6589272ca1SMauro Carvalho Chehab
6689272ca1SMauro Carvalho ChehabThe process consists of three operations as follows.
6789272ca1SMauro Carvalho Chehab
6889272ca1SMauro Carvalho Chehab1. A victim segment is selected through referencing segment usage table.
6989272ca1SMauro Carvalho Chehab2. It loads parent index structures of all the data in the victim identified by
7089272ca1SMauro Carvalho Chehab   segment summary blocks.
7189272ca1SMauro Carvalho Chehab3. It checks the cross-reference between the data and its parent index structure.
7289272ca1SMauro Carvalho Chehab4. It moves valid data selectively.
7389272ca1SMauro Carvalho Chehab
7489272ca1SMauro Carvalho ChehabThis cleaning job may cause unexpected long delays, so the most important goal
7589272ca1SMauro Carvalho Chehabis to hide the latencies to users. And also definitely, it should reduce the
7689272ca1SMauro Carvalho Chehabamount of valid data to be moved, and move them quickly as well.
7789272ca1SMauro Carvalho Chehab
7889272ca1SMauro Carvalho ChehabKey Features
7989272ca1SMauro Carvalho Chehab============
8089272ca1SMauro Carvalho Chehab
8189272ca1SMauro Carvalho ChehabFlash Awareness
8289272ca1SMauro Carvalho Chehab---------------
8389272ca1SMauro Carvalho Chehab- Enlarge the random write area for better performance, but provide the high
8489272ca1SMauro Carvalho Chehab  spatial locality
8589272ca1SMauro Carvalho Chehab- Align FS data structures to the operational units in FTL as best efforts
8689272ca1SMauro Carvalho Chehab
8789272ca1SMauro Carvalho ChehabWandering Tree Problem
8889272ca1SMauro Carvalho Chehab----------------------
8989272ca1SMauro Carvalho Chehab- Use a term, “node”, that represents inodes as well as various pointer blocks
9089272ca1SMauro Carvalho Chehab- Introduce Node Address Table (NAT) containing the locations of all the “node”
9189272ca1SMauro Carvalho Chehab  blocks; this will cut off the update propagation.
9289272ca1SMauro Carvalho Chehab
9389272ca1SMauro Carvalho ChehabCleaning Overhead
9489272ca1SMauro Carvalho Chehab-----------------
9589272ca1SMauro Carvalho Chehab- Support a background cleaning process
9689272ca1SMauro Carvalho Chehab- Support greedy and cost-benefit algorithms for victim selection policies
9789272ca1SMauro Carvalho Chehab- Support multi-head logs for static/dynamic hot and cold data separation
9889272ca1SMauro Carvalho Chehab- Introduce adaptive logging for efficient block allocation
9989272ca1SMauro Carvalho Chehab
10089272ca1SMauro Carvalho ChehabMount Options
10189272ca1SMauro Carvalho Chehab=============
10289272ca1SMauro Carvalho Chehab
10389272ca1SMauro Carvalho Chehab
1049aa1ccb4SJonathan Corbet======================== ============================================================
10589272ca1SMauro Carvalho Chehabbackground_gc=%s	 Turn on/off cleaning operations, namely garbage
10689272ca1SMauro Carvalho Chehab			 collection, triggered in background when I/O subsystem is
10789272ca1SMauro Carvalho Chehab			 idle. If background_gc=on, it will turn on the garbage
10889272ca1SMauro Carvalho Chehab			 collection and if background_gc=off, garbage collection
10989272ca1SMauro Carvalho Chehab			 will be turned off. If background_gc=sync, it will turn
11089272ca1SMauro Carvalho Chehab			 on synchronous garbage collection running in background.
11189272ca1SMauro Carvalho Chehab			 Default value for this option is on. So garbage
11289272ca1SMauro Carvalho Chehab			 collection is on by default.
1135911d2d1SChao Yugc_merge		 When background_gc is on, this option can be enabled to
1145911d2d1SChao Yu			 let background GC thread to handle foreground GC requests,
1155911d2d1SChao Yu			 it can eliminate the sluggish issue caused by slow foreground
1165911d2d1SChao Yu			 GC operation when GC is triggered from a process with limited
1175911d2d1SChao Yu			 I/O and CPU resources.
1185911d2d1SChao Yunogc_merge		 Disable GC merge feature.
11989272ca1SMauro Carvalho Chehabdisable_roll_forward	 Disable the roll-forward recovery routine
12089272ca1SMauro Carvalho Chehabnorecovery		 Disable the roll-forward recovery routine, mounted read-
12189272ca1SMauro Carvalho Chehab			 only (i.e., -o ro,disable_roll_forward)
12289272ca1SMauro Carvalho Chehabdiscard/nodiscard	 Enable/disable real-time discard in f2fs, if discard is
12389272ca1SMauro Carvalho Chehab			 enabled, f2fs will issue discard/TRIM commands when a
12489272ca1SMauro Carvalho Chehab			 segment is cleaned.
12589272ca1SMauro Carvalho Chehabno_heap			 Disable heap-style segment allocation which finds free
12689272ca1SMauro Carvalho Chehab			 segments for data from the beginning of main area, while
12789272ca1SMauro Carvalho Chehab			 for node from the end of main area.
12889272ca1SMauro Carvalho Chehabnouser_xattr		 Disable Extended User Attributes. Note: xattr is enabled
12989272ca1SMauro Carvalho Chehab			 by default if CONFIG_F2FS_FS_XATTR is selected.
13089272ca1SMauro Carvalho Chehabnoacl			 Disable POSIX Access Control List. Note: acl is enabled
13189272ca1SMauro Carvalho Chehab			 by default if CONFIG_F2FS_FS_POSIX_ACL is selected.
13289272ca1SMauro Carvalho Chehabactive_logs=%u		 Support configuring the number of active logs. In the
13389272ca1SMauro Carvalho Chehab			 current design, f2fs supports only 2, 4, and 6 logs.
13489272ca1SMauro Carvalho Chehab			 Default number is 6.
13589272ca1SMauro Carvalho Chehabdisable_ext_identify	 Disable the extension list configured by mkfs, so f2fs
136ca313c82SRandy Dunlap			 is not aware of cold files such as media files.
13789272ca1SMauro Carvalho Chehabinline_xattr		 Enable the inline xattrs feature.
13889272ca1SMauro Carvalho Chehabnoinline_xattr		 Disable the inline xattrs feature.
13989272ca1SMauro Carvalho Chehabinline_xattr_size=%u	 Support configuring inline xattr size, it depends on
14089272ca1SMauro Carvalho Chehab			 flexible inline xattr feature.
141ca313c82SRandy Dunlapinline_data		 Enable the inline data feature: Newly created small (<~3.4k)
14289272ca1SMauro Carvalho Chehab			 files can be written into inode block.
143ca313c82SRandy Dunlapinline_dentry		 Enable the inline dir feature: data in newly created
14489272ca1SMauro Carvalho Chehab			 directory entries can be written into inode block. The
14589272ca1SMauro Carvalho Chehab			 space of inode block which is used to store inline
14689272ca1SMauro Carvalho Chehab			 dentries is limited to ~3.4k.
14789272ca1SMauro Carvalho Chehabnoinline_dentry		 Disable the inline dentry feature.
14889272ca1SMauro Carvalho Chehabflush_merge		 Merge concurrent cache_flush commands as much as possible
14989272ca1SMauro Carvalho Chehab			 to eliminate redundant command issues. If the underlying
15089272ca1SMauro Carvalho Chehab			 device handles the cache_flush command relatively slowly,
15189272ca1SMauro Carvalho Chehab			 recommend to enable this option.
15289272ca1SMauro Carvalho Chehabnobarrier		 This option can be used if underlying storage guarantees
15389272ca1SMauro Carvalho Chehab			 its cached data should be written to the novolatile area.
15489272ca1SMauro Carvalho Chehab			 If this option is set, no cache_flush commands are issued
15589272ca1SMauro Carvalho Chehab			 but f2fs still guarantees the write ordering of all the
15689272ca1SMauro Carvalho Chehab			 data writes.
15789272ca1SMauro Carvalho Chehabfastboot		 This option is used when a system wants to reduce mount
15889272ca1SMauro Carvalho Chehab			 time as much as possible, even though normal performance
15989272ca1SMauro Carvalho Chehab			 can be sacrificed.
16089272ca1SMauro Carvalho Chehabextent_cache		 Enable an extent cache based on rb-tree, it can cache
16189272ca1SMauro Carvalho Chehab			 as many as extent which map between contiguous logical
16289272ca1SMauro Carvalho Chehab			 address and physical address per inode, resulting in
16389272ca1SMauro Carvalho Chehab			 increasing the cache hit ratio. Set by default.
16489272ca1SMauro Carvalho Chehabnoextent_cache		 Disable an extent cache based on rb-tree explicitly, see
16589272ca1SMauro Carvalho Chehab			 the above extent_cache mount option.
16689272ca1SMauro Carvalho Chehabnoinline_data		 Disable the inline data feature, inline data feature is
16789272ca1SMauro Carvalho Chehab			 enabled by default.
16889272ca1SMauro Carvalho Chehabdata_flush		 Enable data flushing before checkpoint in order to
16989272ca1SMauro Carvalho Chehab			 persist data of regular and symlink.
17089272ca1SMauro Carvalho Chehabreserve_root=%d		 Support configuring reserved space which is used for
17189272ca1SMauro Carvalho Chehab			 allocation from a privileged user with specified uid or
17289272ca1SMauro Carvalho Chehab			 gid, unit: 4KB, the default limit is 0.2% of user blocks.
17389272ca1SMauro Carvalho Chehabresuid=%d		 The user ID which may use the reserved blocks.
17489272ca1SMauro Carvalho Chehabresgid=%d		 The group ID which may use the reserved blocks.
17589272ca1SMauro Carvalho Chehabfault_injection=%d	 Enable fault injection in all supported types with
17689272ca1SMauro Carvalho Chehab			 specified injection rate.
17789272ca1SMauro Carvalho Chehabfault_type=%d		 Support configuring fault injection type, should be
17889272ca1SMauro Carvalho Chehab			 enabled with fault_injection option, fault type value
17989272ca1SMauro Carvalho Chehab			 is shown below, it supports single or combined type.
18089272ca1SMauro Carvalho Chehab
18189272ca1SMauro Carvalho Chehab			 ===================	  ===========
18289272ca1SMauro Carvalho Chehab			 Type_Name		  Type_Value
18389272ca1SMauro Carvalho Chehab			 ===================	  ===========
18489272ca1SMauro Carvalho Chehab			 FAULT_KMALLOC		  0x000000001
18589272ca1SMauro Carvalho Chehab			 FAULT_KVMALLOC		  0x000000002
18689272ca1SMauro Carvalho Chehab			 FAULT_PAGE_ALLOC	  0x000000004
18789272ca1SMauro Carvalho Chehab			 FAULT_PAGE_GET		  0x000000008
188b96d9b3bSChao Yu			 FAULT_ALLOC_BIO	  0x000000010 (obsolete)
18989272ca1SMauro Carvalho Chehab			 FAULT_ALLOC_NID	  0x000000020
19089272ca1SMauro Carvalho Chehab			 FAULT_ORPHAN		  0x000000040
19189272ca1SMauro Carvalho Chehab			 FAULT_BLOCK		  0x000000080
19289272ca1SMauro Carvalho Chehab			 FAULT_DIR_DEPTH	  0x000000100
19389272ca1SMauro Carvalho Chehab			 FAULT_EVICT_INODE	  0x000000200
19489272ca1SMauro Carvalho Chehab			 FAULT_TRUNCATE		  0x000000400
19589272ca1SMauro Carvalho Chehab			 FAULT_READ_IO		  0x000000800
19689272ca1SMauro Carvalho Chehab			 FAULT_CHECKPOINT	  0x000001000
19789272ca1SMauro Carvalho Chehab			 FAULT_DISCARD		  0x000002000
19889272ca1SMauro Carvalho Chehab			 FAULT_WRITE_IO		  0x000004000
19932410577SChao Yu			 FAULT_SLAB_ALLOC	  0x000008000
200*10a26878SChao Yu			 FAULT_DQUOT_INIT	  0x000010000
20189272ca1SMauro Carvalho Chehab			 ===================	  ===========
20289272ca1SMauro Carvalho Chehabmode=%s			 Control block allocation mode which supports "adaptive"
20389272ca1SMauro Carvalho Chehab			 and "lfs". In "lfs" mode, there should be no random
20489272ca1SMauro Carvalho Chehab			 writes towards main area.
2056691d940SDaeho Jeong			 "fragment:segment" and "fragment:block" are newly added here.
2066691d940SDaeho Jeong			 These are developer options for experiments to simulate filesystem
2076691d940SDaeho Jeong			 fragmentation/after-GC situation itself. The developers use these
2086691d940SDaeho Jeong			 modes to understand filesystem fragmentation/after-GC condition well,
2096691d940SDaeho Jeong			 and eventually get some insights to handle them better.
2106691d940SDaeho Jeong			 In "fragment:segment", f2fs allocates a new segment in ramdom
2116691d940SDaeho Jeong			 position. With this, we can simulate the after-GC condition.
2126691d940SDaeho Jeong			 In "fragment:block", we can scatter block allocation with
2136691d940SDaeho Jeong			 "max_fragment_chunk" and "max_fragment_hole" sysfs nodes.
2146691d940SDaeho Jeong			 We added some randomness to both chunk and hole size to make
2156691d940SDaeho Jeong			 it close to realistic IO pattern. So, in this mode, f2fs will allocate
2166691d940SDaeho Jeong			 1..<max_fragment_chunk> blocks in a chunk and make a hole in the
2176691d940SDaeho Jeong			 length of 1..<max_fragment_hole> by turns. With this, the newly
2186691d940SDaeho Jeong			 allocated blocks will be scattered throughout the whole partition.
2196691d940SDaeho Jeong			 Note that "fragment:block" implicitly enables "fragment:segment"
2206691d940SDaeho Jeong			 option for more randomness.
2216691d940SDaeho Jeong			 Please, use these options for your experiments and we strongly
2226691d940SDaeho Jeong			 recommend to re-format the filesystem after using these options.
22389272ca1SMauro Carvalho Chehabio_bits=%u		 Set the bit size of write IO requests. It should be set
22489272ca1SMauro Carvalho Chehab			 with "mode=lfs".
22589272ca1SMauro Carvalho Chehabusrquota		 Enable plain user disk quota accounting.
22689272ca1SMauro Carvalho Chehabgrpquota		 Enable plain group disk quota accounting.
22789272ca1SMauro Carvalho Chehabprjquota		 Enable plain project quota accounting.
22889272ca1SMauro Carvalho Chehabusrjquota=<file>	 Appoint specified file and type during mount, so that quota
22989272ca1SMauro Carvalho Chehabgrpjquota=<file>	 information can be properly updated during recovery flow,
23089272ca1SMauro Carvalho Chehabprjjquota=<file>	 <quota file>: must be in root directory;
23189272ca1SMauro Carvalho Chehabjqfmt=<quota type>	 <quota type>: [vfsold,vfsv0,vfsv1].
232ca313c82SRandy Dunlapoffusrjquota		 Turn off user journalled quota.
233ca313c82SRandy Dunlapoffgrpjquota		 Turn off group journalled quota.
234ca313c82SRandy Dunlapoffprjjquota		 Turn off project journalled quota.
23589272ca1SMauro Carvalho Chehabquota			 Enable plain user disk quota accounting.
23689272ca1SMauro Carvalho Chehabnoquota			 Disable all plain disk quota option.
23789272ca1SMauro Carvalho Chehabwhint_mode=%s		 Control which write hints are passed down to block
23889272ca1SMauro Carvalho Chehab			 layer. This supports "off", "user-based", and
23989272ca1SMauro Carvalho Chehab			 "fs-based".  In "off" mode (default), f2fs does not pass
24089272ca1SMauro Carvalho Chehab			 down hints. In "user-based" mode, f2fs tries to pass
24189272ca1SMauro Carvalho Chehab			 down hints given by users. And in "fs-based" mode, f2fs
24289272ca1SMauro Carvalho Chehab			 passes down hints with its policy.
24389272ca1SMauro Carvalho Chehaballoc_mode=%s		 Adjust block allocation policy, which supports "reuse"
24489272ca1SMauro Carvalho Chehab			 and "default".
24589272ca1SMauro Carvalho Chehabfsync_mode=%s		 Control the policy of fsync. Currently supports "posix",
24689272ca1SMauro Carvalho Chehab			 "strict", and "nobarrier". In "posix" mode, which is
24789272ca1SMauro Carvalho Chehab			 default, fsync will follow POSIX semantics and does a
24889272ca1SMauro Carvalho Chehab			 light operation to improve the filesystem performance.
24989272ca1SMauro Carvalho Chehab			 In "strict" mode, fsync will be heavy and behaves in line
25089272ca1SMauro Carvalho Chehab			 with xfs, ext4 and btrfs, where xfstest generic/342 will
25189272ca1SMauro Carvalho Chehab			 pass, but the performance will regress. "nobarrier" is
25289272ca1SMauro Carvalho Chehab			 based on "posix", but doesn't issue flush command for
25389272ca1SMauro Carvalho Chehab			 non-atomic files likewise "nobarrier" mount option.
254ed318a6cSEric Biggerstest_dummy_encryption
255ed318a6cSEric Biggerstest_dummy_encryption=%s
256ed318a6cSEric Biggers			 Enable dummy encryption, which provides a fake fscrypt
25789272ca1SMauro Carvalho Chehab			 context. The fake fscrypt context is used by xfstests.
258ed318a6cSEric Biggers			 The argument may be either "v1" or "v2", in order to
259ed318a6cSEric Biggers			 select the corresponding fscrypt policy version.
26089272ca1SMauro Carvalho Chehabcheckpoint=%s[:%u[%]]	 Set to "disable" to turn off checkpointing. Set to "enable"
26189272ca1SMauro Carvalho Chehab			 to reenable checkpointing. Is enabled by default. While
26289272ca1SMauro Carvalho Chehab			 disabled, any unmounting or unexpected shutdowns will cause
26389272ca1SMauro Carvalho Chehab			 the filesystem contents to appear as they did when the
26489272ca1SMauro Carvalho Chehab			 filesystem was mounted with that option.
26589272ca1SMauro Carvalho Chehab			 While mounting with checkpoint=disabled, the filesystem must
26689272ca1SMauro Carvalho Chehab			 run garbage collection to ensure that all available space can
26789272ca1SMauro Carvalho Chehab			 be used. If this takes too much time, the mount may return
26889272ca1SMauro Carvalho Chehab			 EAGAIN. You may optionally add a value to indicate how much
26989272ca1SMauro Carvalho Chehab			 of the disk you would be willing to temporarily give up to
27089272ca1SMauro Carvalho Chehab			 avoid additional garbage collection. This can be given as a
27189272ca1SMauro Carvalho Chehab			 number of blocks, or as a percent. For instance, mounting
27289272ca1SMauro Carvalho Chehab			 with checkpoint=disable:100% would always succeed, but it may
27389272ca1SMauro Carvalho Chehab			 hide up to all remaining free space. The actual space that
27489272ca1SMauro Carvalho Chehab			 would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
27589272ca1SMauro Carvalho Chehab			 This space is reclaimed once checkpoint=enable.
276261eeb9cSDaeho Jeongcheckpoint_merge	 When checkpoint is enabled, this can be used to create a kernel
277261eeb9cSDaeho Jeong			 daemon and make it to merge concurrent checkpoint requests as
278261eeb9cSDaeho Jeong			 much as possible to eliminate redundant checkpoint issues. Plus,
279261eeb9cSDaeho Jeong			 we can eliminate the sluggish issue caused by slow checkpoint
280261eeb9cSDaeho Jeong			 operation when the checkpoint is done in a process context in
281261eeb9cSDaeho Jeong			 a cgroup having low i/o budget and cpu shares. To make this
282261eeb9cSDaeho Jeong			 do better, we set the default i/o priority of the kernel daemon
283261eeb9cSDaeho Jeong			 to "3", to give one higher priority than other kernel threads.
284261eeb9cSDaeho Jeong			 This is the same way to give a I/O priority to the jbd2
285261eeb9cSDaeho Jeong			 journaling thread of ext4 filesystem.
286261eeb9cSDaeho Jeongnocheckpoint_merge	 Disable checkpoint merge feature.
287f40f31caSLinus Torvaldscompress_algorithm=%s	 Control compress algorithm, currently f2fs supports "lzo",
2886d92b201SChao Yu			 "lz4", "zstd" and "lzo-rle" algorithm.
2893fde13f8SChao Yucompress_algorithm=%s:%d Control compress algorithm and its compress level, now, only
2903fde13f8SChao Yu			 "lz4" and "zstd" support compress level config.
2913fde13f8SChao Yu			 algorithm	level range
2923fde13f8SChao Yu			 lz4		3 - 16
2933fde13f8SChao Yu			 zstd		1 - 22
29489272ca1SMauro Carvalho Chehabcompress_log_size=%u	 Support configuring compress cluster size, the size will
29589272ca1SMauro Carvalho Chehab			 be 4KB * (1 << %u), 16KB is minimum size, also it's
29689272ca1SMauro Carvalho Chehab			 default size.
29789272ca1SMauro Carvalho Chehabcompress_extension=%s	 Support adding specified extension, so that f2fs can enable
29889272ca1SMauro Carvalho Chehab			 compression on those corresponding files, e.g. if all files
29989272ca1SMauro Carvalho Chehab			 with '.ext' has high compression rate, we can set the '.ext'
30089272ca1SMauro Carvalho Chehab			 on compression extension list and enable compression on
30189272ca1SMauro Carvalho Chehab			 these file by default rather than to enable it via ioctl.
30289272ca1SMauro Carvalho Chehab			 For other files, we can still enable compression via ioctl.
303fa679555SChao Yu			 Note that, there is one reserved special extension '*', it
304fa679555SChao Yu			 can be set to enable compression for all files.
305151b1982SFengnan Changnocompress_extension=%s	   Support adding specified extension, so that f2fs can disable
306151b1982SFengnan Chang			 compression on those corresponding files, just contrary to compression extension.
307151b1982SFengnan Chang			 If you know exactly which files cannot be compressed, you can use this.
308151b1982SFengnan Chang			 The same extension name can't appear in both compress and nocompress
309151b1982SFengnan Chang			 extension at the same time.
310151b1982SFengnan Chang			 If the compress extension specifies all files, the types specified by the
311151b1982SFengnan Chang			 nocompress extension will be treated as special cases and will not be compressed.
312151b1982SFengnan Chang			 Don't allow use '*' to specifie all file in nocompress extension.
313151b1982SFengnan Chang			 After add nocompress_extension, the priority should be:
314151b1982SFengnan Chang			 dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
315151b1982SFengnan Chang			 See more in compression sections.
316151b1982SFengnan Chang
317b28f047bSChao Yucompress_chksum		 Support verifying chksum of raw data in compressed cluster.
318602a16d5SDaeho Jeongcompress_mode=%s	 Control file compression mode. This supports "fs" and "user"
319602a16d5SDaeho Jeong			 modes. In "fs" mode (default), f2fs does automatic compression
320602a16d5SDaeho Jeong			 on the compression enabled files. In "user" mode, f2fs disables
321602a16d5SDaeho Jeong			 the automaic compression and gives the user discretion of
322602a16d5SDaeho Jeong			 choosing the target file and the timing. The user can do manual
323602a16d5SDaeho Jeong			 compression/decompression on the compression enabled files using
324602a16d5SDaeho Jeong			 ioctls.
3256ce19affSChao Yucompress_cache		 Support to use address space of a filesystem managed inode to
3266ce19affSChao Yu			 cache compressed block, in order to improve cache hit ratio of
3276ce19affSChao Yu			 random read.
3282324d50dSLinus Torvaldsinlinecrypt		 When possible, encrypt/decrypt the contents of encrypted
32927aacd28SSatya Tangirala			 files using the blk-crypto framework rather than
33027aacd28SSatya Tangirala			 filesystem-layer encryption. This allows the use of
33127aacd28SSatya Tangirala			 inline encryption hardware. The on-disk format is
33227aacd28SSatya Tangirala			 unaffected. For more details, see
33327aacd28SSatya Tangirala			 Documentation/block/inline-encryption.rst.
334093749e2SChao Yuatgc			 Enable age-threshold garbage collection, it provides high
335093749e2SChao Yu			 effectiveness and efficiency on background GC.
3364f993264SChao Yudiscard_unit=%s		 Control discard unit, the argument can be "block", "segment"
3374f993264SChao Yu			 and "section", issued discard command's offset/size will be
3384f993264SChao Yu			 aligned to the unit, by default, "discard_unit=block" is set,
3394f993264SChao Yu			 so that small discard functionality is enabled.
3404f993264SChao Yu			 For blkzoned device, "discard_unit=section" will be set by
3414f993264SChao Yu			 default, it is helpful for large sized SMR or ZNS devices to
3424f993264SChao Yu			 reduce memory cost by getting rid of fs metadata supports small
3434f993264SChao Yu			 discard.
3449aa1ccb4SJonathan Corbet======================== ============================================================
34589272ca1SMauro Carvalho Chehab
34689272ca1SMauro Carvalho ChehabDebugfs Entries
34789272ca1SMauro Carvalho Chehab===============
34889272ca1SMauro Carvalho Chehab
34989272ca1SMauro Carvalho Chehab/sys/kernel/debug/f2fs/ contains information about all the partitions mounted as
35089272ca1SMauro Carvalho Chehabf2fs. Each file shows the whole f2fs information.
35189272ca1SMauro Carvalho Chehab
35289272ca1SMauro Carvalho Chehab/sys/kernel/debug/f2fs/status includes:
35389272ca1SMauro Carvalho Chehab
35489272ca1SMauro Carvalho Chehab - major file system information managed by f2fs currently
35589272ca1SMauro Carvalho Chehab - average SIT information about whole segments
35689272ca1SMauro Carvalho Chehab - current memory footprint consumed by f2fs.
35789272ca1SMauro Carvalho Chehab
35889272ca1SMauro Carvalho ChehabSysfs Entries
35989272ca1SMauro Carvalho Chehab=============
36089272ca1SMauro Carvalho Chehab
36189272ca1SMauro Carvalho ChehabInformation about mounted f2fs file systems can be found in
36289272ca1SMauro Carvalho Chehab/sys/fs/f2fs.  Each mounted filesystem will have a directory in
36389272ca1SMauro Carvalho Chehab/sys/fs/f2fs based on its device name (i.e., /sys/fs/f2fs/sda).
36489272ca1SMauro Carvalho ChehabThe files in each per-device directory are shown in table below.
36589272ca1SMauro Carvalho Chehab
36689272ca1SMauro Carvalho ChehabFiles in /sys/fs/f2fs/<devname>
36789272ca1SMauro Carvalho Chehab(see also Documentation/ABI/testing/sysfs-fs-f2fs)
36889272ca1SMauro Carvalho Chehab
36989272ca1SMauro Carvalho ChehabUsage
37089272ca1SMauro Carvalho Chehab=====
37189272ca1SMauro Carvalho Chehab
37289272ca1SMauro Carvalho Chehab1. Download userland tools and compile them.
37389272ca1SMauro Carvalho Chehab
37489272ca1SMauro Carvalho Chehab2. Skip, if f2fs was compiled statically inside kernel.
37589272ca1SMauro Carvalho Chehab   Otherwise, insert the f2fs.ko module::
37689272ca1SMauro Carvalho Chehab
37789272ca1SMauro Carvalho Chehab	# insmod f2fs.ko
37889272ca1SMauro Carvalho Chehab
379ca313c82SRandy Dunlap3. Create a directory to use when mounting::
38089272ca1SMauro Carvalho Chehab
38189272ca1SMauro Carvalho Chehab	# mkdir /mnt/f2fs
38289272ca1SMauro Carvalho Chehab
38389272ca1SMauro Carvalho Chehab4. Format the block device, and then mount as f2fs::
38489272ca1SMauro Carvalho Chehab
38589272ca1SMauro Carvalho Chehab	# mkfs.f2fs -l label /dev/block_device
38689272ca1SMauro Carvalho Chehab	# mount -t f2fs /dev/block_device /mnt/f2fs
38789272ca1SMauro Carvalho Chehab
38889272ca1SMauro Carvalho Chehabmkfs.f2fs
38989272ca1SMauro Carvalho Chehab---------
39089272ca1SMauro Carvalho ChehabThe mkfs.f2fs is for the use of formatting a partition as the f2fs filesystem,
39189272ca1SMauro Carvalho Chehabwhich builds a basic on-disk layout.
39289272ca1SMauro Carvalho Chehab
393568d2a1eSJaegeuk KimThe quick options consist of:
39489272ca1SMauro Carvalho Chehab
39589272ca1SMauro Carvalho Chehab===============    ===========================================================
39689272ca1SMauro Carvalho Chehab``-l [label]``     Give a volume label, up to 512 unicode name.
39789272ca1SMauro Carvalho Chehab``-a [0 or 1]``    Split start location of each area for heap-based allocation.
39889272ca1SMauro Carvalho Chehab
39989272ca1SMauro Carvalho Chehab                   1 is set by default, which performs this.
40089272ca1SMauro Carvalho Chehab``-o [int]``       Set overprovision ratio in percent over volume size.
40189272ca1SMauro Carvalho Chehab
40289272ca1SMauro Carvalho Chehab                   5 is set by default.
40389272ca1SMauro Carvalho Chehab``-s [int]``       Set the number of segments per section.
40489272ca1SMauro Carvalho Chehab
40589272ca1SMauro Carvalho Chehab                   1 is set by default.
40689272ca1SMauro Carvalho Chehab``-z [int]``       Set the number of sections per zone.
40789272ca1SMauro Carvalho Chehab
40889272ca1SMauro Carvalho Chehab                   1 is set by default.
40989272ca1SMauro Carvalho Chehab``-e [str]``       Set basic extension list. e.g. "mp3,gif,mov"
41089272ca1SMauro Carvalho Chehab``-t [0 or 1]``    Disable discard command or not.
41189272ca1SMauro Carvalho Chehab
41289272ca1SMauro Carvalho Chehab                   1 is set by default, which conducts discard.
41389272ca1SMauro Carvalho Chehab===============    ===========================================================
41489272ca1SMauro Carvalho Chehab
415ca313c82SRandy DunlapNote: please refer to the manpage of mkfs.f2fs(8) to get full option list.
416568d2a1eSJaegeuk Kim
41789272ca1SMauro Carvalho Chehabfsck.f2fs
41889272ca1SMauro Carvalho Chehab---------
41989272ca1SMauro Carvalho ChehabThe fsck.f2fs is a tool to check the consistency of an f2fs-formatted
42089272ca1SMauro Carvalho Chehabpartition, which examines whether the filesystem metadata and user-made data
42189272ca1SMauro Carvalho Chehabare cross-referenced correctly or not.
42289272ca1SMauro Carvalho ChehabNote that, initial version of the tool does not fix any inconsistency.
42389272ca1SMauro Carvalho Chehab
424568d2a1eSJaegeuk KimThe quick options consist of::
42589272ca1SMauro Carvalho Chehab
42689272ca1SMauro Carvalho Chehab  -d debug level [default:0]
42789272ca1SMauro Carvalho Chehab
428ca313c82SRandy DunlapNote: please refer to the manpage of fsck.f2fs(8) to get full option list.
429568d2a1eSJaegeuk Kim
43089272ca1SMauro Carvalho Chehabdump.f2fs
43189272ca1SMauro Carvalho Chehab---------
43289272ca1SMauro Carvalho ChehabThe dump.f2fs shows the information of specific inode and dumps SSA and SIT to
43389272ca1SMauro Carvalho Chehabfile. Each file is dump_ssa and dump_sit.
43489272ca1SMauro Carvalho Chehab
43589272ca1SMauro Carvalho ChehabThe dump.f2fs is used to debug on-disk data structures of the f2fs filesystem.
43689272ca1SMauro Carvalho ChehabIt shows on-disk inode information recognized by a given inode number, and is
43789272ca1SMauro Carvalho Chehabable to dump all the SSA and SIT entries into predefined files, ./dump_ssa and
43889272ca1SMauro Carvalho Chehab./dump_sit respectively.
43989272ca1SMauro Carvalho Chehab
44089272ca1SMauro Carvalho ChehabThe options consist of::
44189272ca1SMauro Carvalho Chehab
44289272ca1SMauro Carvalho Chehab  -d debug level [default:0]
44389272ca1SMauro Carvalho Chehab  -i inode no (hex)
44489272ca1SMauro Carvalho Chehab  -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
44589272ca1SMauro Carvalho Chehab  -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
44689272ca1SMauro Carvalho Chehab
44789272ca1SMauro Carvalho ChehabExamples::
44889272ca1SMauro Carvalho Chehab
44989272ca1SMauro Carvalho Chehab    # dump.f2fs -i [ino] /dev/sdx
45089272ca1SMauro Carvalho Chehab    # dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
45189272ca1SMauro Carvalho Chehab    # dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
45289272ca1SMauro Carvalho Chehab
453ca313c82SRandy DunlapNote: please refer to the manpage of dump.f2fs(8) to get full option list.
454568d2a1eSJaegeuk Kim
455568d2a1eSJaegeuk Kimsload.f2fs
456568d2a1eSJaegeuk Kim----------
457568d2a1eSJaegeuk KimThe sload.f2fs gives a way to insert files and directories in the exisiting disk
458568d2a1eSJaegeuk Kimimage. This tool is useful when building f2fs images given compiled files.
459568d2a1eSJaegeuk Kim
460ca313c82SRandy DunlapNote: please refer to the manpage of sload.f2fs(8) to get full option list.
461568d2a1eSJaegeuk Kim
462568d2a1eSJaegeuk Kimresize.f2fs
463568d2a1eSJaegeuk Kim-----------
464ca313c82SRandy DunlapThe resize.f2fs lets a user resize the f2fs-formatted disk image, while preserving
465568d2a1eSJaegeuk Kimall the files and directories stored in the image.
466568d2a1eSJaegeuk Kim
467ca313c82SRandy DunlapNote: please refer to the manpage of resize.f2fs(8) to get full option list.
468568d2a1eSJaegeuk Kim
469568d2a1eSJaegeuk Kimdefrag.f2fs
470568d2a1eSJaegeuk Kim-----------
471ca313c82SRandy DunlapThe defrag.f2fs can be used to defragment scattered written data as well as
472568d2a1eSJaegeuk Kimfilesystem metadata across the disk. This can improve the write speed by giving
473568d2a1eSJaegeuk Kimmore free consecutive space.
474568d2a1eSJaegeuk Kim
475ca313c82SRandy DunlapNote: please refer to the manpage of defrag.f2fs(8) to get full option list.
476568d2a1eSJaegeuk Kim
477568d2a1eSJaegeuk Kimf2fs_io
478568d2a1eSJaegeuk Kim-------
479568d2a1eSJaegeuk KimThe f2fs_io is a simple tool to issue various filesystem APIs as well as
480568d2a1eSJaegeuk Kimf2fs-specific ones, which is very useful for QA tests.
481568d2a1eSJaegeuk Kim
482ca313c82SRandy DunlapNote: please refer to the manpage of f2fs_io(8) to get full option list.
483568d2a1eSJaegeuk Kim
48489272ca1SMauro Carvalho ChehabDesign
48589272ca1SMauro Carvalho Chehab======
48689272ca1SMauro Carvalho Chehab
48789272ca1SMauro Carvalho ChehabOn-disk Layout
48889272ca1SMauro Carvalho Chehab--------------
48989272ca1SMauro Carvalho Chehab
49089272ca1SMauro Carvalho ChehabF2FS divides the whole volume into a number of segments, each of which is fixed
49189272ca1SMauro Carvalho Chehabto 2MB in size. A section is composed of consecutive segments, and a zone
49289272ca1SMauro Carvalho Chehabconsists of a set of sections. By default, section and zone sizes are set to one
49389272ca1SMauro Carvalho Chehabsegment size identically, but users can easily modify the sizes by mkfs.
49489272ca1SMauro Carvalho Chehab
49589272ca1SMauro Carvalho ChehabF2FS splits the entire volume into six areas, and all the areas except superblock
496ca313c82SRandy Dunlapconsist of multiple segments as described below::
49789272ca1SMauro Carvalho Chehab
49889272ca1SMauro Carvalho Chehab                                            align with the zone size <-|
49989272ca1SMauro Carvalho Chehab                 |-> align with the segment size
50089272ca1SMauro Carvalho Chehab     _________________________________________________________________________
50189272ca1SMauro Carvalho Chehab    |            |            |   Segment   |    Node     |   Segment  |      |
50289272ca1SMauro Carvalho Chehab    | Superblock | Checkpoint |    Info.    |   Address   |   Summary  | Main |
50389272ca1SMauro Carvalho Chehab    |    (SB)    |   (CP)     | Table (SIT) | Table (NAT) | Area (SSA) |      |
50489272ca1SMauro Carvalho Chehab    |____________|_____2______|______N______|______N______|______N_____|__N___|
50589272ca1SMauro Carvalho Chehab                                                                       .      .
50689272ca1SMauro Carvalho Chehab                                                             .                .
50789272ca1SMauro Carvalho Chehab                                                 .                            .
50889272ca1SMauro Carvalho Chehab                                    ._________________________________________.
50989272ca1SMauro Carvalho Chehab                                    |_Segment_|_..._|_Segment_|_..._|_Segment_|
51089272ca1SMauro Carvalho Chehab                                    .           .
51189272ca1SMauro Carvalho Chehab                                    ._________._________
51289272ca1SMauro Carvalho Chehab                                    |_section_|__...__|_
51389272ca1SMauro Carvalho Chehab                                    .            .
51489272ca1SMauro Carvalho Chehab		                    .________.
51589272ca1SMauro Carvalho Chehab	                            |__zone__|
51689272ca1SMauro Carvalho Chehab
51789272ca1SMauro Carvalho Chehab- Superblock (SB)
51889272ca1SMauro Carvalho Chehab   It is located at the beginning of the partition, and there exist two copies
51989272ca1SMauro Carvalho Chehab   to avoid file system crash. It contains basic partition information and some
52089272ca1SMauro Carvalho Chehab   default parameters of f2fs.
52189272ca1SMauro Carvalho Chehab
52289272ca1SMauro Carvalho Chehab- Checkpoint (CP)
52389272ca1SMauro Carvalho Chehab   It contains file system information, bitmaps for valid NAT/SIT sets, orphan
52489272ca1SMauro Carvalho Chehab   inode lists, and summary entries of current active segments.
52589272ca1SMauro Carvalho Chehab
52689272ca1SMauro Carvalho Chehab- Segment Information Table (SIT)
52789272ca1SMauro Carvalho Chehab   It contains segment information such as valid block count and bitmap for the
52889272ca1SMauro Carvalho Chehab   validity of all the blocks.
52989272ca1SMauro Carvalho Chehab
53089272ca1SMauro Carvalho Chehab- Node Address Table (NAT)
53189272ca1SMauro Carvalho Chehab   It is composed of a block address table for all the node blocks stored in
53289272ca1SMauro Carvalho Chehab   Main area.
53389272ca1SMauro Carvalho Chehab
53489272ca1SMauro Carvalho Chehab- Segment Summary Area (SSA)
53589272ca1SMauro Carvalho Chehab   It contains summary entries which contains the owner information of all the
53689272ca1SMauro Carvalho Chehab   data and node blocks stored in Main area.
53789272ca1SMauro Carvalho Chehab
53889272ca1SMauro Carvalho Chehab- Main Area
53989272ca1SMauro Carvalho Chehab   It contains file and directory data including their indices.
54089272ca1SMauro Carvalho Chehab
54189272ca1SMauro Carvalho ChehabIn order to avoid misalignment between file system and flash-based storage, F2FS
54289272ca1SMauro Carvalho Chehabaligns the start block address of CP with the segment size. Also, it aligns the
54389272ca1SMauro Carvalho Chehabstart block address of Main area with the zone size by reserving some segments
54489272ca1SMauro Carvalho Chehabin SSA area.
54589272ca1SMauro Carvalho Chehab
54689272ca1SMauro Carvalho ChehabReference the following survey for additional technical details.
54789272ca1SMauro Carvalho Chehabhttps://wiki.linaro.org/WorkingGroups/Kernel/Projects/FlashCardSurvey
54889272ca1SMauro Carvalho Chehab
54989272ca1SMauro Carvalho ChehabFile System Metadata Structure
55089272ca1SMauro Carvalho Chehab------------------------------
55189272ca1SMauro Carvalho Chehab
55289272ca1SMauro Carvalho ChehabF2FS adopts the checkpointing scheme to maintain file system consistency. At
55389272ca1SMauro Carvalho Chehabmount time, F2FS first tries to find the last valid checkpoint data by scanning
55489272ca1SMauro Carvalho ChehabCP area. In order to reduce the scanning time, F2FS uses only two copies of CP.
55589272ca1SMauro Carvalho ChehabOne of them always indicates the last valid data, which is called as shadow copy
55689272ca1SMauro Carvalho Chehabmechanism. In addition to CP, NAT and SIT also adopt the shadow copy mechanism.
55789272ca1SMauro Carvalho Chehab
55889272ca1SMauro Carvalho ChehabFor file system consistency, each CP points to which NAT and SIT copies are
55989272ca1SMauro Carvalho Chehabvalid, as shown as below::
56089272ca1SMauro Carvalho Chehab
56189272ca1SMauro Carvalho Chehab  +--------+----------+---------+
56289272ca1SMauro Carvalho Chehab  |   CP   |    SIT   |   NAT   |
56389272ca1SMauro Carvalho Chehab  +--------+----------+---------+
56489272ca1SMauro Carvalho Chehab  .         .          .          .
56589272ca1SMauro Carvalho Chehab  .            .              .              .
56689272ca1SMauro Carvalho Chehab  .               .                 .                 .
56789272ca1SMauro Carvalho Chehab  +-------+-------+--------+--------+--------+--------+
56889272ca1SMauro Carvalho Chehab  | CP #0 | CP #1 | SIT #0 | SIT #1 | NAT #0 | NAT #1 |
56989272ca1SMauro Carvalho Chehab  +-------+-------+--------+--------+--------+--------+
57089272ca1SMauro Carvalho Chehab     |             ^                          ^
57189272ca1SMauro Carvalho Chehab     |             |                          |
57289272ca1SMauro Carvalho Chehab     `----------------------------------------'
57389272ca1SMauro Carvalho Chehab
57489272ca1SMauro Carvalho ChehabIndex Structure
57589272ca1SMauro Carvalho Chehab---------------
57689272ca1SMauro Carvalho Chehab
57789272ca1SMauro Carvalho ChehabThe key data structure to manage the data locations is a "node". Similar to
57889272ca1SMauro Carvalho Chehabtraditional file structures, F2FS has three types of node: inode, direct node,
57989272ca1SMauro Carvalho Chehabindirect node. F2FS assigns 4KB to an inode block which contains 923 data block
58089272ca1SMauro Carvalho Chehabindices, two direct node pointers, two indirect node pointers, and one double
58189272ca1SMauro Carvalho Chehabindirect node pointer as described below. One direct node block contains 1018
58289272ca1SMauro Carvalho Chehabdata blocks, and one indirect node block contains also 1018 node blocks. Thus,
58389272ca1SMauro Carvalho Chehabone inode block (i.e., a file) covers::
58489272ca1SMauro Carvalho Chehab
58589272ca1SMauro Carvalho Chehab  4KB * (923 + 2 * 1018 + 2 * 1018 * 1018 + 1018 * 1018 * 1018) := 3.94TB.
58689272ca1SMauro Carvalho Chehab
58789272ca1SMauro Carvalho Chehab   Inode block (4KB)
58889272ca1SMauro Carvalho Chehab     |- data (923)
58989272ca1SMauro Carvalho Chehab     |- direct node (2)
59089272ca1SMauro Carvalho Chehab     |          `- data (1018)
59189272ca1SMauro Carvalho Chehab     |- indirect node (2)
59289272ca1SMauro Carvalho Chehab     |            `- direct node (1018)
59389272ca1SMauro Carvalho Chehab     |                       `- data (1018)
59489272ca1SMauro Carvalho Chehab     `- double indirect node (1)
59589272ca1SMauro Carvalho Chehab                         `- indirect node (1018)
59689272ca1SMauro Carvalho Chehab			              `- direct node (1018)
59789272ca1SMauro Carvalho Chehab	                                         `- data (1018)
59889272ca1SMauro Carvalho Chehab
599ca313c82SRandy DunlapNote that all the node blocks are mapped by NAT which means the location of
60089272ca1SMauro Carvalho Chehabeach node is translated by the NAT table. In the consideration of the wandering
60189272ca1SMauro Carvalho Chehabtree problem, F2FS is able to cut off the propagation of node updates caused by
60289272ca1SMauro Carvalho Chehableaf data writes.
60389272ca1SMauro Carvalho Chehab
60489272ca1SMauro Carvalho ChehabDirectory Structure
60589272ca1SMauro Carvalho Chehab-------------------
60689272ca1SMauro Carvalho Chehab
60789272ca1SMauro Carvalho ChehabA directory entry occupies 11 bytes, which consists of the following attributes.
60889272ca1SMauro Carvalho Chehab
60989272ca1SMauro Carvalho Chehab- hash		hash value of the file name
61089272ca1SMauro Carvalho Chehab- ino		inode number
61189272ca1SMauro Carvalho Chehab- len		the length of file name
61289272ca1SMauro Carvalho Chehab- type		file type such as directory, symlink, etc
61389272ca1SMauro Carvalho Chehab
61489272ca1SMauro Carvalho ChehabA dentry block consists of 214 dentry slots and file names. Therein a bitmap is
61589272ca1SMauro Carvalho Chehabused to represent whether each dentry is valid or not. A dentry block occupies
61689272ca1SMauro Carvalho Chehab4KB with the following composition.
61789272ca1SMauro Carvalho Chehab
61889272ca1SMauro Carvalho Chehab::
61989272ca1SMauro Carvalho Chehab
62089272ca1SMauro Carvalho Chehab  Dentry Block(4 K) = bitmap (27 bytes) + reserved (3 bytes) +
62189272ca1SMauro Carvalho Chehab	              dentries(11 * 214 bytes) + file name (8 * 214 bytes)
62289272ca1SMauro Carvalho Chehab
62389272ca1SMauro Carvalho Chehab                         [Bucket]
62489272ca1SMauro Carvalho Chehab             +--------------------------------+
62589272ca1SMauro Carvalho Chehab             |dentry block 1 | dentry block 2 |
62689272ca1SMauro Carvalho Chehab             +--------------------------------+
62789272ca1SMauro Carvalho Chehab             .               .
62889272ca1SMauro Carvalho Chehab       .                             .
62989272ca1SMauro Carvalho Chehab  .       [Dentry Block Structure: 4KB]       .
63089272ca1SMauro Carvalho Chehab  +--------+----------+----------+------------+
63189272ca1SMauro Carvalho Chehab  | bitmap | reserved | dentries | file names |
63289272ca1SMauro Carvalho Chehab  +--------+----------+----------+------------+
63389272ca1SMauro Carvalho Chehab  [Dentry Block: 4KB] .   .
63489272ca1SMauro Carvalho Chehab		 .               .
63589272ca1SMauro Carvalho Chehab            .                          .
63689272ca1SMauro Carvalho Chehab            +------+------+-----+------+
63789272ca1SMauro Carvalho Chehab            | hash | ino  | len | type |
63889272ca1SMauro Carvalho Chehab            +------+------+-----+------+
63989272ca1SMauro Carvalho Chehab            [Dentry Structure: 11 bytes]
64089272ca1SMauro Carvalho Chehab
64189272ca1SMauro Carvalho ChehabF2FS implements multi-level hash tables for directory structure. Each level has
64289272ca1SMauro Carvalho Chehaba hash table with dedicated number of hash buckets as shown below. Note that
64389272ca1SMauro Carvalho Chehab"A(2B)" means a bucket includes 2 data blocks.
64489272ca1SMauro Carvalho Chehab
64589272ca1SMauro Carvalho Chehab::
64689272ca1SMauro Carvalho Chehab
64789272ca1SMauro Carvalho Chehab    ----------------------
64889272ca1SMauro Carvalho Chehab    A : bucket
64989272ca1SMauro Carvalho Chehab    B : block
65089272ca1SMauro Carvalho Chehab    N : MAX_DIR_HASH_DEPTH
65189272ca1SMauro Carvalho Chehab    ----------------------
65289272ca1SMauro Carvalho Chehab
65389272ca1SMauro Carvalho Chehab    level #0   | A(2B)
65489272ca1SMauro Carvalho Chehab	    |
65589272ca1SMauro Carvalho Chehab    level #1   | A(2B) - A(2B)
65689272ca1SMauro Carvalho Chehab	    |
65789272ca1SMauro Carvalho Chehab    level #2   | A(2B) - A(2B) - A(2B) - A(2B)
65889272ca1SMauro Carvalho Chehab	.     |   .       .       .       .
65989272ca1SMauro Carvalho Chehab    level #N/2 | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
66089272ca1SMauro Carvalho Chehab	.     |   .       .       .       .
66189272ca1SMauro Carvalho Chehab    level #N   | A(4B) - A(4B) - A(4B) - A(4B) - A(4B) - ... - A(4B)
66289272ca1SMauro Carvalho Chehab
66389272ca1SMauro Carvalho ChehabThe number of blocks and buckets are determined by::
66489272ca1SMauro Carvalho Chehab
66589272ca1SMauro Carvalho Chehab                            ,- 2, if n < MAX_DIR_HASH_DEPTH / 2,
66689272ca1SMauro Carvalho Chehab  # of blocks in level #n = |
66789272ca1SMauro Carvalho Chehab                            `- 4, Otherwise
66889272ca1SMauro Carvalho Chehab
66989272ca1SMauro Carvalho Chehab                             ,- 2^(n + dir_level),
67089272ca1SMauro Carvalho Chehab			     |        if n + dir_level < MAX_DIR_HASH_DEPTH / 2,
67189272ca1SMauro Carvalho Chehab  # of buckets in level #n = |
67289272ca1SMauro Carvalho Chehab                             `- 2^((MAX_DIR_HASH_DEPTH / 2) - 1),
67389272ca1SMauro Carvalho Chehab			              Otherwise
67489272ca1SMauro Carvalho Chehab
67589272ca1SMauro Carvalho ChehabWhen F2FS finds a file name in a directory, at first a hash value of the file
67689272ca1SMauro Carvalho Chehabname is calculated. Then, F2FS scans the hash table in level #0 to find the
67789272ca1SMauro Carvalho Chehabdentry consisting of the file name and its inode number. If not found, F2FS
67889272ca1SMauro Carvalho Chehabscans the next hash table in level #1. In this way, F2FS scans hash tables in
679ca313c82SRandy Dunlapeach levels incrementally from 1 to N. In each level F2FS needs to scan only
68089272ca1SMauro Carvalho Chehabone bucket determined by the following equation, which shows O(log(# of files))
68189272ca1SMauro Carvalho Chehabcomplexity::
68289272ca1SMauro Carvalho Chehab
68389272ca1SMauro Carvalho Chehab  bucket number to scan in level #n = (hash value) % (# of buckets in level #n)
68489272ca1SMauro Carvalho Chehab
68589272ca1SMauro Carvalho ChehabIn the case of file creation, F2FS finds empty consecutive slots that cover the
68689272ca1SMauro Carvalho Chehabfile name. F2FS searches the empty slots in the hash tables of whole levels from
68789272ca1SMauro Carvalho Chehab1 to N in the same way as the lookup operation.
68889272ca1SMauro Carvalho Chehab
68989272ca1SMauro Carvalho ChehabThe following figure shows an example of two cases holding children::
69089272ca1SMauro Carvalho Chehab
69189272ca1SMauro Carvalho Chehab       --------------> Dir <--------------
69289272ca1SMauro Carvalho Chehab       |                                 |
69389272ca1SMauro Carvalho Chehab    child                             child
69489272ca1SMauro Carvalho Chehab
69589272ca1SMauro Carvalho Chehab    child - child                     [hole] - child
69689272ca1SMauro Carvalho Chehab
69789272ca1SMauro Carvalho Chehab    child - child - child             [hole] - [hole] - child
69889272ca1SMauro Carvalho Chehab
69989272ca1SMauro Carvalho Chehab   Case 1:                           Case 2:
70089272ca1SMauro Carvalho Chehab   Number of children = 6,           Number of children = 3,
70189272ca1SMauro Carvalho Chehab   File size = 7                     File size = 7
70289272ca1SMauro Carvalho Chehab
70389272ca1SMauro Carvalho ChehabDefault Block Allocation
70489272ca1SMauro Carvalho Chehab------------------------
70589272ca1SMauro Carvalho Chehab
70689272ca1SMauro Carvalho ChehabAt runtime, F2FS manages six active logs inside "Main" area: Hot/Warm/Cold node
70789272ca1SMauro Carvalho Chehaband Hot/Warm/Cold data.
70889272ca1SMauro Carvalho Chehab
70989272ca1SMauro Carvalho Chehab- Hot node	contains direct node blocks of directories.
71089272ca1SMauro Carvalho Chehab- Warm node	contains direct node blocks except hot node blocks.
71189272ca1SMauro Carvalho Chehab- Cold node	contains indirect node blocks
71289272ca1SMauro Carvalho Chehab- Hot data	contains dentry blocks
71389272ca1SMauro Carvalho Chehab- Warm data	contains data blocks except hot and cold data blocks
71489272ca1SMauro Carvalho Chehab- Cold data	contains multimedia data or migrated data blocks
71589272ca1SMauro Carvalho Chehab
71689272ca1SMauro Carvalho ChehabLFS has two schemes for free space management: threaded log and copy-and-compac-
71789272ca1SMauro Carvalho Chehabtion. The copy-and-compaction scheme which is known as cleaning, is well-suited
71889272ca1SMauro Carvalho Chehabfor devices showing very good sequential write performance, since free segments
71989272ca1SMauro Carvalho Chehabare served all the time for writing new data. However, it suffers from cleaning
72089272ca1SMauro Carvalho Chehaboverhead under high utilization. Contrarily, the threaded log scheme suffers
72189272ca1SMauro Carvalho Chehabfrom random writes, but no cleaning process is needed. F2FS adopts a hybrid
72289272ca1SMauro Carvalho Chehabscheme where the copy-and-compaction scheme is adopted by default, but the
72389272ca1SMauro Carvalho Chehabpolicy is dynamically changed to the threaded log scheme according to the file
72489272ca1SMauro Carvalho Chehabsystem status.
72589272ca1SMauro Carvalho Chehab
72689272ca1SMauro Carvalho ChehabIn order to align F2FS with underlying flash-based storage, F2FS allocates a
72789272ca1SMauro Carvalho Chehabsegment in a unit of section. F2FS expects that the section size would be the
72889272ca1SMauro Carvalho Chehabsame as the unit size of garbage collection in FTL. Furthermore, with respect
72989272ca1SMauro Carvalho Chehabto the mapping granularity in FTL, F2FS allocates each section of the active
73089272ca1SMauro Carvalho Chehablogs from different zones as much as possible, since FTL can write the data in
73189272ca1SMauro Carvalho Chehabthe active logs into one allocation unit according to its mapping granularity.
73289272ca1SMauro Carvalho Chehab
73389272ca1SMauro Carvalho ChehabCleaning process
73489272ca1SMauro Carvalho Chehab----------------
73589272ca1SMauro Carvalho Chehab
73689272ca1SMauro Carvalho ChehabF2FS does cleaning both on demand and in the background. On-demand cleaning is
73789272ca1SMauro Carvalho Chehabtriggered when there are not enough free segments to serve VFS calls. Background
73889272ca1SMauro Carvalho Chehabcleaner is operated by a kernel thread, and triggers the cleaning job when the
73989272ca1SMauro Carvalho Chehabsystem is idle.
74089272ca1SMauro Carvalho Chehab
74189272ca1SMauro Carvalho ChehabF2FS supports two victim selection policies: greedy and cost-benefit algorithms.
74289272ca1SMauro Carvalho ChehabIn the greedy algorithm, F2FS selects a victim segment having the smallest number
74389272ca1SMauro Carvalho Chehabof valid blocks. In the cost-benefit algorithm, F2FS selects a victim segment
74489272ca1SMauro Carvalho Chehabaccording to the segment age and the number of valid blocks in order to address
74589272ca1SMauro Carvalho Chehablog block thrashing problem in the greedy algorithm. F2FS adopts the greedy
74689272ca1SMauro Carvalho Chehabalgorithm for on-demand cleaner, while background cleaner adopts cost-benefit
74789272ca1SMauro Carvalho Chehabalgorithm.
74889272ca1SMauro Carvalho Chehab
74989272ca1SMauro Carvalho ChehabIn order to identify whether the data in the victim segment are valid or not,
75089272ca1SMauro Carvalho ChehabF2FS manages a bitmap. Each bit represents the validity of a block, and the
75189272ca1SMauro Carvalho Chehabbitmap is composed of a bit stream covering whole blocks in main area.
75289272ca1SMauro Carvalho Chehab
75389272ca1SMauro Carvalho ChehabWrite-hint Policy
75489272ca1SMauro Carvalho Chehab-----------------
75589272ca1SMauro Carvalho Chehab
75689272ca1SMauro Carvalho Chehab1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.
75789272ca1SMauro Carvalho Chehab
75889272ca1SMauro Carvalho Chehab2) whint_mode=user-based. F2FS tries to pass down hints given by
75989272ca1SMauro Carvalho Chehabusers.
76089272ca1SMauro Carvalho Chehab
76189272ca1SMauro Carvalho Chehab===================== ======================== ===================
76289272ca1SMauro Carvalho ChehabUser                  F2FS                     Block
76389272ca1SMauro Carvalho Chehab===================== ======================== ===================
7643c16dc40SChao YuN/A                   META                     WRITE_LIFE_NOT_SET
7653c16dc40SChao YuN/A                   HOT_NODE                 "
7663c16dc40SChao YuN/A                   WARM_NODE                "
7673c16dc40SChao YuN/A                   COLD_NODE                "
76889272ca1SMauro Carvalho Chehabioctl(COLD)           COLD_DATA                WRITE_LIFE_EXTREME
76989272ca1SMauro Carvalho Chehabextension list        "                        "
77089272ca1SMauro Carvalho Chehab
77189272ca1SMauro Carvalho Chehab-- buffered io
77289272ca1SMauro Carvalho ChehabWRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
77389272ca1SMauro Carvalho ChehabWRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
77489272ca1SMauro Carvalho ChehabWRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
77589272ca1SMauro Carvalho ChehabWRITE_LIFE_NONE       "                        "
77689272ca1SMauro Carvalho ChehabWRITE_LIFE_MEDIUM     "                        "
77789272ca1SMauro Carvalho ChehabWRITE_LIFE_LONG       "                        "
77889272ca1SMauro Carvalho Chehab
77989272ca1SMauro Carvalho Chehab-- direct io
78089272ca1SMauro Carvalho ChehabWRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
78189272ca1SMauro Carvalho ChehabWRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
78289272ca1SMauro Carvalho ChehabWRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
78389272ca1SMauro Carvalho ChehabWRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
78489272ca1SMauro Carvalho ChehabWRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
78589272ca1SMauro Carvalho ChehabWRITE_LIFE_LONG       "                        WRITE_LIFE_LONG
78689272ca1SMauro Carvalho Chehab===================== ======================== ===================
78789272ca1SMauro Carvalho Chehab
78889272ca1SMauro Carvalho Chehab3) whint_mode=fs-based. F2FS passes down hints with its policy.
78989272ca1SMauro Carvalho Chehab
79089272ca1SMauro Carvalho Chehab===================== ======================== ===================
79189272ca1SMauro Carvalho ChehabUser                  F2FS                     Block
79289272ca1SMauro Carvalho Chehab===================== ======================== ===================
7933c16dc40SChao YuN/A                   META                     WRITE_LIFE_MEDIUM;
7943c16dc40SChao YuN/A                   HOT_NODE                 WRITE_LIFE_NOT_SET
7953c16dc40SChao YuN/A                   WARM_NODE                "
7963c16dc40SChao YuN/A                   COLD_NODE                WRITE_LIFE_NONE
79789272ca1SMauro Carvalho Chehabioctl(COLD)           COLD_DATA                WRITE_LIFE_EXTREME
79889272ca1SMauro Carvalho Chehabextension list        "                        "
79989272ca1SMauro Carvalho Chehab
80089272ca1SMauro Carvalho Chehab-- buffered io
80189272ca1SMauro Carvalho ChehabWRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
80289272ca1SMauro Carvalho ChehabWRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
80389272ca1SMauro Carvalho ChehabWRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_LONG
80489272ca1SMauro Carvalho ChehabWRITE_LIFE_NONE       "                        "
80589272ca1SMauro Carvalho ChehabWRITE_LIFE_MEDIUM     "                        "
80689272ca1SMauro Carvalho ChehabWRITE_LIFE_LONG       "                        "
80789272ca1SMauro Carvalho Chehab
80889272ca1SMauro Carvalho Chehab-- direct io
80989272ca1SMauro Carvalho ChehabWRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
81089272ca1SMauro Carvalho ChehabWRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
81189272ca1SMauro Carvalho ChehabWRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
81289272ca1SMauro Carvalho ChehabWRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
81389272ca1SMauro Carvalho ChehabWRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
81489272ca1SMauro Carvalho ChehabWRITE_LIFE_LONG       "                        WRITE_LIFE_LONG
81589272ca1SMauro Carvalho Chehab===================== ======================== ===================
81689272ca1SMauro Carvalho Chehab
81789272ca1SMauro Carvalho ChehabFallocate(2) Policy
81889272ca1SMauro Carvalho Chehab-------------------
81989272ca1SMauro Carvalho Chehab
820ca313c82SRandy DunlapThe default policy follows the below POSIX rule.
82189272ca1SMauro Carvalho Chehab
82289272ca1SMauro Carvalho ChehabAllocating disk space
82389272ca1SMauro Carvalho Chehab    The default operation (i.e., mode is zero) of fallocate() allocates
82489272ca1SMauro Carvalho Chehab    the disk space within the range specified by offset and len.  The
82589272ca1SMauro Carvalho Chehab    file size (as reported by stat(2)) will be changed if offset+len is
82689272ca1SMauro Carvalho Chehab    greater than the file size.  Any subregion within the range specified
82789272ca1SMauro Carvalho Chehab    by offset and len that did not contain data before the call will be
82889272ca1SMauro Carvalho Chehab    initialized to zero.  This default behavior closely resembles the
82989272ca1SMauro Carvalho Chehab    behavior of the posix_fallocate(3) library function, and is intended
83089272ca1SMauro Carvalho Chehab    as a method of optimally implementing that function.
83189272ca1SMauro Carvalho Chehab
83289272ca1SMauro Carvalho ChehabHowever, once F2FS receives ioctl(fd, F2FS_IOC_SET_PIN_FILE) in prior to
833ca313c82SRandy Dunlapfallocate(fd, DEFAULT_MODE), it allocates on-disk block addressess having
83489272ca1SMauro Carvalho Chehabzero or random data, which is useful to the below scenario where:
83589272ca1SMauro Carvalho Chehab
83689272ca1SMauro Carvalho Chehab 1. create(fd)
83789272ca1SMauro Carvalho Chehab 2. ioctl(fd, F2FS_IOC_SET_PIN_FILE)
83889272ca1SMauro Carvalho Chehab 3. fallocate(fd, 0, 0, size)
83989272ca1SMauro Carvalho Chehab 4. address = fibmap(fd, offset)
84089272ca1SMauro Carvalho Chehab 5. open(blkdev)
84189272ca1SMauro Carvalho Chehab 6. write(blkdev, address)
84289272ca1SMauro Carvalho Chehab
84389272ca1SMauro Carvalho ChehabCompression implementation
84489272ca1SMauro Carvalho Chehab--------------------------
84589272ca1SMauro Carvalho Chehab
84689272ca1SMauro Carvalho Chehab- New term named cluster is defined as basic unit of compression, file can
84789272ca1SMauro Carvalho Chehab  be divided into multiple clusters logically. One cluster includes 4 << n
84889272ca1SMauro Carvalho Chehab  (n >= 0) logical pages, compression size is also cluster size, each of
84989272ca1SMauro Carvalho Chehab  cluster can be compressed or not.
85089272ca1SMauro Carvalho Chehab
85189272ca1SMauro Carvalho Chehab- In cluster metadata layout, one special block address is used to indicate
852ca313c82SRandy Dunlap  a cluster is a compressed one or normal one; for compressed cluster, following
85389272ca1SMauro Carvalho Chehab  metadata maps cluster to [1, 4 << n - 1] physical blocks, in where f2fs
85489272ca1SMauro Carvalho Chehab  stores data including compress header and compressed data.
85589272ca1SMauro Carvalho Chehab
85689272ca1SMauro Carvalho Chehab- In order to eliminate write amplification during overwrite, F2FS only
85789272ca1SMauro Carvalho Chehab  support compression on write-once file, data can be compressed only when
8584fc781a3SChao Yu  all logical blocks in cluster contain valid data and compress ratio of
8594fc781a3SChao Yu  cluster data is lower than specified threshold.
86089272ca1SMauro Carvalho Chehab
861151b1982SFengnan Chang- To enable compression on regular inode, there are four ways:
86289272ca1SMauro Carvalho Chehab
86389272ca1SMauro Carvalho Chehab  * chattr +c file
86489272ca1SMauro Carvalho Chehab  * chattr +c dir; touch dir/file
86589272ca1SMauro Carvalho Chehab  * mount w/ -o compress_extension=ext; touch file.ext
86638740707SChao Yu  * mount w/ -o compress_extension=*; touch any_file
86738740707SChao Yu
868151b1982SFengnan Chang- To disable compression on regular inode, there are two ways:
869151b1982SFengnan Chang
870151b1982SFengnan Chang  * chattr -c file
871151b1982SFengnan Chang  * mount w/ -o nocompress_extension=ext; touch file.ext
872151b1982SFengnan Chang
873151b1982SFengnan Chang- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
874151b1982SFengnan Chang
875151b1982SFengnan Chang  * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch
876151b1982SFengnan Chang    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
877151b1982SFengnan Chang    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
878151b1982SFengnan Chang    can enable compress on bar.zip.
879151b1982SFengnan Chang  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
880151b1982SFengnan Chang    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
881151b1982SFengnan Chang    compresse, bar.zip and baz.txt should be non-compressed.
882151b1982SFengnan Chang    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
883151b1982SFengnan Chang    and baz.txt.
884151b1982SFengnan Chang
88538740707SChao Yu- At this point, compression feature doesn't expose compressed space to user
88638740707SChao Yu  directly in order to guarantee potential data updates later to the space.
88738740707SChao Yu  Instead, the main goal is to reduce data writes to flash disk as much as
88838740707SChao Yu  possible, resulting in extending disk life time as well as relaxing IO
8894a4fc043SFengnan Chang  congestion. Alternatively, we've added ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS)
8904a4fc043SFengnan Chang  interface to reclaim compressed space and show it to user after putting the
8914a4fc043SFengnan Chang  immutable bit. Immutable bit, after release, it doesn't allow writing/mmaping
8924a4fc043SFengnan Chang  on the file, until reserving compressed space via
8934a4fc043SFengnan Chang  ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or truncating filesize to zero.
89489272ca1SMauro Carvalho Chehab
89589272ca1SMauro Carvalho ChehabCompress metadata layout::
89689272ca1SMauro Carvalho Chehab
89789272ca1SMauro Carvalho Chehab				[Dnode Structure]
89889272ca1SMauro Carvalho Chehab		+-----------------------------------------------+
89989272ca1SMauro Carvalho Chehab		| cluster 1 | cluster 2 | ......... | cluster N |
90089272ca1SMauro Carvalho Chehab		+-----------------------------------------------+
90189272ca1SMauro Carvalho Chehab		.           .                       .           .
90289272ca1SMauro Carvalho Chehab	.                       .                .                      .
90389272ca1SMauro Carvalho Chehab    .         Compressed Cluster       .        .        Normal Cluster            .
90489272ca1SMauro Carvalho Chehab    +----------+---------+---------+---------+  +---------+---------+---------+---------+
90589272ca1SMauro Carvalho Chehab    |compr flag| block 1 | block 2 | block 3 |  | block 1 | block 2 | block 3 | block 4 |
90689272ca1SMauro Carvalho Chehab    +----------+---------+---------+---------+  +---------+---------+---------+---------+
90789272ca1SMauro Carvalho Chehab	    .                             .
90889272ca1SMauro Carvalho Chehab	    .                                           .
90989272ca1SMauro Carvalho Chehab	.                                                           .
91089272ca1SMauro Carvalho Chehab	+-------------+-------------+----------+----------------------------+
91189272ca1SMauro Carvalho Chehab	| data length | data chksum | reserved |      compressed data       |
91289272ca1SMauro Carvalho Chehab	+-------------+-------------+----------+----------------------------+
913de881df9SAravind Ramesh
914602a16d5SDaeho JeongCompression mode
915602a16d5SDaeho Jeong--------------------------
916602a16d5SDaeho Jeong
917602a16d5SDaeho Jeongf2fs supports "fs" and "user" compression modes with "compression_mode" mount option.
918602a16d5SDaeho JeongWith this option, f2fs provides a choice to select the way how to compress the
919602a16d5SDaeho Jeongcompression enabled files (refer to "Compression implementation" section for how to
920602a16d5SDaeho Jeongenable compression on a regular inode).
921602a16d5SDaeho Jeong
922602a16d5SDaeho Jeong1) compress_mode=fs
923602a16d5SDaeho JeongThis is the default option. f2fs does automatic compression in the writeback of the
924602a16d5SDaeho Jeongcompression enabled files.
925602a16d5SDaeho Jeong
926602a16d5SDaeho Jeong2) compress_mode=user
927092af2ebSEd TsaiThis disables the automatic compression and gives the user discretion of choosing the
928602a16d5SDaeho Jeongtarget file and the timing. The user can do manual compression/decompression on the
929602a16d5SDaeho Jeongcompression enabled files using F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE
930602a16d5SDaeho Jeongioctls like the below.
931602a16d5SDaeho Jeong
932602a16d5SDaeho JeongTo decompress a file,
933602a16d5SDaeho Jeong
934602a16d5SDaeho Jeongfd = open(filename, O_WRONLY, 0);
935602a16d5SDaeho Jeongret = ioctl(fd, F2FS_IOC_DECOMPRESS_FILE);
936602a16d5SDaeho Jeong
937602a16d5SDaeho JeongTo compress a file,
938602a16d5SDaeho Jeong
939602a16d5SDaeho Jeongfd = open(filename, O_WRONLY, 0);
940602a16d5SDaeho Jeongret = ioctl(fd, F2FS_IOC_COMPRESS_FILE);
941602a16d5SDaeho Jeong
942de881df9SAravind RameshNVMe Zoned Namespace devices
943de881df9SAravind Ramesh----------------------------
944de881df9SAravind Ramesh
945de881df9SAravind Ramesh- ZNS defines a per-zone capacity which can be equal or less than the
946de881df9SAravind Ramesh  zone-size. Zone-capacity is the number of usable blocks in the zone.
947ca313c82SRandy Dunlap  F2FS checks if zone-capacity is less than zone-size, if it is, then any
948de881df9SAravind Ramesh  segment which starts after the zone-capacity is marked as not-free in
949de881df9SAravind Ramesh  the free segment bitmap at initial mount time. These segments are marked
950de881df9SAravind Ramesh  as permanently used so they are not allocated for writes and
951de881df9SAravind Ramesh  consequently are not needed to be garbage collected. In case the
952de881df9SAravind Ramesh  zone-capacity is not aligned to default segment size(2MB), then a segment
953de881df9SAravind Ramesh  can start before the zone-capacity and span across zone-capacity boundary.
954de881df9SAravind Ramesh  Such spanning segments are also considered as usable segments. All blocks
955de881df9SAravind Ramesh  past the zone-capacity are considered unusable in these segments.
956