From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [f2fs-dev] [PATCH v2 12/20] f2fs: support subpage blocks in defragmentation
Date: Sun, 15 Nov 2026 20:08:43 -0800 [thread overview]
Message-ID: <20261116040851.2849696-13-daeho43@gmail.com> (raw)
In-Reply-To: <20261116040851.2849696-1-daeho43@gmail.com>
From: Daeho Jeong <daehojeong@google.com>
Mark only the target block, not its whole page, dirty when redirtying
data for defragmentation. Remove the -EOPNOTSUPP check.
Read a multi-block folio once through ->read_folio() instead of each
block synchronously, and redirty the folio that was read after locking
it. This also applies to large folios when the block size equals
PAGE_SIZE.
Read compressed files through ->read_folio() as well, with any block
size. f2fs_get_lock_data_folio() reads the mapped block as it is, so a
block of a compressed cluster that was not in the page cache was read
without decompression, and defragmentation wrote the compressed data
back as file data.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
fs/f2fs/file.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4499a461be86..26dd06961389 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3202,6 +3202,41 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)
return ret;
}
+/*
+ * Return the locked folio of a block to redirty it for defragmentation.
+ *
+ * A compressed file is read through ->read_folio(), which decompresses the
+ * cluster: f2fs_get_lock_data_folio() would read the mapped block as it is
+ * and leave compressed data in the page cache. A multi-block folio is read
+ * the same way, in one I/O instead of one synchronous read per block.
+ */
+static struct folio *f2fs_get_defrag_folio(struct file *filp, pgoff_t bidx)
+{
+ struct inode *inode = file_inode(filp);
+ struct address_space *mapping = inode->i_mapping;
+ pgoff_t index = f2fs_lblk_to_folio_index(F2FS_I_SB(inode), bidx);
+ struct folio *folio;
+
+ if (!f2fs_compressed_file(inode) && !f2fs_has_multiblock_folios(inode))
+ return f2fs_get_lock_data_folio(inode, bidx, true);
+
+repeat:
+ folio = read_mapping_folio(mapping, index, filp);
+ if (IS_ERR(folio))
+ return folio;
+
+ folio_lock(folio);
+ if (unlikely(folio->mapping != mapping)) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+ if (unlikely(!folio_test_uptodate(folio))) {
+ f2fs_folio_put(folio, true);
+ return ERR_PTR(-EIO);
+ }
+ return folio;
+}
+
static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
struct file *filp,
struct f2fs_defragment *range)
@@ -3327,7 +3362,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
cnt < BLKS_PER_SEG(sbi)) {
struct folio *folio;
- folio = f2fs_get_lock_data_folio(inode, idx, true);
+ folio = f2fs_get_defrag_folio(filp, idx);
if (IS_ERR(folio)) {
err = PTR_ERR(folio);
goto clear_out;
@@ -3336,8 +3371,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
f2fs_folio_wait_writeback(folio, true, true);
f2fs_ffs_mark_subrange_dirty(folio,
- offset_in_folio(folio, (loff_t)idx << PAGE_SHIFT),
- PAGE_SIZE);
+ f2fs_folio_byte_offset(sbi, folio, idx),
+ F2FS_BLKSIZE(sbi));
f2fs_folio_mark_dirty(folio);
folio_set_f2fs_gcing(folio);
f2fs_folio_put(folio, true);
@@ -3378,9 +3413,6 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
struct f2fs_defragment range;
int err;
- if (f2fs_has_subpage_blocks(sbi))
- return -EOPNOTSUPP;
-
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
--
2.56.0.611.g1030f0b940-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [PATCH v2 12/20] f2fs: support subpage blocks in defragmentation
Date: Sun, 15 Nov 2026 20:08:43 -0800 [thread overview]
Message-ID: <20261116040851.2849696-13-daeho43@gmail.com> (raw)
In-Reply-To: <20261116040851.2849696-1-daeho43@gmail.com>
From: Daeho Jeong <daehojeong@google.com>
Mark only the target block, not its whole page, dirty when redirtying
data for defragmentation. Remove the -EOPNOTSUPP check.
Read a multi-block folio once through ->read_folio() instead of each
block synchronously, and redirty the folio that was read after locking
it. This also applies to large folios when the block size equals
PAGE_SIZE.
Read compressed files through ->read_folio() as well, with any block
size. f2fs_get_lock_data_folio() reads the mapped block as it is, so a
block of a compressed cluster that was not in the page cache was read
without decompression, and defragmentation wrote the compressed data
back as file data.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
fs/f2fs/file.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4499a461be86..26dd06961389 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3202,6 +3202,41 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)
return ret;
}
+/*
+ * Return the locked folio of a block to redirty it for defragmentation.
+ *
+ * A compressed file is read through ->read_folio(), which decompresses the
+ * cluster: f2fs_get_lock_data_folio() would read the mapped block as it is
+ * and leave compressed data in the page cache. A multi-block folio is read
+ * the same way, in one I/O instead of one synchronous read per block.
+ */
+static struct folio *f2fs_get_defrag_folio(struct file *filp, pgoff_t bidx)
+{
+ struct inode *inode = file_inode(filp);
+ struct address_space *mapping = inode->i_mapping;
+ pgoff_t index = f2fs_lblk_to_folio_index(F2FS_I_SB(inode), bidx);
+ struct folio *folio;
+
+ if (!f2fs_compressed_file(inode) && !f2fs_has_multiblock_folios(inode))
+ return f2fs_get_lock_data_folio(inode, bidx, true);
+
+repeat:
+ folio = read_mapping_folio(mapping, index, filp);
+ if (IS_ERR(folio))
+ return folio;
+
+ folio_lock(folio);
+ if (unlikely(folio->mapping != mapping)) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+ if (unlikely(!folio_test_uptodate(folio))) {
+ f2fs_folio_put(folio, true);
+ return ERR_PTR(-EIO);
+ }
+ return folio;
+}
+
static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
struct file *filp,
struct f2fs_defragment *range)
@@ -3327,7 +3362,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
cnt < BLKS_PER_SEG(sbi)) {
struct folio *folio;
- folio = f2fs_get_lock_data_folio(inode, idx, true);
+ folio = f2fs_get_defrag_folio(filp, idx);
if (IS_ERR(folio)) {
err = PTR_ERR(folio);
goto clear_out;
@@ -3336,8 +3371,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
f2fs_folio_wait_writeback(folio, true, true);
f2fs_ffs_mark_subrange_dirty(folio,
- offset_in_folio(folio, (loff_t)idx << PAGE_SHIFT),
- PAGE_SIZE);
+ f2fs_folio_byte_offset(sbi, folio, idx),
+ F2FS_BLKSIZE(sbi));
f2fs_folio_mark_dirty(folio);
folio_set_f2fs_gcing(folio);
f2fs_folio_put(folio, true);
@@ -3378,9 +3413,6 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
struct f2fs_defragment range;
int err;
- if (f2fs_has_subpage_blocks(sbi))
- return -EOPNOTSUPP;
-
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
--
2.56.0.611.g1030f0b940-goog
next prev parent reply other threads:[~2026-11-16 4:09 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 4:08 [f2fs-dev] [PATCH v2 00/20] f2fs: support block size smaller than PAGE_SIZE Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 01/20] f2fs: use block-based index and size calculations in more paths Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:53 ` [f2fs-dev] " Chao Yu
2026-11-17 8:53 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 02/20] f2fs: support subpage block size superblock and mount Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:53 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 8:53 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 03/20] f2fs: extend f2fs_folio_state for subpage blocks Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:54 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 8:54 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 04/20] f2fs: support subpage blocks in directory operations Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:54 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 8:54 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 05/20] f2fs: convert inode dirty page counters to dirty block counters Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:54 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 8:54 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 06/20] f2fs: support subpage blocks in data read path and GC Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 8:58 ` [f2fs-dev] " Chao Yu
2026-11-17 8:58 ` Chao Yu via Linux-f2fs-devel
2026-11-17 16:51 ` Jaegeuk Kim
2026-11-17 16:51 ` Jaegeuk Kim via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 07/20] f2fs: support subpage blocks in data write path and writeback Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 10:43 ` [f2fs-dev] " Chao Yu
2026-11-17 10:43 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 08/20] f2fs: adapt range operations and mmap for subpage blocks Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:05 ` [f2fs-dev] " Chao Yu
2026-11-17 11:05 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 09/20] f2fs: support subpage blocks in pinned files Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:09 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:09 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 10/20] f2fs: support subpage blocks in collapse and insert range Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:13 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:13 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 11/20] f2fs: support subpage blocks in move range Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:22 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:22 ` Chao Yu
2026-11-16 4:08 ` Daeho Jeong [this message]
2026-11-16 4:08 ` [PATCH v2 12/20] f2fs: support subpage blocks in defragmentation Daeho Jeong
2026-11-17 11:25 ` [f2fs-dev] " Chao Yu
2026-11-17 11:25 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 13/20] f2fs: support subpage blocks in swapfile activation Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:25 ` [f2fs-dev] " Chao Yu
2026-11-17 11:25 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 14/20] f2fs: support subpage blocks in fs-verity enablement Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:38 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:38 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 15/20] f2fs: support subpage blocks in atomic writes Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:39 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:39 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 16/20] f2fs: preserve inline data in subpage block mode Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:40 ` [f2fs-dev] " Chao Yu
2026-11-17 11:40 ` Chao Yu via Linux-f2fs-devel
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 17/20] f2fs: support subpage blocks in online resize Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-17 11:41 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-17 11:41 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 18/20] f2fs: support subpage blocks in compression Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-18 2:29 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-18 2:29 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 19/20] f2fs: count compress cache entries in pages for its memory limit Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-18 2:30 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-18 2:30 ` Chao Yu
2026-11-16 4:08 ` [f2fs-dev] [PATCH v2 20/20] f2fs: enable subpage block size support Daeho Jeong
2026-11-16 4:08 ` Daeho Jeong
2026-11-18 2:30 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-18 2:30 ` Chao Yu
2026-11-17 16:50 ` [f2fs-dev] [PATCH v2 00/20] f2fs: support block size smaller than PAGE_SIZE patchwork-bot+f2fs--- via Linux-f2fs-devel
2026-11-17 16:50 ` patchwork-bot+f2fs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116040851.2849696-13-daeho43@gmail.com \
--to=daeho43@gmail.com \
--cc=daehojeong@google.com \
--cc=kernel-team@android.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.