Skip to content

Commit f5a53ed

Browse files
author
Jaegeuk Kim
committed
f2fs: support aligned pinned file
This patch supports 2MB-aligned pinned file, which can guarantee no GC at all by allocating fully valid 2MB segment. Check free segments by has_not_enough_free_secs() with large budget. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent bc005a4 commit f5a53ed

7 files changed

Lines changed: 73 additions & 11 deletions

File tree

‎fs/f2fs/f2fs.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ enum {
890890
CURSEG_WARM_NODE, /* direct node blocks of normal files */
891891
CURSEG_COLD_NODE, /* indirect node blocks */
892892
NO_CHECK_TYPE,
893+
CURSEG_COLD_DATA_PINNED,/* cold data for pinned file */
893894
};
894895

895896
struct flush_cmd {
@@ -1301,6 +1302,7 @@ struct f2fs_sb_info {
13011302

13021303
/* threshold for gc trials on pinned files */
13031304
u64 gc_pin_file_threshold;
1305+
struct rw_semaphore pin_sem;
13041306

13051307
/* maximum # of trials to find a victim segment for SSR and GC */
13061308
unsigned int max_victim_search;
@@ -3116,7 +3118,7 @@ void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
31163118
int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
31173119
void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
31183120
unsigned int start, unsigned int end);
3119-
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
3121+
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type);
31203122
int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
31213123
bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
31223124
struct cp_control *cpc);

‎fs/f2fs/file.c‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,12 +1545,44 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
15451545
if (off_end)
15461546
map.m_len++;
15471547

1548-
if (f2fs_is_pinned_file(inode))
1549-
map.m_seg_type = CURSEG_COLD_DATA;
1548+
if (!map.m_len)
1549+
return 0;
1550+
1551+
if (f2fs_is_pinned_file(inode)) {
1552+
block_t len = (map.m_len >> sbi->log_blocks_per_seg) <<
1553+
sbi->log_blocks_per_seg;
1554+
block_t done = 0;
1555+
1556+
if (map.m_len % sbi->blocks_per_seg)
1557+
len += sbi->blocks_per_seg;
1558+
1559+
map.m_len = sbi->blocks_per_seg;
1560+
next_alloc:
1561+
if (has_not_enough_free_secs(sbi, 0,
1562+
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
1563+
mutex_lock(&sbi->gc_mutex);
1564+
err = f2fs_gc(sbi, true, false, NULL_SEGNO);
1565+
if (err && err != -ENODATA && err != -EAGAIN)
1566+
goto out_err;
1567+
}
15501568

1551-
err = f2fs_map_blocks(inode, &map, 1, (f2fs_is_pinned_file(inode) ?
1552-
F2FS_GET_BLOCK_PRE_DIO :
1553-
F2FS_GET_BLOCK_PRE_AIO));
1569+
down_write(&sbi->pin_sem);
1570+
map.m_seg_type = CURSEG_COLD_DATA_PINNED;
1571+
f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
1572+
err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
1573+
up_write(&sbi->pin_sem);
1574+
1575+
done += map.m_len;
1576+
len -= map.m_len;
1577+
map.m_lblk += map.m_len;
1578+
if (!err && len)
1579+
goto next_alloc;
1580+
1581+
map.m_len = done;
1582+
} else {
1583+
err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
1584+
}
1585+
out_err:
15541586
if (err) {
15551587
pgoff_t last_off;
15561588

‎fs/f2fs/recovery.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
711711
f2fs_put_page(page, 1);
712712
}
713713
if (!err)
714-
f2fs_allocate_new_segments(sbi);
714+
f2fs_allocate_new_segments(sbi, NO_CHECK_TYPE);
715715
return err;
716716
}
717717

‎fs/f2fs/segment.c‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
26902690
up_read(&SM_I(sbi)->curseg_lock);
26912691
}
26922692

2693-
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
2693+
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type)
26942694
{
26952695
struct curseg_info *curseg;
26962696
unsigned int old_segno;
@@ -2699,10 +2699,17 @@ void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
26992699
down_write(&SIT_I(sbi)->sentry_lock);
27002700

27012701
for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
2702+
if (type != NO_CHECK_TYPE && i != type)
2703+
continue;
2704+
27022705
curseg = CURSEG_I(sbi, i);
2703-
old_segno = curseg->segno;
2704-
SIT_I(sbi)->s_ops->allocate_segment(sbi, i, true);
2705-
locate_dirty_segment(sbi, old_segno);
2706+
if (type == NO_CHECK_TYPE || curseg->next_blkoff ||
2707+
get_valid_blocks(sbi, curseg->segno, false) ||
2708+
get_ckpt_valid_blocks(sbi, curseg->segno)) {
2709+
old_segno = curseg->segno;
2710+
SIT_I(sbi)->s_ops->allocate_segment(sbi, i, true);
2711+
locate_dirty_segment(sbi, old_segno);
2712+
}
27062713
}
27072714

27082715
up_write(&SIT_I(sbi)->sentry_lock);
@@ -3068,6 +3075,19 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
30683075
{
30693076
struct sit_info *sit_i = SIT_I(sbi);
30703077
struct curseg_info *curseg = CURSEG_I(sbi, type);
3078+
bool put_pin_sem = false;
3079+
3080+
if (type == CURSEG_COLD_DATA) {
3081+
/* GC during CURSEG_COLD_DATA_PINNED allocation */
3082+
if (down_read_trylock(&sbi->pin_sem)) {
3083+
put_pin_sem = true;
3084+
} else {
3085+
type = CURSEG_WARM_DATA;
3086+
curseg = CURSEG_I(sbi, type);
3087+
}
3088+
} else if (type == CURSEG_COLD_DATA_PINNED) {
3089+
type = CURSEG_COLD_DATA;
3090+
}
30713091

30723092
down_read(&SM_I(sbi)->curseg_lock);
30733093

@@ -3133,6 +3153,9 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
31333153
mutex_unlock(&curseg->curseg_mutex);
31343154

31353155
up_read(&SM_I(sbi)->curseg_lock);
3156+
3157+
if (put_pin_sem)
3158+
up_read(&sbi->pin_sem);
31363159
}
31373160

31383161
static void update_device_state(struct f2fs_io_info *fio)

‎fs/f2fs/segment.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ struct sit_entry_set {
313313
*/
314314
static inline struct curseg_info *CURSEG_I(struct f2fs_sb_info *sbi, int type)
315315
{
316+
if (type == CURSEG_COLD_DATA_PINNED)
317+
type = CURSEG_COLD_DATA;
316318
return (struct curseg_info *)(SM_I(sbi)->curseg_array + type);
317319
}
318320

‎fs/f2fs/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
28532853
spin_lock_init(&sbi->dev_lock);
28542854

28552855
init_rwsem(&sbi->sb_lock);
2856+
init_rwsem(&sbi->pin_sem);
28562857
}
28572858

28582859
static int init_percpu_info(struct f2fs_sb_info *sbi)

‎fs/f2fs/sysfs.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static ssize_t features_show(struct f2fs_attr *a,
154154
if (f2fs_sb_has_casefold(sbi))
155155
len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
156156
len ? ", " : "", "casefold");
157+
len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
158+
len ? ", " : "", "pin_file");
157159
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
158160
return len;
159161
}

0 commit comments

Comments
 (0)