Skip to content

Commit 8f45533

Browse files
committed
Merge tag 'f2fs-for-5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "In this round, we've introduced fairly small number of patches as below. Enhancements: - improve the in-place-update IO flow - allocate segment to guarantee no GC for pinned files Bug fixes: - fix updatetime in lazytime mode - potential memory leak in f2fs_listxattr - record parent inode number in rename2 correctly - fix deadlock in f2fs_gc along with atomic writes - avoid needless data migration in GC" * tag 'f2fs-for-5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: f2fs: stop GC when the victim becomes fully valid f2fs: expose main_blkaddr in sysfs f2fs: choose hardlimit when softlimit is larger than hardlimit in f2fs_statfs_project() f2fs: Fix deadlock in f2fs_gc() context during atomic files handling f2fs: show f2fs instance in printk_ratelimited f2fs: fix potential overflow f2fs: fix to update dir's i_pino during cross_rename f2fs: support aligned pinned file f2fs: avoid kernel panic on corruption test f2fs: fix wrong description in document f2fs: cache global IPU bio f2fs: fix to avoid memory leakage in f2fs_listxattr f2fs: check total_segments from devices in raw_super f2fs: update multi-dev metadata in resize_fs f2fs: mark recovery flag correctly in read_raw_super_block() f2fs: fix to update time in lazytime mode
2 parents 4a55d36 + 803e74b commit 8f45533

File tree

17 files changed

+421
-107
lines changed

17 files changed

+421
-107
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Contact: "Jaegeuk Kim" <[email protected]>
3131
Description:
3232
Controls the issue rate of segment discard commands.
3333

34+
What: /sys/fs/f2fs/<disk>/max_blkaddr
35+
Date: November 2019
36+
Contact: "Ramon Pantin" <[email protected]>
37+
Description:
38+
Shows first block address of MAIN area.
39+
3440
What: /sys/fs/f2fs/<disk>/ipu_policy
3541
Date: November 2013
3642
Contact: "Jaegeuk Kim" <[email protected]>

Documentation/filesystems/f2fs.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ Files in /sys/fs/f2fs/<devname>
297297
reclaim the prefree segments to free segments.
298298
By default, 5% over total # of segments.
299299

300+
main_blkaddr This value gives the first block address of
301+
MAIN area in the partition.
302+
300303
max_small_discards This parameter controls the number of discard
301304
commands that consist small blocks less than 2MB.
302305
The candidates to be discarded are cached until
@@ -346,7 +349,7 @@ Files in /sys/fs/f2fs/<devname>
346349

347350
ram_thresh This parameter controls the memory footprint used
348351
by free nids and cached nat entries. By default,
349-
10 is set, which indicates 10 MB / 1 GB RAM.
352+
1 is set, which indicates 10 MB / 1 GB RAM.
350353

351354
ra_nid_pages When building free nids, F2FS reads NAT blocks
352355
ahead for speed up. Default is 0.

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
581581

582582
if (time_to_inject(sbi, FAULT_ORPHAN)) {
583583
spin_unlock(&im->ino_lock);
584-
f2fs_show_injection_info(FAULT_ORPHAN);
584+
f2fs_show_injection_info(sbi, FAULT_ORPHAN);
585585
return -ENOSPC;
586586
}
587587

fs/f2fs/data.c

Lines changed: 153 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define NUM_PREALLOC_POST_READ_CTXS 128
3030

3131
static struct kmem_cache *bio_post_read_ctx_cache;
32+
static struct kmem_cache *bio_entry_slab;
3233
static mempool_t *bio_post_read_ctx_pool;
3334

3435
static bool __is_cp_guaranteed(struct page *page)
@@ -167,9 +168,10 @@ static bool f2fs_bio_post_read_required(struct bio *bio)
167168

168169
static void f2fs_read_end_io(struct bio *bio)
169170
{
170-
if (time_to_inject(F2FS_P_SB(bio_first_page_all(bio)),
171-
FAULT_READ_IO)) {
172-
f2fs_show_injection_info(FAULT_READ_IO);
171+
struct f2fs_sb_info *sbi = F2FS_P_SB(bio_first_page_all(bio));
172+
173+
if (time_to_inject(sbi, FAULT_READ_IO)) {
174+
f2fs_show_injection_info(sbi, FAULT_READ_IO);
173175
bio->bi_status = BLK_STS_IOERR;
174176
}
175177

@@ -191,7 +193,7 @@ static void f2fs_write_end_io(struct bio *bio)
191193
struct bvec_iter_all iter_all;
192194

193195
if (time_to_inject(sbi, FAULT_WRITE_IO)) {
194-
f2fs_show_injection_info(FAULT_WRITE_IO);
196+
f2fs_show_injection_info(sbi, FAULT_WRITE_IO);
195197
bio->bi_status = BLK_STS_IOERR;
196198
}
197199

@@ -543,6 +545,126 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
543545
return io_type_is_mergeable(io, fio);
544546
}
545547

548+
static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
549+
struct page *page, enum temp_type temp)
550+
{
551+
struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
552+
struct bio_entry *be;
553+
554+
be = f2fs_kmem_cache_alloc(bio_entry_slab, GFP_NOFS);
555+
be->bio = bio;
556+
bio_get(bio);
557+
558+
if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE)
559+
f2fs_bug_on(sbi, 1);
560+
561+
down_write(&io->bio_list_lock);
562+
list_add_tail(&be->list, &io->bio_list);
563+
up_write(&io->bio_list_lock);
564+
}
565+
566+
static void del_bio_entry(struct bio_entry *be)
567+
{
568+
list_del(&be->list);
569+
kmem_cache_free(bio_entry_slab, be);
570+
}
571+
572+
static int add_ipu_page(struct f2fs_sb_info *sbi, struct bio **bio,
573+
struct page *page)
574+
{
575+
enum temp_type temp;
576+
bool found = false;
577+
int ret = -EAGAIN;
578+
579+
for (temp = HOT; temp < NR_TEMP_TYPE && !found; temp++) {
580+
struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
581+
struct list_head *head = &io->bio_list;
582+
struct bio_entry *be;
583+
584+
down_write(&io->bio_list_lock);
585+
list_for_each_entry(be, head, list) {
586+
if (be->bio != *bio)
587+
continue;
588+
589+
found = true;
590+
591+
if (bio_add_page(*bio, page, PAGE_SIZE, 0) == PAGE_SIZE) {
592+
ret = 0;
593+
break;
594+
}
595+
596+
/* bio is full */
597+
del_bio_entry(be);
598+
__submit_bio(sbi, *bio, DATA);
599+
break;
600+
}
601+
up_write(&io->bio_list_lock);
602+
}
603+
604+
if (ret) {
605+
bio_put(*bio);
606+
*bio = NULL;
607+
}
608+
609+
return ret;
610+
}
611+
612+
void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
613+
struct bio **bio, struct page *page)
614+
{
615+
enum temp_type temp;
616+
bool found = false;
617+
struct bio *target = bio ? *bio : NULL;
618+
619+
for (temp = HOT; temp < NR_TEMP_TYPE && !found; temp++) {
620+
struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
621+
struct list_head *head = &io->bio_list;
622+
struct bio_entry *be;
623+
624+
if (list_empty(head))
625+
continue;
626+
627+
down_read(&io->bio_list_lock);
628+
list_for_each_entry(be, head, list) {
629+
if (target)
630+
found = (target == be->bio);
631+
else
632+
found = __has_merged_page(be->bio, NULL,
633+
page, 0);
634+
if (found)
635+
break;
636+
}
637+
up_read(&io->bio_list_lock);
638+
639+
if (!found)
640+
continue;
641+
642+
found = false;
643+
644+
down_write(&io->bio_list_lock);
645+
list_for_each_entry(be, head, list) {
646+
if (target)
647+
found = (target == be->bio);
648+
else
649+
found = __has_merged_page(be->bio, NULL,
650+
page, 0);
651+
if (found) {
652+
target = be->bio;
653+
del_bio_entry(be);
654+
break;
655+
}
656+
}
657+
up_write(&io->bio_list_lock);
658+
}
659+
660+
if (found)
661+
__submit_bio(sbi, target, DATA);
662+
if (bio && *bio) {
663+
bio_put(*bio);
664+
*bio = NULL;
665+
}
666+
}
667+
546668
int f2fs_merge_page_bio(struct f2fs_io_info *fio)
547669
{
548670
struct bio *bio = *fio->bio;
@@ -557,20 +679,17 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
557679
f2fs_trace_ios(fio, 0);
558680

559681
if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
560-
fio->new_blkaddr)) {
561-
__submit_bio(fio->sbi, bio, fio->type);
562-
bio = NULL;
563-
}
682+
fio->new_blkaddr))
683+
f2fs_submit_merged_ipu_write(fio->sbi, &bio, NULL);
564684
alloc_new:
565685
if (!bio) {
566686
bio = __bio_alloc(fio, BIO_MAX_PAGES);
567687
bio_set_op_attrs(bio, fio->op, fio->op_flags);
568-
}
569688

570-
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
571-
__submit_bio(fio->sbi, bio, fio->type);
572-
bio = NULL;
573-
goto alloc_new;
689+
add_bio_entry(fio->sbi, bio, page, fio->temp);
690+
} else {
691+
if (add_ipu_page(fio->sbi, &bio, page))
692+
goto alloc_new;
574693
}
575694

576695
if (fio->io_wbc)
@@ -584,19 +703,6 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
584703
return 0;
585704
}
586705

587-
static void f2fs_submit_ipu_bio(struct f2fs_sb_info *sbi, struct bio **bio,
588-
struct page *page)
589-
{
590-
if (!bio)
591-
return;
592-
593-
if (!__has_merged_page(*bio, NULL, page, 0))
594-
return;
595-
596-
__submit_bio(sbi, *bio, DATA);
597-
*bio = NULL;
598-
}
599-
600706
void f2fs_submit_page_write(struct f2fs_io_info *fio)
601707
{
602708
struct f2fs_sb_info *sbi = fio->sbi;
@@ -2098,7 +2204,7 @@ static int __write_data_page(struct page *page, bool *submitted,
20982204
loff_t i_size = i_size_read(inode);
20992205
const pgoff_t end_index = ((unsigned long long) i_size)
21002206
>> PAGE_SHIFT;
2101-
loff_t psize = (page->index + 1) << PAGE_SHIFT;
2207+
loff_t psize = (loff_t)(page->index + 1) << PAGE_SHIFT;
21022208
unsigned offset = 0;
21032209
bool need_balance_fs = false;
21042210
int err = 0;
@@ -2215,14 +2321,12 @@ static int __write_data_page(struct page *page, bool *submitted,
22152321

22162322
unlock_page(page);
22172323
if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode) &&
2218-
!F2FS_I(inode)->cp_task) {
2219-
f2fs_submit_ipu_bio(sbi, bio, page);
2324+
!F2FS_I(inode)->cp_task)
22202325
f2fs_balance_fs(sbi, need_balance_fs);
2221-
}
22222326

22232327
if (unlikely(f2fs_cp_error(sbi))) {
2224-
f2fs_submit_ipu_bio(sbi, bio, page);
22252328
f2fs_submit_merged_write(sbi, DATA);
2329+
f2fs_submit_merged_ipu_write(sbi, bio, NULL);
22262330
submitted = NULL;
22272331
}
22282332

@@ -2342,13 +2446,11 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
23422446
}
23432447

23442448
if (PageWriteback(page)) {
2345-
if (wbc->sync_mode != WB_SYNC_NONE) {
2449+
if (wbc->sync_mode != WB_SYNC_NONE)
23462450
f2fs_wait_on_page_writeback(page,
23472451
DATA, true, true);
2348-
f2fs_submit_ipu_bio(sbi, &bio, page);
2349-
} else {
2452+
else
23502453
goto continue_unlock;
2351-
}
23522454
}
23532455

23542456
if (!clear_page_dirty_for_io(page))
@@ -2406,7 +2508,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
24062508
NULL, 0, DATA);
24072509
/* submit cached bio of IPU write */
24082510
if (bio)
2409-
__submit_bio(sbi, bio, DATA);
2511+
f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
24102512

24112513
return ret;
24122514
}
@@ -3211,8 +3313,22 @@ int __init f2fs_init_post_read_processing(void)
32113313
return -ENOMEM;
32123314
}
32133315

3214-
void __exit f2fs_destroy_post_read_processing(void)
3316+
void f2fs_destroy_post_read_processing(void)
32153317
{
32163318
mempool_destroy(bio_post_read_ctx_pool);
32173319
kmem_cache_destroy(bio_post_read_ctx_cache);
32183320
}
3321+
3322+
int __init f2fs_init_bio_entry_cache(void)
3323+
{
3324+
bio_entry_slab = f2fs_kmem_cache_create("bio_entry_slab",
3325+
sizeof(struct bio_entry));
3326+
if (!bio_entry_slab)
3327+
return -ENOMEM;
3328+
return 0;
3329+
}
3330+
3331+
void __exit f2fs_destroy_bio_entry_cache(void)
3332+
{
3333+
kmem_cache_destroy(bio_entry_slab);
3334+
}

fs/f2fs/dir.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
628628

629629
start:
630630
if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) {
631-
f2fs_show_injection_info(FAULT_DIR_DEPTH);
631+
f2fs_show_injection_info(F2FS_I_SB(dir), FAULT_DIR_DEPTH);
632632
return -ENOSPC;
633633
}
634634

@@ -919,8 +919,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
919919
bit_pos++;
920920
ctx->pos = start_pos + bit_pos;
921921
printk_ratelimited(
922-
"%s, invalid namelen(0), ino:%u, run fsck to fix.",
923-
KERN_WARNING, le32_to_cpu(de->ino));
922+
"%sF2FS-fs (%s): invalid namelen(0), ino:%u, run fsck to fix.",
923+
KERN_WARNING, sbi->sb->s_id,
924+
le32_to_cpu(de->ino));
924925
set_sbi_flag(sbi, SBI_NEED_FSCK);
925926
continue;
926927
}

0 commit comments

Comments
 (0)