Commit 1a0bd28
f2fs: atomic: fix to avoid racing w/ GC
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 <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>1 parent d72750e commit 1a0bd28
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 | |
|---|---|---|---|
| |||
1424 | 1424 | | |
1425 | 1425 | | |
1426 | 1426 | | |
1427 | | - | |
| 1427 | + | |
| 1428 | + | |
1428 | 1429 | | |
1429 | 1430 | | |
1430 | 1431 | | |
| |||
1434 | 1435 | | |
1435 | 1436 | | |
1436 | 1437 | | |
| 1438 | + | |
1437 | 1439 | | |
1438 | 1440 | | |
1439 | 1441 | | |
| |||
2404 | 2406 | | |
2405 | 2407 | | |
2406 | 2408 | | |
| 2409 | + | |
2407 | 2410 | | |
2408 | 2411 | | |
2409 | 2412 | | |
2410 | 2413 | | |
| 2414 | + | |
2411 | 2415 | | |
2412 | 2416 | | |
2413 | 2417 | | |
2414 | 2418 | | |
| 2419 | + | |
2415 | 2420 | | |
2416 | 2421 | | |
2417 | 2422 | | |
| |||
2443 | 2448 | | |
2444 | 2449 | | |
2445 | 2450 | | |
| 2451 | + | |
2446 | 2452 | | |
2447 | 2453 | | |
2448 | 2454 | | |
| |||
0 commit comments