f2fs: avoid retrying quota flushes while the device is congested
PATCH 1/1 f2fs: avoid retrying quota flushes while the device is congested
While experimenting with ICE/FBE + f2fs on an Android device, I was able to reliably reproduce quota corruption during initial setup wizard.
During 10 times of factory resets, quota flushes failed 5 times each in average.
Add a wait for uncongestion on quota flush retries to resolve the issue.
--- fs/f2fs/checkpoint.c | 1 + 1 file changed, 1 insertion(+)
fs/f2fs/checkpoint.c +1 -0
@@ -1130,6 +1130,7 @@ static int block_operations(struct f2fs_sb_info *sbi)f2fs_lock_all (sbi);if (__need_flush_quota (sbi)) {f2fs_unlock_all (sbi); +congestion_wait (BLK_RW_ASYNC ,HZ /50 );cond_resched (); goto retry_flush_quotas; }
Signature · 1 line
2.21.0
Hi Ju Hyung,
Quoted 6 lines · Park Ju Hyung
While experimenting with ICE/FBE + f2fs on an Android device, I was able to reliably reproduce quota corruption during initial setup wizard.
During 10 times of factory resets, quota flushes failed 5 times each in average.
I knew this works in scenario cell phone suffers sudden power-cut frequently, actually, in a normal case, if there is race in between checkpoint() and quota updater, checkpoint() may suffer longer delay than before.
So I suggest we keep the logic as it is, since sudden power-cut is not a common case, even in such case, quota sysfile is corrupted, we have another chance to repair it with fsck-tools, right?
Thanks,
Quoted 21 lines
Add a wait for uncongestion on quota flush retries to resolve the issue.
Signed-off-by Park Ju Hyung <[email protected]>--- fs/f2fs/checkpoint.c | 1 + 1 file changed, 1 insertion(+)fs/f2fs/checkpoint.c +1
-0@@ -1130,6 +1130,7 @@ static int block_operations(struct f2fs_sb_info *sbi)f2fs_lock_all (sbi);if (__need_flush_quota (sbi)) {f2fs_unlock_all (sbi); +congestion_wait (BLK_RW_ASYNC ,HZ /50 );cond_resched (); goto retry_flush_quotas; }
Hi Chao,
Quoted 3 lines · Chao Yu
I knew this works in scenario cell phone suffers sudden power-cut frequently, actually, in a normal case, if there is race in between
checkpoint()and quota updater,checkpoint()may suffer longer delay than before.
This was actually not a sudden power-cut scenario.
After passing the setup wizard
(the quota flush timeout might have happened during initial dex2oat process) and simply rebooting, I always see "quota file may be corrupted, skip loading it".
I personally investigated this quota corruption issue as I frequently saw it on my
daily driver phone even when I never had sudden power-cuts.
Quoted 2 lines
So I suggest we keep the logic as it is, since sudden power-cut is not a common case,
As I said, the issue is caused from a totally normal scenario. A solution must be implemented imo.
Feel free to suggest a better idea/patch for me to test with.
Quoted 2 lines
even in such case, quota sysfile is corrupted, we have another chance to repair it with fsck-tools, right?
This is an another potential issue. Android does fsck.f2fs -a on boot and it does not
restore quota. Doing a run with -f fixes it, but not with -a.
This ultimately led the storage settings under the settings app to misbehave.
Thanks.
Hi Ju Hyung,
Quoted 13 lines · Ju Hyung Park
Hi Chao,
Quoted 3 lines · Chao Yu
I knew this works in scenario cell phone suffers sudden power-cut frequently, actually, in a normal case, if there is race in between
checkpoint()and quota updater,checkpoint()may suffer longer delay than before.This was actually not a sudden power-cut scenario.
After passing the setup wizard
(the quota flush timeout might have happened during initial dex2oat process) and simply rebooting, I always see "quota file may be corrupted, skip loading it".
Quoted 3 lines
I personally investigated this quota corruption issue as I frequently saw it on my
daily driver phone even when I never had sudden power-cuts.
Okay.
Quoted 7 lines
Quoted 3 lines
So I suggest we keep the logic as it is, since sudden power-cut is not a common case,
As I said, the issue is caused from a totally normal scenario. A solution must be implemented imo.
Feel free to suggest a better idea/patch for me to test with.
retry_flush_quotas:
if (__need_flush_quota(sbi)) {
int locked;
if (++cnt > DEFAULT_RETRY_QUOTA_FLUSH_COUNT) {
set_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
f2fs_lock_all(sbi);
goto retry_flush_dents;
}/* maximum retry quota flush count */
#define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8
I added above flush count number to limit cycle index, so that we won't be stuck for long time once we are under heavy racy in between checkpoint() and quota updating.
Once we skip flushing quota, in current checkpoint, quota sysfile may be corrupted, but if there is no sudden power-cut, I expect we can have chance to flush all data of quota file in next checkpoint, then the quota file is integrated again.
So could you track the root cause why we set the CP_QUOTA_NEED_FSCK_FLAG flag in checkpoint() from umount?
Do we skip flush quota due to flush count exceeds the DEFAULT_RETRY_QUOTA_FLUSH_COUNT?
Quoted 7 lines
Quoted 3 lines
even in such case, quota sysfile is corrupted, we have another chance to repair it with fsck-tools, right?
This is an another potential issue. Android does fsck.f2fs -a on boot and it does not
restore quota. Doing a run with -f fixes it, but not with -a.
Could you check your source code? did you apply dfede78aa918 ("fsck.f2fs: detect and recover corrupted quota file")? This patch can enable fsck to repair quota file corruption once kernel set CP_QUOTA_NEED_FSCK_FLAG flag.
Thanks,
Quoted 6 lines
This ultimately led the storage settings under the settings app to misbehave.
Thanks.
.
Hi Chao,
Quoted 6 lines · Chao Yu
/* maximum retry quota flush count */
#defineDEFAULT_RETRY_QUOTA_FLUSH_COUNT8I added above flush count number to limit cycle index, so that we won't be stuck for long time once we are under heavy racy in between
checkpoint()and quota updating.
I saw this. I actually first attempted increasing this to 16. It didn't fix it.
Quoted 7 lines
Once we skip flushing quota, in current checkpoint, quota sysfile may be corrupted, but if there is no sudden power-cut, I expect we can have chance to flush all data of quota file in next checkpoint, then the quota file is integrated again.
So could you track the root cause why we set the
CP_QUOTA_NEED_FSCK_FLAGflag incheckpoint()from umount?
Ok, I'll check this out. Please allow me a day or two for this.
Quoted 2 lines
Do we skip flush quota due to flush count exceeds the
DEFAULT_RETRY_QUOTA_FLUSH_COUNT?
I'll set this to an unrealistic number(e.g. 500) and add a log to check too.
Quoted 3 lines
Could you check your source code? did you apply
dfede78aa918("fsck.f2fs: detect and recover corrupted quota file")? This patch can enable fsck to repair quota file corruption once kernel setCP_QUOTA_NEED_FSCK_FLAGflag.
Oh right. Yeah my fsck.f2fs was not up-to-date(pie-release branch). False alarm.
Thanks.