Commit d889928
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 <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 8edf3a4 commit d889928
2 files changed
+16
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2623 | 2623 | | |
2624 | 2624 | | |
2625 | 2625 | | |
| 2626 | + | |
2626 | 2627 | | |
2627 | 2628 | | |
2628 | 2629 | | |
2629 | | - | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
2630 | 2633 | | |
2631 | 2634 | | |
2632 | 2635 | | |
| |||
2730 | 2733 | | |
2731 | 2734 | | |
2732 | 2735 | | |
| 2736 | + | |
| 2737 | + | |
2733 | 2738 | | |
2734 | 2739 | | |
2735 | 2740 | | |
| |||
3700 | 3705 | | |
3701 | 3706 | | |
3702 | 3707 | | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
3703 | 3711 | | |
3704 | 3712 | | |
3705 | 3713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1411 | 1411 | | |
1412 | 1412 | | |
1413 | 1413 | | |
1414 | | - | |
| 1414 | + | |
| 1415 | + | |
1415 | 1416 | | |
1416 | 1417 | | |
1417 | 1418 | | |
| |||
1421 | 1422 | | |
1422 | 1423 | | |
1423 | 1424 | | |
| 1425 | + | |
1424 | 1426 | | |
1425 | 1427 | | |
1426 | 1428 | | |
| |||
2386 | 2388 | | |
2387 | 2389 | | |
2388 | 2390 | | |
| 2391 | + | |
2389 | 2392 | | |
2390 | 2393 | | |
2391 | 2394 | | |
2392 | 2395 | | |
| 2396 | + | |
2393 | 2397 | | |
2394 | 2398 | | |
2395 | 2399 | | |
2396 | 2400 | | |
| 2401 | + | |
2397 | 2402 | | |
2398 | 2403 | | |
2399 | 2404 | | |
| |||
2425 | 2430 | | |
2426 | 2431 | | |
2427 | 2432 | | |
| 2433 | + | |
2428 | 2434 | | |
2429 | 2435 | | |
2430 | 2436 | | |
| |||
0 commit comments