Re: [f2fs-dev] [PATCH v2 18/20] f2fs: support subpage blocks in compression

From: Chao Yu

Date: Tue Nov 17 2026 - 21:30:00 EST


On 11/16/26 12:08, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@xxxxxxxxxx>
>
> With subpage blocks, a cluster spans fewer folios than blocks, and
> several compressed blocks share a bounce folio.
>
> - Require a cluster to cover at least one page. This raises the minimum
> compress_log_size only when a page has more than four blocks, e.g. to
> 64KB for 4KB blocks on a 64KB page kernel, where the mount option and
> F2FS_IOC_SET_COMPRESS_OPTION reject a smaller one. A file that already
> has a smaller cluster is handled like one with an unsupported
> compression algorithm: it can be looked up and removed, but opening it
> fails with -EOPNOTSUPP.
> - Use block offsets and sizes for compressed data, keep each compressed
> block at its block offset within the cluster, and count pending
> compressed I/O in blocks so that a shared bounce folio is not
> decompressed or freed early.
> - Submit only the written block of a shared bounce folio in
> f2fs_submit_page_write(), at its offset in the folio.
> - Keep compressed files on the page based read and write paths, and
> compress a cluster only when all of its blocks are dirty and below
> EOF.
> - A folio with per-block state may hold uptodate blocks newer than the
> on-disk cluster, so decompress into a bounce page and copy back only
> the blocks that are not uptodate.
> - Cache compressed blocks one block at a time in the compress cache.
> - Lock only the unlocked pages in cancel_cluster_writeback() to avoid a
> self-deadlock.
> - Attach a folio state to the multi-block folios of a rewritten cluster
> before they are dirtied, as the other write paths do.
> - Attach a folio state to multi-block folios that have none when
> compressed writeback starts, as the raw write path does. Otherwise the
> write completion, which does not hold the folio lock, can detach the
> page private flags while a task is moving them into a new folio state.
> - Take sbi from the dic to count the blocks of a compressed page in
> f2fs_finish_read_bio().
> - Write the blocks of a multi-block folio in
> f2fs_write_single_data_page() as f2fs_write_cache_folios() does,
> taking the write_blocks_pending bias with a new helper shared by the
> two and dropping it with f2fs_ffs_put_write_pending().
> - Count a read folio of a compressed file once in the iostat:
> f2fs_mpage_readpages() counts the folios that go through its loop,
> and f2fs_read_data_large_folio() counts the others.
> - Remove the -EOPNOTSUPP checks.
> - Remove inode_inc_dirty_block() and inode_dec_dirty_block(), which
> have no caller left.
>
> The bounce folios are now freed when the last block of a cluster
> completes, also when the block size equals PAGE_SIZE.
>
> Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>

Reviewed-by: Chao Yu <chao@xxxxxxxxxx>

One minor comment below:

> @@ -4277,6 +4354,46 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
>
> folio_zero_segment(folio, offset, folio_size(folio));
> write:
> + if (f2fs_is_multiblock_folio(sbi, folio)) {
> + struct f2fs_lock_context lc;
> + unsigned int to_blk = f2fs_blocks_per_folio(sbi, folio);
> + u64 pos = folio_pos(folio);
> +
> + if (!compr_blocks && !f2fs_verity_in_progress(inode))
> + to_blk = min_t(unsigned int,
> + F2FS_BLK_ALIGN(sbi, i_size - pos),
> + to_blk);
> +
> + /* Deadlock due to between page->lock and f2fs_lock_op */
> + if (!compr_blocks && !f2fs_trylock_op(sbi, &lc)) {
> + err = -EAGAIN;
> + goto redirty_out;
> + }
> +
> + folio_start_writeback(folio);
> + f2fs_folio_get_write_bias(folio, F2FS_BLK_TO_BYTES(sbi, to_blk));
> +
> + err = f2fs_write_folio_dirty_range(folio, &local_submitted,
> + wbc, io_type, pos,
> + pos + F2FS_BLK_TO_BYTES(sbi, to_blk),
> + compr_blocks);
> +
> + if (!compr_blocks)
> + f2fs_unlock_op(sbi, &lc);
> +
> + /* The callers drop the submitted count on error. */
> + if (err && local_submitted)
> + f2fs_submit_merged_write_cond(sbi, NULL, folio);

We'd better clean up this if this is not a bug fix.

I think we can pass local_submitted to @submitted_p in f2fs_write_raw_pages() before
its error handling, so that its caller (f2fs_write_cache_pages()) can flush the bio
cache.

Thanks,