Skip to content

Commit 5c7ecad

Browse files
committed
Merge tag 'f2fs-for-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs update from Jaegeuk Kim: "In this round, we've mainly modified to support non-power-of-two zone size, which is not required for f2fs by design. In order to avoid arch dependency, we refactored the messy rb_entry structure shared across different extent_cache. In addition to the improvement, we've also fixed several subtle bugs and error cases. Enhancements: - support non-power-of-two zone size for zoned device - remove sharing the rb_entry structure in extent cache - refactor f2fs_gc to call checkpoint in urgent condition - support iopoll Bug fixes: - fix potential corruption when moving a directory - fix to avoid use-after-free for cached IPU bio - fix the folio private usage - avoid kernel warnings or panics in the cp_error case - fix to recover quota data correctly - fix some bugs in atomic operations - fix system crash due to lack of free space in LFS - fix null pointer panic in tracepoint in __replace_atomic_write_block - fix iostat lock protection - fix scheduling while atomic in decompression path - preserve direct write semantics when buffering is forced - fix to call f2fs_wait_on_page_writeback() in f2fs_write_raw_pages()" * tag 'f2fs-for-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (52 commits) f2fs: remove unnessary comment in __may_age_extent_tree f2fs: allocate node blocks for atomic write block replacement f2fs: use cow inode data when updating atomic write f2fs: remove power-of-two limitation of zoned device f2fs: allocate trace path buffer from names_cache f2fs: add has_enough_free_secs() f2fs: relax sanity check if checkpoint is corrupted f2fs: refactor f2fs_gc to call checkpoint in urgent condition f2fs: remove folio_detach_private() in .invalidate_folio and .release_folio f2fs: remove bulk remove_proc_entry() and unnecessary kobject_del() f2fs: support iopoll method f2fs: remove batched_trim_sections node description f2fs: fix to check return value of inc_valid_block_count() f2fs: fix to check return value of f2fs_do_truncate_blocks() f2fs: fix passing relative address when discard zones f2fs: fix potential corruption when moving a directory f2fs: add radix_tree_preload_end in error case f2fs: fix to recover quota data correctly f2fs: fix to check readonly condition correctly docs: f2fs: Correct instruction to disable checkpoint ...
2 parents fbfaf03 + 8375be2 commit 5c7ecad

File tree

22 files changed

+899
-897
lines changed

22 files changed

+899
-897
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ Description: Controls the memory footprint used by free nids and cached
190190
nat entries. By default, 1 is set, which indicates
191191
10 MB / 1 GB RAM.
192192

193-
What: /sys/fs/f2fs/<disk>/batched_trim_sections
194-
Date: February 2015
195-
Contact: "Jaegeuk Kim" <[email protected]>
196-
Description: Controls the trimming rate in batch mode.
197-
<deprecated>
198-
199193
What: /sys/fs/f2fs/<disk>/cp_interval
200194
Date: October 2015
201195
Contact: "Jaegeuk Kim" <[email protected]>
@@ -729,3 +723,20 @@ What: /sys/fs/f2fs/<disk>/last_age_weight
729723
Date: January 2023
730724
Contact: "Ping Xiong" <[email protected]>
731725
Description: When DATA SEPARATION is on, it controls the weight of last data block age.
726+
727+
What: /sys/fs/f2fs/<disk>/compress_watermark
728+
Date: February 2023
729+
Contact: "Yangtao Li" <[email protected]>
730+
Description: When compress cache is on, it controls free memory watermark
731+
in order to limit caching compress page. If free memory is lower
732+
than watermark, then deny caching compress page. The value should be in
733+
range of (0, 100], by default it was initialized as 20(%).
734+
735+
What: /sys/fs/f2fs/<disk>/compress_percent
736+
Date: February 2023
737+
Contact: "Yangtao Li" <[email protected]>
738+
Description: When compress cache is on, it controls cached page
739+
percent(compress pages / free_ram) in order to limit caching compress page.
740+
If cached page percent exceed threshold, then deny caching compress page.
741+
The value should be in range of (0, 100], by default it was initialized
742+
as 20(%).

Documentation/filesystems/f2fs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ checkpoint=%s[:%u[%]] Set to "disable" to turn off checkpointing. Set to "enabl
264264
disabled, any unmounting or unexpected shutdowns will cause
265265
the filesystem contents to appear as they did when the
266266
filesystem was mounted with that option.
267-
While mounting with checkpoint=disabled, the filesystem must
267+
While mounting with checkpoint=disable, the filesystem must
268268
run garbage collection to ensure that all available space can
269269
be used. If this takes too much time, the mount may return
270270
EAGAIN. You may optionally add a value to indicate how much

fs/f2fs/checkpoint.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
152152
se = get_seg_entry(sbi, segno);
153153

154154
exist = f2fs_test_bit(offset, se->cur_valid_map);
155+
156+
/* skip data, if we already have an error in checkpoint. */
157+
if (unlikely(f2fs_cp_error(sbi)))
158+
return exist;
159+
155160
if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
156161
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
157162
blkaddr, exist);
@@ -202,6 +207,11 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
202207
case DATA_GENERIC_ENHANCE_UPDATE:
203208
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
204209
blkaddr < MAIN_BLKADDR(sbi))) {
210+
211+
/* Skip to emit an error message. */
212+
if (unlikely(f2fs_cp_error(sbi)))
213+
return false;
214+
205215
f2fs_warn(sbi, "access invalid blkaddr:%u",
206216
blkaddr);
207217
set_sbi_flag(sbi, SBI_NEED_FSCK);
@@ -325,8 +335,15 @@ static int __f2fs_write_meta_page(struct page *page,
325335

326336
trace_f2fs_writepage(page, META);
327337

328-
if (unlikely(f2fs_cp_error(sbi)))
338+
if (unlikely(f2fs_cp_error(sbi))) {
339+
if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) {
340+
ClearPageUptodate(page);
341+
dec_page_count(sbi, F2FS_DIRTY_META);
342+
unlock_page(page);
343+
return 0;
344+
}
329345
goto redirty_out;
346+
}
330347
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
331348
goto redirty_out;
332349
if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
@@ -508,6 +525,7 @@ static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino,
508525
if (!e) {
509526
if (!new) {
510527
spin_unlock(&im->ino_lock);
528+
radix_tree_preload_end();
511529
goto retry;
512530
}
513531
e = new;
@@ -706,32 +724,18 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
706724
int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
707725
{
708726
block_t start_blk, orphan_blocks, i, j;
709-
unsigned int s_flags = sbi->sb->s_flags;
710727
int err = 0;
711-
#ifdef CONFIG_QUOTA
712-
int quota_enabled;
713-
#endif
714728

715729
if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
716730
return 0;
717731

718-
if (bdev_read_only(sbi->sb->s_bdev)) {
732+
if (f2fs_hw_is_readonly(sbi)) {
719733
f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
720734
return 0;
721735
}
722736

723-
if (s_flags & SB_RDONLY) {
737+
if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE))
724738
f2fs_info(sbi, "orphan cleanup on readonly fs");
725-
sbi->sb->s_flags &= ~SB_RDONLY;
726-
}
727-
728-
#ifdef CONFIG_QUOTA
729-
/*
730-
* Turn on quotas which were not enabled for read-only mounts if
731-
* filesystem has quota feature, so that they are updated correctly.
732-
*/
733-
quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
734-
#endif
735739

736740
start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
737741
orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
@@ -765,13 +769,6 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
765769
out:
766770
set_sbi_flag(sbi, SBI_IS_RECOVERED);
767771

768-
#ifdef CONFIG_QUOTA
769-
/* Turn quotas off */
770-
if (quota_enabled)
771-
f2fs_quota_off_umount(sbi->sb);
772-
#endif
773-
sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
774-
775772
return err;
776773
}
777774

@@ -982,7 +979,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
982979

983980
cp_blk_no = le32_to_cpu(fsb->cp_blkaddr);
984981
if (cur_page == cp2)
985-
cp_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg);
982+
cp_blk_no += BIT(le32_to_cpu(fsb->log_blocks_per_seg));
986983

987984
for (i = 1; i < cp_blks; i++) {
988985
void *sit_bitmap_ptr;
@@ -1133,7 +1130,7 @@ int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type,
11331130
goto retry;
11341131
}
11351132

1136-
int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
1133+
static int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
11371134
{
11381135
struct list_head *head = &sbi->inode_list[DIRTY_META];
11391136
struct inode *inode;
@@ -1306,7 +1303,8 @@ void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
13061303
if (!get_pages(sbi, type))
13071304
break;
13081305

1309-
if (unlikely(f2fs_cp_error(sbi)))
1306+
if (unlikely(f2fs_cp_error(sbi) &&
1307+
!is_sbi_flag_set(sbi, SBI_IS_CLOSE)))
13101308
break;
13111309

13121310
if (type == F2FS_DIRTY_META)

fs/f2fs/compress.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -264,35 +264,21 @@ static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
264264
cc->private = NULL;
265265
}
266266

267-
#ifdef CONFIG_F2FS_FS_LZ4HC
268-
static int lz4hc_compress_pages(struct compress_ctx *cc)
267+
static int lz4_compress_pages(struct compress_ctx *cc)
269268
{
269+
int len = -EINVAL;
270270
unsigned char level = F2FS_I(cc->inode)->i_compress_level;
271-
int len;
272271

273-
if (level)
274-
len = LZ4_compress_HC(cc->rbuf, cc->cbuf->cdata, cc->rlen,
275-
cc->clen, level, cc->private);
276-
else
272+
if (!level)
277273
len = LZ4_compress_default(cc->rbuf, cc->cbuf->cdata, cc->rlen,
278274
cc->clen, cc->private);
279-
if (!len)
280-
return -EAGAIN;
281-
282-
cc->clen = len;
283-
return 0;
284-
}
285-
#endif
286-
287-
static int lz4_compress_pages(struct compress_ctx *cc)
288-
{
289-
int len;
290-
291275
#ifdef CONFIG_F2FS_FS_LZ4HC
292-
return lz4hc_compress_pages(cc);
276+
else
277+
len = LZ4_compress_HC(cc->rbuf, cc->cbuf->cdata, cc->rlen,
278+
cc->clen, level, cc->private);
293279
#endif
294-
len = LZ4_compress_default(cc->rbuf, cc->cbuf->cdata, cc->rlen,
295-
cc->clen, cc->private);
280+
if (len < 0)
281+
return len;
296282
if (!len)
297283
return -EAGAIN;
298284

@@ -670,7 +656,7 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
670656

671657
cc->cbuf->clen = cpu_to_le32(cc->clen);
672658

673-
if (fi->i_compress_flag & 1 << COMPRESS_CHKSUM)
659+
if (fi->i_compress_flag & BIT(COMPRESS_CHKSUM))
674660
chksum = f2fs_crc32(F2FS_I_SB(cc->inode),
675661
cc->cbuf->cdata, cc->clen);
676662
cc->cbuf->chksum = cpu_to_le32(chksum);
@@ -755,13 +741,18 @@ void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task)
755741

756742
if (dic->clen > PAGE_SIZE * dic->nr_cpages - COMPRESS_HEADER_SIZE) {
757743
ret = -EFSCORRUPTED;
758-
f2fs_handle_error(sbi, ERROR_FAIL_DECOMPRESSION);
744+
745+
/* Avoid f2fs_commit_super in irq context */
746+
if (in_task)
747+
f2fs_save_errors(sbi, ERROR_FAIL_DECOMPRESSION);
748+
else
749+
f2fs_handle_error(sbi, ERROR_FAIL_DECOMPRESSION);
759750
goto out_release;
760751
}
761752

762753
ret = cops->decompress_pages(dic);
763754

764-
if (!ret && (fi->i_compress_flag & 1 << COMPRESS_CHKSUM)) {
755+
if (!ret && (fi->i_compress_flag & BIT(COMPRESS_CHKSUM))) {
765756
u32 provided = le32_to_cpu(dic->cbuf->chksum);
766757
u32 calculated = f2fs_crc32(sbi, dic->cbuf->cdata, dic->clen);
767758

@@ -1456,6 +1447,12 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
14561447
if (!PageDirty(cc->rpages[i]))
14571448
goto continue_unlock;
14581449

1450+
if (PageWriteback(cc->rpages[i])) {
1451+
if (wbc->sync_mode == WB_SYNC_NONE)
1452+
goto continue_unlock;
1453+
f2fs_wait_on_page_writeback(cc->rpages[i], DATA, true, true);
1454+
}
1455+
14591456
if (!clear_page_dirty_for_io(cc->rpages[i]))
14601457
goto continue_unlock;
14611458

0 commit comments

Comments
 (0)