Skip to content

f2fs: support block size smaller than PAGE_SIZE

Daeho Jeong linux-f2fs-devel lkml 2 versions – Applied

Status from this message: This series was applied to jaegeuk/f2fs.git (dev)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest20 patches 21 repliesApplied 20/20
  2. v120 patches 25 repliesSuperseded

Patches in v2 All 20 applied

#Subject and filesSizeRepliesApplied
1/20f2fs: use block-based index and size calculations in more pathsfs/f2fs/data.c fs/f2fs/dir.c fs/f2fs/file.c +1 more+32 -311 replyApplied
2/20f2fs: support subpage block size superblock and mountfs/f2fs/compress.c fs/f2fs/f2fs.h fs/f2fs/file.c +3 more+226 -621 replyApplied
3/20f2fs: extend f2fs_folio_state for subpage blocksfs/f2fs/data.c fs/f2fs/f2fs.h fs/f2fs/file.c +1 more+269 -2261 replyApplied
4/20f2fs: support subpage blocks in directory operationsfs/f2fs/dir.c fs/f2fs/f2fs.h fs/f2fs/inline.c+91 -401 replyApplied
5/20f2fs: convert inode dirty page counters to dirty block countersfs/f2fs/checkpoint.c fs/f2fs/data.c fs/f2fs/f2fs.h +4 more+38 -381 replyApplied
6/20f2fs: support subpage blocks in data read path and GCfs/f2fs/data.c fs/f2fs/f2fs.h fs/f2fs/file.c +2 more+358 -2112 repliesApplied
7/20f2fs: support subpage blocks in data write path and writebackfs/f2fs/checkpoint.c fs/f2fs/compress.c fs/f2fs/data.c +6 more+433 -2951 replyApplied
8/20f2fs: adapt range operations and mmap for subpage blocksfs/f2fs/data.c fs/f2fs/f2fs.h fs/f2fs/file.c+261 -1121 replyApplied
9/20f2fs: support subpage blocks in pinned filesfs/f2fs/file.c+16 -61 replyApplied
10/20f2fs: support subpage blocks in collapse and insert rangefs/f2fs/file.c+65 -501 replyApplied
11/20f2fs: support subpage blocks in move rangefs/f2fs/file.c+58 -151 replyApplied
12/20f2fs: support subpage blocks in defragmentationfs/f2fs/file.c+38 -61 replyApplied
13/20f2fs: support subpage blocks in swapfile activationfs/f2fs/data.c+28 -151 replyApplied
14/20f2fs: support subpage blocks in fs-verity enablementfs/f2fs/data.c fs/f2fs/f2fs.h fs/f2fs/file.c +1 more+26 -191 replyApplied
15/20f2fs: support subpage blocks in atomic writesfs/f2fs/data.c fs/f2fs/file.c fs/f2fs/inode.c +1 more+46 -161 replyApplied
16/20f2fs: preserve inline data in subpage block modefs/f2fs/data.c+45 -91 replyApplied
17/20f2fs: support subpage blocks in online resizefs/f2fs/file.c+0 -31 replyApplied
18/20f2fs: support subpage blocks in compressionDocumentation/filesystems/f2fs.rst fs/f2fs/compress.c fs/f2fs/data.c +3 more+657 -3431 replyApplied
19/20f2fs: count compress cache entries in pages for its memory limitfs/f2fs/node.c+4 -21 replyApplied
20/20f2fs: enable subpage block size supportfs/f2fs/super.c+0 -71 replyApplied

Reviews trailers per patch

All 20 patches have a Reviewed-by or Acked-by.

PatchChao Yu
1/20R-b
2/20R-b
3/20R-b
4/20R-b
5/20R-b
6/20R-b
7/20R-b
8/20R-b
9/20R-b
10/20R-b
11/20R-b
12/20R-b
13/20R-b
14/20R-b
15/20R-b
16/20R-b
17/20R-b
18/20R-b
19/20R-b
20/20R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/20] f2fs: support block size smaller than PAGE_SIZE

From: Daeho Jeong <[email protected]>

F2FS has required the filesystem block size to equal PAGE_SIZE. On a kernel with 16KB pages, this means an existing F2FS image with 4KB blocks cannot be mounted, e.g. the userdata partition of an Android device that moves from a 4KB page kernel to a 16KB page kernel.

This series lets F2FS mount and use a filesystem whose block size is smaller than PAGE_SIZE, such as 4KB blocks on a 16KB page kernel. The on-disk format does not change.

With subpage blocks, even an order-0 folio holds several blocks, so the series builds on the large folio support from Nanzhe Zhao [1] and tracks uptodate and dirty state per block in f2fs_folio_state for any folio that holds more than one block. Most paths then work in blocks instead of pages:

- Patches 1-2 convert more page based index and size calculations to block based ones, and add the superblock and mount infrastructure. Subpage block sizes are still rejected at this point.
- Patch 3 extends f2fs_folio_state with per-block state, identified by a magic number, and allocates it on demand with __GFP_NOFAIL.
- Patches 4-7 handle directories, the per-inode dirty counters, the read path and GC, and the write path and writeback per block.
- Patches 8-19 adapt the remaining features: range operations and mmap, pinned files, collapse/insert range, move range, defragmentation, swapfile, fs-verity, atomic writes, inline data, online resize and compression, and remove the -EOPNOTSUPP checks that patch 2 added for the features that need them.
- Patch 20 stops rejecting subpage block sizes.

When the block size equals PAGE_SIZE, the behavior does not change, except for the fixes noted in the individual patches. The following are not limited to subpage blocks or large folios:

- Patch 1: __complete_revoke_list() and __clone_blkaddrs() compute offsets in 64 bits on 32-bit architectures.
- Patch 8: an extending direct write updates i_size in ->end_io(), before iomap invalidates the page cache of the written range.
- Patch 10: collapse and insert range hold i_gc_rwsem[WRITE] and invalidate_lock until the moved blocks are written back and the page cache is dropped.
- Patch 11: move range zeroes the cached data past the old EOF of the destination before extending it, and drops the source blocks from the page cache also after an exchange that failed part way.
- Patch 12: defragmentation reads compressed files through ->read_folio(). A block of a compressed cluster that was not in the page cache was read without decompression and written back as file data.
- Patch 15: aborting atomic writes holds i_gc_rwsem[WRITE] and invalidate_lock.

A few of the patches adjust code from the large folio series [1]:

- f2fs_folio_has_ffs() checks the folio state magic instead of requiring a large folio, since order-0 multi-block folios also carry a folio state, and the page private flags can legitimately be set before a state is attached.
- f2fs_ffs_find_or_alloc() cannot fail with __GFP_NOFAIL, so the allocation failure handling of its callers is removed.
- The inode dirty blocks are counted from the dirty bits of the folio state, and ->dirty_folio() marks the uptodate blocks of a folio dirty, since mm does not tell which blocks were modified.
- Defragmentation and swapfile activation mark only the target block dirty instead of the whole page.

Changes in v2:

Addressed the review comments from Chao Yu and Nanzhe Zhao, the warning reported by the kernel test robot, and the findings of the Sashiko review. v1 is at [2].

- Patch 1 (block based calculations): rename the subject ("in more paths"). Use F2FS_BLK_ALIGN() in dir_blocks(). Compute the new i_size in __clone_blkaddrs() in 64 bits.
- Patch 2 (superblock and mount): probe the 2nd superblock from the smallest block size and stop at the first one found, so that a stale superblock of a larger block size is not picked, and return its error instead of the error of the last probe. Bound log_sectorsize by log_blocksize and remove F2FS_MAX_LOG_SECTOR_SIZE. Check the requested inline_xattr_size in f2fs_check_opt_consistency(). Do not set *recovery when no valid superblock is found. Report a failed read of a superblock again.
- Patch 3 (folio state): remove the unused variable in prepare_large_folio_write_begin(). Count the submitted blocks in nwritten also on error. Do not clear the uptodate flag of the folio of an inline inode in f2fs_invalidate_folio(). Explain the use of __GFP_NOFAIL in the commit message.
- Patch 4 (directories): read the name length in f2fs_delete_entry() under the folio lock. Clear the gcing flag of the folio when its last dirty block is freed. Simplify f2fs_dentry_to_lblk() and use f2fs_folio_lblk_address().
- Patch 5 (dirty counters): commit message only.
- Patch 6 (read path and GC): keep the folio state of a folio that is not fully uptodate in ->release_folio while the folio has other users. Read the block again in f2fs_get_read_data_folio() and f2fs_find_data_folio() when the folio state was released while the folio was unlocked, instead of failing. Do not map the blocks past EOF in f2fs_read_data_large_folio(). Read under memalloc_nofs in ra_data_block(), where GC locks are held. Rename f2fs_submit_page_read_sync() to f2fs_submit_block_read_sync().
- Patch 7 (write path and writeback): count the inode dirty blocks from the dirty bits of the folio state instead of per folio. Make ->dirty_folio() mark the uptodate blocks within EOF dirty, and add f2fs_folio_mark_dirty() for the updates made by f2fs, which mark only the blocks they modify. Keep f2fs_balance_fs_folio_locked() in write_begin instead of balancing after the folio is unlocked. Drop the pending write that a failed submission leaves behind in f2fs_convert_inline_folio(). Keep the folio dirty and accounted when flush_inline_data() fails.
- Patch 8 (range operations and mmap): update i_size of an extending direct write in ->end_io(). In page_mkwrite, reserve blocks only where it may allocate, i.e. not for a pinned file or a compressed cluster, do not balance with the folio locked, and read the blocks that are not uptodate after a partial invalidation. Check the dirty state of a reserved block only for SEEK_DATA.
- Patch 9 (pinned files): keep failing page_mkwrite on a device aliasing file with -EIO.
- Patch 10 (collapse and insert range): hold i_gc_rwsem[WRITE] and invalidate_lock from before the first writeback until the moved blocks are written back and the page cache is dropped.
- Patch 11 (move range): zero the cached data past the old EOF of the destination with f2fs_zero_post_eof_page() before the move. Drop the source blocks from the page cache also after an exchange that failed part way. Call pagecache_isize_extended() for the gap between the old EOF and the moved data.
- Patch 12 (defragmentation): read compressed files through ->read_folio() as well, and lock and redirty the folio that was read instead of looking it up again (f2fs_get_defrag_folio()).
- Patch 13 (swapfile): use f2fs_folio_mark_dirty().
- Patch 14 (fs-verity): stop the data reads of a verity file at i_size in f2fs_read_data_large_folio(). Do not zero the blocks past i_size on read while verity is being enabled.
- Patch 15 (atomic writes): hold i_gc_rwsem[WRITE] and invalidate_lock while aborting atomic writes, except at eviction.
- Patch 16 (inline data): redirty the folio and stop on any error of the inline writeback in f2fs_write_cache_folios(). Note the effect on inline inodes with large folios in the commit message.
- Patch 18 (compression): raise the minimum cluster size only when a page has more than four blocks, reject a smaller compress_log_size in the mount option and in F2FS_IOC_SET_COMPRESS_OPTION, fail the open of a file that already has a smaller cluster with -EOPNOTSUPP instead of failing its inode sanity check, and document it. Dirty every block of a partially dirty compressed cluster before it is rewritten. Attach a folio state to the multi-block folios of a rewritten cluster before they are dirtied. Count a read folio of a compressed file once in the iostat. Do not cut the range that redirty_blocks() dirties at EOF. Remove inode_inc_dirty_block() and inode_dec_dirty_block().
- Patches 17, 19 and 20: no change.
- The patches also use the F2FS_BLK_* helpers in more places, as suggested in the review.

Testing:

Built every patch for x86_64, arm64 (16KB pages), arm and i386.

Ran the xfstests auto group (excluding the clone, dedupe and thin groups) on arm64 QEMU with mount options "discard,fsync_mode=strict" in these combinations of page size / block size:

- 16KB/4KB: default, compression (lz4, zstd, lz4hc, lzo-rle with 64KB clusters and checksum), compression+encryption, encryption+verity, mode=lfs, atgc
- 4KB/4KB: default, compression, encryption+verity,
compression+encryption, mode=lfs
- 16KB/16KB: default, compression, encryption+verity, compression+encryption, mode=lfs

plus generic/019, 521, 522 and 780 for each combination, and a 24 hour power-off recovery test with fsstress for each of the three combinations.

There were no crashes or hangs, and the power-off recovery tests found no corruption. Two failures are worth a note, and neither depends on this series:

- generic/455 failed once on 16KB/4KB with encryption+verity, because fsync() returned before its node block was written. [3] fixes it.
- generic/551 was killed by the OOM killer in three of the compression runs. It is killed the same way without this series.

Also ran:

- The xfstests quick group with lockdep (PROVE_LOCKING and DEBUG_ATOMIC_SLEEP) on 16KB/4KB, default and compression. The only reports were in generic/574 with compression, where f2fs_decompress_cluster() may sleep in the read completion. This happens without this series as well, and [4] fixes it.
- 16 processes writing through mmap at the same time until the filesystem is full, on a 1GB image with 16KB pages and 4KB blocks, with and without large folios and with and without mode=lfs, as asked in the review of v1. They got SIGBUS only after the free space ran out, the data read back was correct, and fsck found no error.
- A 32-bit ARM kernel (4KB pages) with files beyond 4GB.

[1] https://lore.kernel.org/linux-f2fs-devel/[email protected]/
[2] https://lore.kernel.org/linux-f2fs-devel/[email protected]/
[3] https://lore.kernel.org/linux-f2fs-devel/[email protected]/
[4] https://lore.kernel.org/linux-f2fs-devel/[email protected]/

Daeho Jeong (20):
f2fs: use block-based index and size calculations in more paths
f2fs: support subpage block size superblock and mount
f2fs: extend f2fs_folio_state for subpage blocks
f2fs: support subpage blocks in directory operations
f2fs: convert inode dirty page counters to dirty block counters
f2fs: support subpage blocks in data read path and GC
f2fs: support subpage blocks in data write path and writeback
f2fs: adapt range operations and mmap for subpage blocks
f2fs: support subpage blocks in pinned files
f2fs: support subpage blocks in collapse and insert range
f2fs: support subpage blocks in move range
f2fs: support subpage blocks in defragmentation
f2fs: support subpage blocks in swapfile activation
f2fs: support subpage blocks in fs-verity enablement
f2fs: support subpage blocks in atomic writes
f2fs: preserve inline data in subpage block mode
f2fs: support subpage blocks in online resize
f2fs: support subpage blocks in compression
f2fs: count compress cache entries in pages for its memory limit
f2fs: enable subpage block size support

 Documentation/filesystems/f2fs.rst |    7 +-
 fs/f2fs/checkpoint.c               |   67 +-
 fs/f2fs/compress.c                 |  569 ++++++---
 fs/f2fs/data.c                     | 1725 ++++++++++++++++++----------
 fs/f2fs/dir.c                      |  126 +-
 fs/f2fs/f2fs.h                     |  237 ++--
 fs/f2fs/file.c                     |  716 ++++++++----
 fs/f2fs/gc.c                       |  103 +-
 fs/f2fs/inline.c                   |   23 +-
 fs/f2fs/inode.c                    |    3 +-
 fs/f2fs/node.c                     |   26 +-
 fs/f2fs/segment.c                  |   14 +-
 fs/f2fs/super.c                    |  180 ++-
 fs/f2fs/verity.c                   |    5 -
 include/linux/f2fs_fs.h            |    2 +-
 15 files changed, 2494 insertions(+), 1309 deletions(-)

base-commit: b9d7379d10d43386b59082da8c9a0b111e054781

Signature · 1 line
2.56.0.611.g1030f0b940-goog