[PATCH v4 0/8] ext4 extent split/convert refactor and kunit tests

Ojaswin Mujoo posted 8 patches 2 weeks, 1 day ago
fs/ext4/ext4.h           |    4 +
fs/ext4/extents-test.c   | 1027 ++++++++++++++++++++++++++++++++++++++
fs/ext4/extents.c        |  568 +++++++++++----------
fs/ext4/extents_status.c |    1 +
fs/ext4/inode.c          |   12 +-
5 files changed, 1357 insertions(+), 255 deletions(-)
create mode 100644 fs/ext4/extents-test.c
[PATCH v4 0/8] ext4 extent split/convert refactor and kunit tests
Posted by Ojaswin Mujoo 2 weeks, 1 day ago
@Ted, I've rebased it over

   3574c322b1d0 -  ext4: use optimized mballoc scanning regardless of inode format

in your dev branch. 

Changes in v4:
- Rename EX_DATA_* -> EXT_DATA_* in kunit tests 
  to avoid build warnings on s390 arch due to redefining 
  symbols
- In kunit tests, fix a couple places to use le32_to_cpu() when
  accessing ex->ee_block

v3: https://lore.kernel.org/linux-ext4/cover.1768844021.git.ojaswin@linux.ibm.com/

Changes in v3:

- Use EX_DATA_LBLK/LEN instead of hard-coding in extents-test.c
- RVBs of Jan and Yi (Thanks!)
- Patch 6/8 - update orig_* after first split
- Minor fixes

Changes in v2:

** KUnit **

- Added new patch 3 to add support for tracking extent status cache in 
  kunit tests
- Kunit tests in patch 2 now test ext4_map_create_blocks() since the
  final es cachine is done here.
- Also refactored the patch 2 to avoid duplicate code.

** extent handling code **

- Fixed some issues detected by extent status Kunit tests where we were
  going out of sync when zeroout fallback was taken.
- We no longer handle unwrit to unwrit split as there are no users of
  that anymore
- Made sure to propogate flags to ext4_find_extent() as well in patch 4,5.
  Also remove some duplication of flags.
- Cleaned up the code flow of ext4_split_extent() in patch 6.
- Picked up RVBs by Jan.

v1: https://lore.kernel.org/linux-ext4/cover.1767528171.git.ojaswin@linux.ibm.com/T/#t

** Testing **

- Run xfstests for 4k, 64k and nodioread_nolock for -g auto with no new
  regressions.
- All new kunit tests in patch 1-3 that were failing due to issues are now
  passing with the patches

** Original Cover **

Offlate we've have seen multiple issues and inconsistencies in the
our extent splitting and conversion logic causing subtle bugs. Recent
patches by Yhang Zi [1] helped address some of the issues however
the messy use of EXT4_EXT_DATA_VALID* and EXT4_EXT_MARK_UNWRIT* flags
made the implementation confusing and error prone.

This patchset aims to refactor the explent split and convert code paths
to make the code simpler and the behavior consistent and easy to
understand. It also adds several Kunit tests to stress various
permutations of extent splitting and conversion.

I've rebased this over [2] since it seems like it'll go in first. 

Another idea I want to try out after this is proactively zeroout
before even trying to split, as Jan suggested here [3], but before
trying to do that I wanted to refactor and add some tests hence sending
these patches out first.

[1] https://lore.kernel.org/linux-ext4/20251129103247.686136-1-yi.zhang@huaweicloud.com/
[2] https://lore.kernel.org/linux-ext4/20251223011802.31238-1-yi.zhang@huaweicloud.com/T/#t
[3] https://lore.kernel.org/linux-ext4/yro4hwpttmy6e2zspvwjfdbpej6qvhlqjvlr5kp3nwffqgcnfd@z6qual55zhfq/

Rest of the details can be found in the commit messages.

Patch 1-2: new kunit tests
Patch 3-4: minor fixes
Patch 5: refactoring zeroout and making sure zeroout handles all
        permutations correctly
Patch 6: Refactoring ext4_split_* functions.
Patch 7: Enable zeroout for writ to unwrit case

*****

Ojaswin Mujoo (8):
  ext4: kunit tests for extent splitting and conversion
  ext4: kunit tests for higher level extent manipulation functions
  ext4: Add extent status cache support to kunit tests
  ext4: propagate flags to convert_initialized_extent()
  ext4: propagate flags to ext4_convert_unwritten_extents_endio()
  ext4: Refactor zeroout path and handle all cases
  ext4: Refactor split and convert extents
  ext4: Allow zeroout when doing written to unwritten split

 fs/ext4/ext4.h           |    4 +
 fs/ext4/extents-test.c   | 1027 ++++++++++++++++++++++++++++++++++++++
 fs/ext4/extents.c        |  568 +++++++++++----------
 fs/ext4/extents_status.c |    1 +
 fs/ext4/inode.c          |   12 +-
 5 files changed, 1357 insertions(+), 255 deletions(-)
 create mode 100644 fs/ext4/extents-test.c

-- 
2.52.0
Re: [PATCH v4 0/8] ext4 extent split/convert refactor and kunit tests
Posted by Theodore Ts'o 1 week, 3 days ago
On Fri, 23 Jan 2026 11:55:31 +0530, Ojaswin Mujoo wrote:
> @Ted, I've rebased it over
> 
>    3574c322b1d0 -  ext4: use optimized mballoc scanning regardless of inode format
> 
> in your dev branch.
> 
> Changes in v4:
> - Rename EX_DATA_* -> EXT_DATA_* in kunit tests
>   to avoid build warnings on s390 arch due to redefining
>   symbols
> - In kunit tests, fix a couple places to use le32_to_cpu() when
>   accessing ex->ee_block
> 
> [...]

Applied, thanks!

[1/8] ext4: kunit tests for extent splitting and conversion
      commit: cb1e0c1d1fad5bfad90d80c74ebdb53796d8a2db
[2/8] ext4: kunit tests for higher level extent manipulation functions
      commit: 4dff18488fe22b743d6e2ee32ca4a533ea237454
[3/8] ext4: Add extent status cache support to kunit tests
      commit: 82f80e2e3b23ef7ecdef0a494f7f310a1b1702e4
[4/8] ext4: propagate flags to convert_initialized_extent()
      commit: 3fffa44b6ebf65be92a562a5063303979385a1c9
[5/8] ext4: propagate flags to ext4_convert_unwritten_extents_endio()
      commit: 6066990c99c48d8955eb4b467c11e14daa8d5ec4
[6/8] ext4: Refactor zeroout path and handle all cases
      commit: a985e07c264552d0aa7c019ca54d075414c56620
[7/8] ext4: Refactor split and convert extents
      commit: 716b9c23b86240d419a43c1f211c628ac04acb8f
[8/8] ext4: Allow zeroout when doing written to unwritten split
      commit: 4f5e8e6f012349a107531b02eed5b5ace6181449

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>