kernel_optimize_test/fs/ext4
Eric Whitney 4b3139576a ext4: shrink race window in ext4_should_retry_alloc()
[ Upstream commit efc61345274d6c7a46a0570efbc916fcbe3e927b ]

When generic/371 is run on kvm-xfstests using 5.10 and 5.11 kernels, it
fails at significant rates on the two test scenarios that disable
delayed allocation (ext3conv and data_journal) and force actual block
allocation for the fallocate and pwrite functions in the test.  The
failure rate on 5.10 for both ext3conv and data_journal on one test
system typically runs about 85%.  On 5.11, the failure rate on ext3conv
sometimes drops to as low as 1% while the rate on data_journal
increases to nearly 100%.

The observed failures are largely due to ext4_should_retry_alloc()
cutting off block allocation retries when s_mb_free_pending (used to
indicate that a transaction in progress will free blocks) is 0.
However, free space is usually available when this occurs during runs
of generic/371.  It appears that a thread attempting to allocate
blocks is just missing transaction commits in other threads that
increase the free cluster count and reset s_mb_free_pending while
the allocating thread isn't running.  Explicitly testing for free space
availability avoids this race.

The current code uses a post-increment operator in the conditional
expression that determines whether the retry limit has been exceeded.
This means that the conditional expression uses the value of the
retry counter before it's increased, resulting in an extra retry cycle.
The current code actually retries twice before hitting its retry limit
rather than once.

Increasing the retry limit to 3 from the current actual maximum retry
count of 2 in combination with the change described above reduces the
observed failure rate to less that 0.1% on both ext3conv and
data_journal with what should be limited impact on users sensitive to
the overhead caused by retries.

A per filesystem percpu counter exported via sysfs is added to allow
users or developers to track the number of times the retry limit is
exceeded without resorting to debugging methods.  This should provide
some insight into worst case retry behavior.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Link: https://lore.kernel.org/r/20210218151132.19678-1-enwlinux@gmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-04-07 15:00:03 +02:00
..
acl.c
acl.h
balloc.c ext4: shrink race window in ext4_should_retry_alloc() 2021-04-07 15:00:03 +02:00
bitmap.c
block_validity.c
dir.c
ext4_extents.h
ext4_jbd2.c
ext4_jbd2.h
ext4.h ext4: shrink race window in ext4_should_retry_alloc() 2021-04-07 15:00:03 +02:00
extents_status.c
extents_status.h
extents.c
fast_commit.c ext4: fix rename whiteout with fast commit 2021-03-25 09:04:17 +01:00
fast_commit.h
file.c
fsmap.c
fsmap.h
fsync.c
hash.c
ialloc.c
indirect.c
inline.c
inode-test.c
inode.c ext4: fix potential error in ext4_do_update_inode 2021-03-25 09:04:17 +01:00
ioctl.c
Kconfig
Makefile
mballoc.c fs/ext4: fix integer overflow in s_log_groups_per_flex 2021-03-30 14:32:08 +02:00
mballoc.h
migrate.c
mmp.c
move_extent.c
namei.c ext4: fix rename whiteout with fast commit 2021-03-25 09:04:17 +01:00
page-io.c
readpage.c
resize.c
super.c ext4: shrink race window in ext4_should_retry_alloc() 2021-04-07 15:00:03 +02:00
symlink.c
sysfs.c ext4: shrink race window in ext4_should_retry_alloc() 2021-04-07 15:00:03 +02:00
truncate.h
verity.c ext4: fix error handling in ext4_end_enable_verity() 2021-03-25 09:04:17 +01:00
xattr_hurd.c
xattr_security.c
xattr_trusted.c
xattr_user.c
xattr.c ext4: add reclaim checks to xattr code 2021-03-30 14:32:08 +02:00
xattr.h