Skip to content

Commit bab475c

Browse files
chaseyuJaegeuk Kim
authored andcommitted
Revert: "f2fs: check last page index in cached bio to decide submission"
There is one case that we can leave bio in f2fs, result in hanging page writeback waiter. Thread A Thread B - f2fs_write_cache_pages - f2fs_submit_page_write page #0 cached in bio #0 of cold log - f2fs_submit_page_write page #1 cached in bio #1 of warm log - f2fs_write_cache_pages - f2fs_submit_page_write bio is full, submit bio #1 contain page #1 - f2fs_submit_merged_write_cond(, page #1) fail to submit bio #0 due to page #1 is not in any cached bios. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent d440c52 commit bab475c

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ static int __f2fs_write_meta_page(struct page *page,
276276
dec_page_count(sbi, F2FS_DIRTY_META);
277277

278278
if (wbc->for_reclaim)
279-
f2fs_submit_merged_write_cond(sbi, page->mapping->host,
280-
0, page->index, META);
279+
f2fs_submit_merged_write_cond(sbi, NULL, page, 0, META);
281280

282281
unlock_page(page);
283282

fs/f2fs/data.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
322322
io->bio = NULL;
323323
}
324324

325-
static bool __has_merged_page(struct f2fs_bio_info *io,
326-
struct inode *inode, nid_t ino, pgoff_t idx)
325+
static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode,
326+
struct page *page, nid_t ino)
327327
{
328328
struct bio_vec *bvec;
329329
struct page *target;
@@ -332,7 +332,7 @@ static bool __has_merged_page(struct f2fs_bio_info *io,
332332
if (!io->bio)
333333
return false;
334334

335-
if (!inode && !ino)
335+
if (!inode && !page && !ino)
336336
return true;
337337

338338
bio_for_each_segment_all(bvec, io->bio, i) {
@@ -342,11 +342,10 @@ static bool __has_merged_page(struct f2fs_bio_info *io,
342342
else
343343
target = fscrypt_control_page(bvec->bv_page);
344344

345-
if (idx != target->index)
346-
continue;
347-
348345
if (inode && inode == target->mapping->host)
349346
return true;
347+
if (page && page == target)
348+
return true;
350349
if (ino && ino == ino_of_node(target))
351350
return true;
352351
}
@@ -355,7 +354,8 @@ static bool __has_merged_page(struct f2fs_bio_info *io,
355354
}
356355

357356
static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode,
358-
nid_t ino, pgoff_t idx, enum page_type type)
357+
struct page *page, nid_t ino,
358+
enum page_type type)
359359
{
360360
enum page_type btype = PAGE_TYPE_OF_BIO(type);
361361
enum temp_type temp;
@@ -366,7 +366,7 @@ static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode,
366366
io = sbi->write_io[btype] + temp;
367367

368368
down_read(&io->io_rwsem);
369-
ret = __has_merged_page(io, inode, ino, idx);
369+
ret = __has_merged_page(io, inode, page, ino);
370370
up_read(&io->io_rwsem);
371371

372372
/* TODO: use HOT temp only for meta pages now. */
@@ -397,12 +397,12 @@ static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
397397
}
398398

399399
static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
400-
struct inode *inode, nid_t ino, pgoff_t idx,
401-
enum page_type type, bool force)
400+
struct inode *inode, struct page *page,
401+
nid_t ino, enum page_type type, bool force)
402402
{
403403
enum temp_type temp;
404404

405-
if (!force && !has_merged_page(sbi, inode, ino, idx, type))
405+
if (!force && !has_merged_page(sbi, inode, page, ino, type))
406406
return;
407407

408408
for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
@@ -421,10 +421,10 @@ void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
421421
}
422422

423423
void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
424-
struct inode *inode, nid_t ino, pgoff_t idx,
425-
enum page_type type)
424+
struct inode *inode, struct page *page,
425+
nid_t ino, enum page_type type)
426426
{
427-
__submit_merged_write_cond(sbi, inode, ino, idx, type, false);
427+
__submit_merged_write_cond(sbi, inode, page, ino, type, false);
428428
}
429429

430430
void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
@@ -1952,7 +1952,7 @@ static int __write_data_page(struct page *page, bool *submitted,
19521952
ClearPageUptodate(page);
19531953

19541954
if (wbc->for_reclaim) {
1955-
f2fs_submit_merged_write_cond(sbi, inode, 0, page->index, DATA);
1955+
f2fs_submit_merged_write_cond(sbi, NULL, page, 0, DATA);
19561956
clear_inode_flag(inode, FI_HOT_DATA);
19571957
f2fs_remove_dirty_inode(inode);
19581958
submitted = NULL;
@@ -2010,10 +2010,10 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
20102010
pgoff_t index;
20112011
pgoff_t end; /* Inclusive */
20122012
pgoff_t done_index;
2013-
pgoff_t last_idx = ULONG_MAX;
20142013
int cycled;
20152014
int range_whole = 0;
20162015
int tag;
2016+
int nwritten = 0;
20172017

20182018
pagevec_init(&pvec);
20192019

@@ -2116,7 +2116,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21162116
done = 1;
21172117
break;
21182118
} else if (submitted) {
2119-
last_idx = page->index;
2119+
nwritten++;
21202120
}
21212121

21222122
if (--wbc->nr_to_write <= 0 &&
@@ -2138,9 +2138,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21382138
if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
21392139
mapping->writeback_index = done_index;
21402140

2141-
if (last_idx != ULONG_MAX)
2141+
if (nwritten)
21422142
f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
2143-
0, last_idx, DATA);
2143+
NULL, 0, DATA);
21442144

21452145
return ret;
21462146
}

fs/f2fs/f2fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,8 +3032,8 @@ int f2fs_init_post_read_processing(void);
30323032
void f2fs_destroy_post_read_processing(void);
30333033
void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
30343034
void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
3035-
struct inode *inode, nid_t ino, pgoff_t idx,
3036-
enum page_type type);
3035+
struct inode *inode, struct page *page,
3036+
nid_t ino, enum page_type type);
30373037
void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
30383038
int f2fs_submit_page_bio(struct f2fs_io_info *fio);
30393039
void f2fs_submit_page_write(struct f2fs_io_info *fio);

fs/f2fs/node.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,7 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted,
15651565
up_read(&sbi->node_write);
15661566

15671567
if (wbc->for_reclaim) {
1568-
f2fs_submit_merged_write_cond(sbi, page->mapping->host, 0,
1569-
page->index, NODE);
1568+
f2fs_submit_merged_write_cond(sbi, NULL, page, 0, NODE);
15701569
submitted = NULL;
15711570
}
15721571

@@ -1631,13 +1630,13 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
16311630
unsigned int *seq_id)
16321631
{
16331632
pgoff_t index;
1634-
pgoff_t last_idx = ULONG_MAX;
16351633
struct pagevec pvec;
16361634
int ret = 0;
16371635
struct page *last_page = NULL;
16381636
bool marked = false;
16391637
nid_t ino = inode->i_ino;
16401638
int nr_pages;
1639+
int nwritten = 0;
16411640

16421641
if (atomic) {
16431642
last_page = last_fsync_dnode(sbi, ino);
@@ -1715,7 +1714,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
17151714
f2fs_put_page(last_page, 0);
17161715
break;
17171716
} else if (submitted) {
1718-
last_idx = page->index;
1717+
nwritten++;
17191718
}
17201719

17211720
if (page == last_page) {
@@ -1741,8 +1740,8 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
17411740
goto retry;
17421741
}
17431742
out:
1744-
if (last_idx != ULONG_MAX)
1745-
f2fs_submit_merged_write_cond(sbi, NULL, ino, last_idx, NODE);
1743+
if (nwritten)
1744+
f2fs_submit_merged_write_cond(sbi, NULL, NULL, ino, NODE);
17461745
return ret ? -EIO: 0;
17471746
}
17481747

fs/f2fs/segment.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static int __f2fs_commit_inmem_pages(struct inode *inode)
371371
.io_type = FS_DATA_IO,
372372
};
373373
struct list_head revoke_list;
374-
pgoff_t last_idx = ULONG_MAX;
374+
bool submit_bio = false;
375375
int err = 0;
376376

377377
INIT_LIST_HEAD(&revoke_list);
@@ -406,14 +406,14 @@ static int __f2fs_commit_inmem_pages(struct inode *inode)
406406
}
407407
/* record old blkaddr for revoking */
408408
cur->old_addr = fio.old_blkaddr;
409-
last_idx = page->index;
409+
submit_bio = true;
410410
}
411411
unlock_page(page);
412412
list_move_tail(&cur->list, &revoke_list);
413413
}
414414

415-
if (last_idx != ULONG_MAX)
416-
f2fs_submit_merged_write_cond(sbi, inode, 0, last_idx, DATA);
415+
if (submit_bio)
416+
f2fs_submit_merged_write_cond(sbi, inode, NULL, 0, DATA);
417417

418418
if (err) {
419419
/*
@@ -3181,8 +3181,7 @@ void f2fs_wait_on_page_writeback(struct page *page,
31813181
if (PageWriteback(page)) {
31823182
struct f2fs_sb_info *sbi = F2FS_P_SB(page);
31833183

3184-
f2fs_submit_merged_write_cond(sbi, page->mapping->host,
3185-
0, page->index, type);
3184+
f2fs_submit_merged_write_cond(sbi, NULL, page, 0, type);
31863185
if (ordered)
31873186
wait_on_page_writeback(page);
31883187
else

0 commit comments

Comments
 (0)