Skip to content

Commit 4d3aed7

Browse files
drosen-googleJaegeuk Kim
authored andcommitted
f2fs: Add option to limit required GC for checkpoint=disable
This extends the checkpoint option to allow checkpoint=disable:%u[%] This allows you to specify what how much of the disk you are willing to lose access to while mounting with checkpoint=disable. If the amount lost would be higher, the mount will return -EAGAIN. This can be given as a percent of total space, or in blocks. Currently, we need to run garbage collection until the amount of holes is smaller than the OVP space. With the new option, f2fs can mark space as unusable up front instead of requiring garbage collection until the number of holes is small enough. Signed-off-by: Daniel Rosenberg <drosen@google.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent a4c3eca commit 4d3aed7

6 files changed

Lines changed: 99 additions & 26 deletions

File tree

‎Documentation/ABI/testing/sysfs-fs-f2fs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,11 @@ Description:
243243
- Del: echo '[h/c]!extension' > /sys/fs/f2fs/<disk>/extension_list
244244
- [h] means add/del hot file extension
245245
- [c] means add/del cold file extension
246+
247+
What: /sys/fs/f2fs/<disk>/unusable
248+
Date April 2019
249+
Contact: "Daniel Rosenberg" <drosen@google.com>
250+
Description:
251+
If checkpoint=disable, it displays the number of blocks that are unusable.
252+
If checkpoint=enable it displays the enumber of blocks that would be unusable
253+
if checkpoint=disable were to be set.

‎Documentation/filesystems/f2fs.txt‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,22 @@ fsync_mode=%s Control the policy of fsync. Currently supports "posix",
214214
non-atomic files likewise "nobarrier" mount option.
215215
test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt
216216
context. The fake fscrypt context is used by xfstests.
217-
checkpoint=%s Set to "disable" to turn off checkpointing. Set to "enable"
217+
checkpoint=%s[:%u[%]] Set to "disable" to turn off checkpointing. Set to "enable"
218218
to reenable checkpointing. Is enabled by default. While
219219
disabled, any unmounting or unexpected shutdowns will cause
220220
the filesystem contents to appear as they did when the
221221
filesystem was mounted with that option.
222+
While mounting with checkpoint=disabled, the filesystem must
223+
run garbage collection to ensure that all available space can
224+
be used. If this takes too much time, the mount may return
225+
EAGAIN. You may optionally add a value to indicate how much
226+
of the disk you would be willing to temporarily give up to
227+
avoid additional garbage collection. This can be given as a
228+
number of blocks, or as a percent. For instance, mounting
229+
with checkpoint=disable:100% would always succeed, but it may
230+
hide up to all remaining free space. The actual space that
231+
would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
232+
This space is reclaimed once checkpoint=enable.
222233

223234
================================================================================
224235
DEBUGFS ENTRIES
@@ -396,6 +407,12 @@ Files in /sys/fs/f2fs/<devname>
396407

397408
current_reserved_blocks This shows # of blocks currently reserved.
398409

410+
unusable If checkpoint=disable, this shows the number of
411+
blocks that are unusable.
412+
If checkpoint=enable it shows the number of blocks
413+
that would be unusable if checkpoint=disable were
414+
to be set.
415+
399416
================================================================================
400417
USAGE
401418
================================================================================

‎fs/f2fs/f2fs.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ struct f2fs_mount_info {
136136
int alloc_mode; /* segment allocation policy */
137137
int fsync_mode; /* fsync policy */
138138
bool test_dummy_encryption; /* test dummy encryption */
139+
block_t unusable_cap; /* Amount of space allowed to be
140+
* unusable when disabling checkpoint
141+
*/
139142
};
140143

141144
#define F2FS_FEATURE_ENCRYPT 0x0001
@@ -3085,7 +3088,8 @@ bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi);
30853088
void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
30863089
struct cp_control *cpc);
30873090
void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
3088-
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi);
3091+
block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi);
3092+
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable);
30893093
void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
30903094
int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
30913095
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);

‎fs/f2fs/segment.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,14 @@ void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi)
873873
mutex_unlock(&dirty_i->seglist_lock);
874874
}
875875

876-
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
876+
block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi)
877877
{
878-
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
879878
int ovp_hole_segs =
880879
(overprovision_segments(sbi) - reserved_segments(sbi));
881880
block_t ovp_holes = ovp_hole_segs << sbi->log_blocks_per_seg;
881+
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
882882
block_t holes[2] = {0, 0}; /* DATA and NODE */
883+
block_t unusable;
883884
struct seg_entry *se;
884885
unsigned int segno;
885886

@@ -893,7 +894,17 @@ int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
893894
}
894895
mutex_unlock(&dirty_i->seglist_lock);
895896

896-
if (holes[DATA] > ovp_holes || holes[NODE] > ovp_holes)
897+
unusable = holes[DATA] > holes[NODE] ? holes[DATA] : holes[NODE];
898+
if (unusable > ovp_holes)
899+
return unusable - ovp_holes;
900+
return 0;
901+
}
902+
903+
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable)
904+
{
905+
int ovp_hole_segs =
906+
(overprovision_segments(sbi) - reserved_segments(sbi));
907+
if (unusable > F2FS_OPTION(sbi).unusable_cap)
897908
return -EAGAIN;
898909
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK) &&
899910
dirty_segments(sbi) > ovp_hole_segs)

‎fs/f2fs/super.c‎

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ enum {
136136
Opt_alloc,
137137
Opt_fsync,
138138
Opt_test_dummy_encryption,
139-
Opt_checkpoint,
139+
Opt_checkpoint_disable,
140+
Opt_checkpoint_disable_cap,
141+
Opt_checkpoint_disable_cap_perc,
142+
Opt_checkpoint_enable,
140143
Opt_err,
141144
};
142145

@@ -195,7 +198,10 @@ static match_table_t f2fs_tokens = {
195198
{Opt_alloc, "alloc_mode=%s"},
196199
{Opt_fsync, "fsync_mode=%s"},
197200
{Opt_test_dummy_encryption, "test_dummy_encryption"},
198-
{Opt_checkpoint, "checkpoint=%s"},
201+
{Opt_checkpoint_disable, "checkpoint=disable"},
202+
{Opt_checkpoint_disable_cap, "checkpoint=disable:%u"},
203+
{Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
204+
{Opt_checkpoint_enable, "checkpoint=enable"},
199205
{Opt_err, NULL},
200206
};
201207

@@ -772,22 +778,30 @@ static int parse_options(struct super_block *sb, char *options)
772778
"Test dummy encryption mount option ignored");
773779
#endif
774780
break;
775-
case Opt_checkpoint:
776-
name = match_strdup(&args[0]);
777-
if (!name)
778-
return -ENOMEM;
779-
780-
if (strlen(name) == 6 &&
781-
!strncmp(name, "enable", 6)) {
782-
clear_opt(sbi, DISABLE_CHECKPOINT);
783-
} else if (strlen(name) == 7 &&
784-
!strncmp(name, "disable", 7)) {
785-
set_opt(sbi, DISABLE_CHECKPOINT);
786-
} else {
787-
kvfree(name);
781+
case Opt_checkpoint_disable_cap_perc:
782+
if (args->from && match_int(args, &arg))
788783
return -EINVAL;
789-
}
790-
kvfree(name);
784+
if (arg < 0 || arg > 100)
785+
return -EINVAL;
786+
if (arg == 100)
787+
F2FS_OPTION(sbi).unusable_cap =
788+
sbi->user_block_count;
789+
else
790+
F2FS_OPTION(sbi).unusable_cap =
791+
(sbi->user_block_count / 100) * arg;
792+
set_opt(sbi, DISABLE_CHECKPOINT);
793+
break;
794+
case Opt_checkpoint_disable_cap:
795+
if (args->from && match_int(args, &arg))
796+
return -EINVAL;
797+
F2FS_OPTION(sbi).unusable_cap = arg;
798+
set_opt(sbi, DISABLE_CHECKPOINT);
799+
break;
800+
case Opt_checkpoint_disable:
801+
set_opt(sbi, DISABLE_CHECKPOINT);
802+
break;
803+
case Opt_checkpoint_enable:
804+
clear_opt(sbi, DISABLE_CHECKPOINT);
791805
break;
792806
default:
793807
f2fs_msg(sb, KERN_ERR,
@@ -1412,8 +1426,8 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
14121426
seq_printf(seq, ",alloc_mode=%s", "reuse");
14131427

14141428
if (test_opt(sbi, DISABLE_CHECKPOINT))
1415-
seq_puts(seq, ",checkpoint=disable");
1416-
1429+
seq_printf(seq, ",checkpoint=disable:%u",
1430+
F2FS_OPTION(sbi).unusable_cap);
14171431
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
14181432
seq_printf(seq, ",fsync_mode=%s", "posix");
14191433
else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
@@ -1442,6 +1456,7 @@ static void default_options(struct f2fs_sb_info *sbi)
14421456
set_opt(sbi, EXTENT_CACHE);
14431457
set_opt(sbi, NOHEAP);
14441458
clear_opt(sbi, DISABLE_CHECKPOINT);
1459+
F2FS_OPTION(sbi).unusable_cap = 0;
14451460
sbi->sb->s_flags |= SB_LAZYTIME;
14461461
set_opt(sbi, FLUSH_MERGE);
14471462
set_opt(sbi, DISCARD);
@@ -1470,6 +1485,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
14701485
struct cp_control cpc;
14711486
int err = 0;
14721487
int ret;
1488+
block_t unusable;
14731489

14741490
if (s_flags & SB_RDONLY) {
14751491
f2fs_msg(sbi->sb, KERN_ERR,
@@ -1497,7 +1513,8 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
14971513
goto restore_flag;
14981514
}
14991515

1500-
if (f2fs_disable_cp_again(sbi)) {
1516+
unusable = f2fs_get_unusable_blocks(sbi);
1517+
if (f2fs_disable_cp_again(sbi, unusable)) {
15011518
err = -EAGAIN;
15021519
goto restore_flag;
15031520
}
@@ -1510,7 +1527,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
15101527
goto out_unlock;
15111528

15121529
spin_lock(&sbi->stat_lock);
1513-
sbi->unusable_block_count = 0;
1530+
sbi->unusable_block_count = unusable;
15141531
spin_unlock(&sbi->stat_lock);
15151532

15161533
out_unlock:

‎fs/f2fs/sysfs.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ static ssize_t dirty_segments_show(struct f2fs_attr *a,
6868
(unsigned long long)(dirty_segments(sbi)));
6969
}
7070

71+
static ssize_t unusable_show(struct f2fs_attr *a,
72+
struct f2fs_sb_info *sbi, char *buf)
73+
{
74+
block_t unusable;
75+
76+
if (test_opt(sbi, DISABLE_CHECKPOINT))
77+
unusable = sbi->unusable_block_count;
78+
else
79+
unusable = f2fs_get_unusable_blocks(sbi);
80+
return snprintf(buf, PAGE_SIZE, "%llu\n",
81+
(unsigned long long)unusable);
82+
}
83+
84+
7185
static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
7286
struct f2fs_sb_info *sbi, char *buf)
7387
{
@@ -440,6 +454,7 @@ F2FS_GENERAL_RO_ATTR(dirty_segments);
440454
F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
441455
F2FS_GENERAL_RO_ATTR(features);
442456
F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
457+
F2FS_GENERAL_RO_ATTR(unusable);
443458

444459
#ifdef CONFIG_FS_ENCRYPTION
445460
F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
@@ -495,6 +510,7 @@ static struct attribute *f2fs_attrs[] = {
495510
ATTR_LIST(inject_type),
496511
#endif
497512
ATTR_LIST(dirty_segments),
513+
ATTR_LIST(unusable),
498514
ATTR_LIST(lifetime_write_kbytes),
499515
ATTR_LIST(features),
500516
ATTR_LIST(reserved_blocks),

0 commit comments

Comments
 (0)