Commit 8d2e73e
f2fs: atomic: fix to avoid racing w/ GC
[ Upstream commit 1a0bd28 ]
Case #1:
SQLite App GC Thread Kworker Shrinker
- f2fs_ioc_start_atomic_write
- f2fs_ioc_commit_atomic_write
- f2fs_commit_atomic_write
- filemap_write_and_wait_range
: write atomic_file's data to cow_inode
echo 3 > drop_caches
to drop atomic_file's
cache.
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
- writepages
- f2fs_do_write_data_page
: overwrite atomic_file's data
to cow_inode
- f2fs_down_write(&fi->i_gc_rwsem[WRITE])
- __f2fs_commit_atomic_write
- f2fs_up_write(&fi->i_gc_rwsem[WRITE])
Case #2:
SQLite App GC Thread Kworker
- f2fs_ioc_start_atomic_write
- __writeback_single_inode
- do_writepages
- f2fs_write_cache_pages
- f2fs_write_single_data_page
- f2fs_do_write_data_page
: write atomic_file's data to cow_inode
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
- writepages
- f2fs_do_write_data_page
: overwrite atomic_file's data to cow_inode
- f2fs_ioc_commit_atomic_write
In above cases racing in between atomic_write and GC, previous
data in atomic_file may be overwrited to cow_file, result in
data corruption.
This patch introduces PAGE_PRIVATE_ATOMIC_WRITE bit flag in page.private,
and use it to indicate that there is last dirty data in atomic file,
and the data should be writebacked into cow_file, if the flag is not
tagged in page, we should never write data across files.
Fixes: 3db1de0 ("f2fs: change the current atomic write way")
Cc: Daeho Jeong <[email protected]>
Signed-off-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>1 parent 82e71e9 commit 8d2e73e
2 files changed
+16
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2650 | 2650 | | |
2651 | 2651 | | |
2652 | 2652 | | |
| 2653 | + | |
2653 | 2654 | | |
2654 | 2655 | | |
2655 | 2656 | | |
2656 | | - | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
2657 | 2660 | | |
2658 | 2661 | | |
2659 | 2662 | | |
| |||
2752 | 2755 | | |
2753 | 2756 | | |
2754 | 2757 | | |
| 2758 | + | |
| 2759 | + | |
2755 | 2760 | | |
2756 | 2761 | | |
2757 | 2762 | | |
| |||
3721 | 3726 | | |
3722 | 3727 | | |
3723 | 3728 | | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
3724 | 3732 | | |
3725 | 3733 | | |
3726 | 3734 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1418 | 1418 | | |
1419 | 1419 | | |
1420 | 1420 | | |
1421 | | - | |
| 1421 | + | |
| 1422 | + | |
1422 | 1423 | | |
1423 | 1424 | | |
1424 | 1425 | | |
| |||
1428 | 1429 | | |
1429 | 1430 | | |
1430 | 1431 | | |
| 1432 | + | |
1431 | 1433 | | |
1432 | 1434 | | |
1433 | 1435 | | |
| |||
2396 | 2398 | | |
2397 | 2399 | | |
2398 | 2400 | | |
| 2401 | + | |
2399 | 2402 | | |
2400 | 2403 | | |
2401 | 2404 | | |
2402 | 2405 | | |
| 2406 | + | |
2403 | 2407 | | |
2404 | 2408 | | |
2405 | 2409 | | |
2406 | 2410 | | |
| 2411 | + | |
2407 | 2412 | | |
2408 | 2413 | | |
2409 | 2414 | | |
| |||
2435 | 2440 | | |
2436 | 2441 | | |
2437 | 2442 | | |
| 2443 | + | |
2438 | 2444 | | |
2439 | 2445 | | |
2440 | 2446 | | |
| |||
0 commit comments