Skip to contentSkip to conversation

common/quota: fix to wait for all inodes been evicted in _check_quota_usage()

PATCH In review Chao Yu 2 participants 2 messages Dec 9, 2025

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v3 1/1 common/quota: fix to wait for all inodes been evicted in _check_quota_usage()

generic/233 3s ... - output mismatch (see /share/git/fstests/results//generic/233.out.bad)

    --- tests/generic/233.out   2025-01-12 21:57:40.259440359 +0800
    +++ /share/git/fstests/results//generic/233.out.bad 2025-12-04 03:02:26.000000000 +0800
    @@ -4,4 +4,12 @@

     seed = S
     Comparing user usage
    +4c4
    +< #1000     --   31476   32000   32000            994  1000  1000
    +---
    +> #1000     --   31476   32000   32000            944  1000  1000
    ...
    (Run 'diff -u /share/git/fstests/tests/generic/233.out /share/git/fstests/results//generic/233.out.bad'  to see the entire diff)

Ran: generic/233
Failures: generic/233
Failed 1 of 1 tests

Sometimes, generic/233 will fail due to it founds inode count is mismatched in between quota system and filesystem.

The reason is cgroup v2 implementation will increase inode reference first, and then, attach it to thread related cgroup writeback structure, once it needs to switch write owner of target inode, a kernel thread will process it, and finally release inode reference via evict_inode().

So, sync & drop_cache may not guarantee all inodes being evicted, as cgroup has one more referenece on inodes during the time.

If inode has not been evicted, dquot inode reference will not be release, it will lead to inode count mismatch.

Let's add a delay to wait for cgroup switching completion before quota check.

Cc Jaegeuk Kim <[email protected]>
Cc Darrick J. Wong <[email protected]>

---
v3:
- sleep in existed case statement rather than in newly added check condition

 common/quota | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
common/quota +8 -1
index a51386b1..5d351fdf 100644
@@ -335,7 +335,14 @@ _check_quota_usage()
 
 	VFS_QUOTA=0
 	case $FSTYP in
-	ext2|ext3|ext4|f2fs|gfs2|bcachefs)
+	ext2|ext3|ext4|gfs2|bcachefs)
+		VFS_QUOTA=1
+		quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
+		;;
+	f2fs)
+		# wait for inode_switch_wbs_wor_fn() to release inodes
+		sleep 3
+
 		VFS_QUOTA=1
 		quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
 		;;
Signature · 1 line
2.49.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 28 lines · Chao Yu

generic/233 3s ... - output mismatch (see /share/git/fstests/results//generic/233.out.bad)

    --- tests/generic/233.out   2025-01-12 21:57:40.259440359 +0800
    +++ /share/git/fstests/results//generic/233.out.bad 2025-12-04 03:02:26.000000000 +0800
    @@ -4,4 +4,12 @@

     seed = S
     Comparing user usage
    +4c4
    +< #1000     --   31476   32000   32000            994  1000  1000
    +---
    +> #1000     --   31476   32000   32000            944  1000  1000
    ...
    (Run 'diff -u /share/git/fstests/tests/generic/233.out /share/git/fstests/results//generic/233.out.bad'  to see the entire diff)

Ran: generic/233
Failures: generic/233
Failed 1 of 1 tests

Sometimes, generic/233 will fail due to it founds inode count is mismatched in between quota system and filesystem.

The reason is cgroup v2 implementation will increase inode reference first, and then, attach it to thread related cgroup writeback structure, once it needs to switch write owner of target inode, a kernel thread will process it, and finally release inode reference via evict_inode().

So, sync & drop_cache may not guarantee all inodes being evicted, as cgroup has one more referenece on inodes during the time.

Quoted 8 lines

If inode has not been evicted, dquot inode reference will not be release, it will lead to inode count mismatch.

Let's add a delay to wait for cgroup switching completion before quota check.

Cc Jaegeuk Kim <[email protected]>
Cc Darrick J. Wong <[email protected]>

Looks fine to me now,

--D

Quoted 29 lines

---
v3:
- sleep in existed case statement rather than in newly added check condition

 common/quota | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
common/quota +8 -1
index a51386b1..5d351fdf 100644
@@ -335,7 +335,14 @@ _check_quota_usage()
 
 	VFS_QUOTA=0
 	case $FSTYP in
-	ext2|ext3|ext4|f2fs|gfs2|bcachefs)
+	ext2|ext3|ext4|gfs2|bcachefs)
+		VFS_QUOTA=1
+		quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
+		;;
+	f2fs)
+		# wait for inode_switch_wbs_wor_fn() to release inodes
+		sleep 3
+
 		VFS_QUOTA=1
 		quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
 		;;
Signature · 1 line
2.49.0