Skip to content

Commit e7547da

Browse files
author
Jaegeuk Kim
committed
f2fs: refactor extent_cache to support for read and more
This patch prepares extent_cache to be ready for addition. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 749d543 commit e7547da

File tree

11 files changed

+470
-307
lines changed

11 files changed

+470
-307
lines changed

fs/f2fs/data.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
11261126
{
11271127
dn->data_blkaddr = blkaddr;
11281128
f2fs_set_data_blkaddr(dn);
1129-
f2fs_update_extent_cache(dn);
1129+
f2fs_update_read_extent_cache(dn);
11301130
}
11311131

11321132
/* dn->ofs_in_node will be returned with up-to-date last block pointer */
@@ -1195,7 +1195,7 @@ int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
11951195
struct extent_info ei = {0, };
11961196
struct inode *inode = dn->inode;
11971197

1198-
if (f2fs_lookup_extent_cache(inode, index, &ei)) {
1198+
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
11991199
dn->data_blkaddr = ei.blk + index - ei.fofs;
12001200
return 0;
12011201
}
@@ -1217,7 +1217,7 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
12171217
if (!page)
12181218
return ERR_PTR(-ENOMEM);
12191219

1220-
if (f2fs_lookup_extent_cache(inode, index, &ei)) {
1220+
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
12211221
dn.data_blkaddr = ei.blk + index - ei.fofs;
12221222
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
12231223
DATA_GENERIC_ENHANCE_READ)) {
@@ -1485,7 +1485,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
14851485
pgofs = (pgoff_t)map->m_lblk;
14861486
end = pgofs + maxblocks;
14871487

1488-
if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
1488+
if (!create && f2fs_lookup_read_extent_cache(inode, pgofs, &ei)) {
14891489
if (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO &&
14901490
map->m_may_create)
14911491
goto next_dnode;
@@ -1695,7 +1695,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
16951695
if (map->m_flags & F2FS_MAP_MAPPED) {
16961696
unsigned int ofs = start_pgofs - map->m_lblk;
16971697

1698-
f2fs_update_extent_cache_range(&dn,
1698+
f2fs_update_read_extent_cache_range(&dn,
16991699
start_pgofs, map->m_pblk + ofs,
17001700
map->m_len - ofs);
17011701
}
@@ -1740,7 +1740,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
17401740
if (map->m_flags & F2FS_MAP_MAPPED) {
17411741
unsigned int ofs = start_pgofs - map->m_lblk;
17421742

1743-
f2fs_update_extent_cache_range(&dn,
1743+
f2fs_update_read_extent_cache_range(&dn,
17441744
start_pgofs, map->m_pblk + ofs,
17451745
map->m_len - ofs);
17461746
}
@@ -2201,7 +2201,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
22012201
if (f2fs_cluster_is_empty(cc))
22022202
goto out;
22032203

2204-
if (f2fs_lookup_extent_cache(inode, start_idx, &ei))
2204+
if (f2fs_lookup_read_extent_cache(inode, start_idx, &ei))
22052205
from_dnode = false;
22062206

22072207
if (!from_dnode)
@@ -2635,7 +2635,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
26352635
set_new_dnode(&dn, inode, NULL, NULL, 0);
26362636

26372637
if (need_inplace_update(fio) &&
2638-
f2fs_lookup_extent_cache(inode, page->index, &ei)) {
2638+
f2fs_lookup_read_extent_cache(inode, page->index, &ei)) {
26392639
fio->old_blkaddr = ei.blk + page->index - ei.fofs;
26402640

26412641
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
@@ -3359,7 +3359,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
33593359
} else if (locked) {
33603360
err = f2fs_get_block(&dn, index);
33613361
} else {
3362-
if (f2fs_lookup_extent_cache(inode, index, &ei)) {
3362+
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
33633363
dn.data_blkaddr = ei.blk + index - ei.fofs;
33643364
} else {
33653365
/* hole case */
@@ -3400,7 +3400,7 @@ static int __find_data_block(struct inode *inode, pgoff_t index,
34003400

34013401
set_new_dnode(&dn, inode, ipage, ipage, 0);
34023402

3403-
if (f2fs_lookup_extent_cache(inode, index, &ei)) {
3403+
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
34043404
dn.data_blkaddr = ei.blk + index - ei.fofs;
34053405
} else {
34063406
/* hole case */

fs/f2fs/debug.c

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ static void update_general_status(struct f2fs_sb_info *sbi)
7272
si->main_area_zones = si->main_area_sections /
7373
le32_to_cpu(raw_super->secs_per_zone);
7474

75-
/* validation check of the segment numbers */
75+
/* general extent cache stats */
76+
for (i = 0; i < NR_EXTENT_CACHES; i++) {
77+
struct extent_tree_info *eti = &sbi->extent_tree[i];
78+
79+
si->hit_cached[i] = atomic64_read(&sbi->read_hit_cached[i]);
80+
si->hit_rbtree[i] = atomic64_read(&sbi->read_hit_rbtree[i]);
81+
si->total_ext[i] = atomic64_read(&sbi->total_hit_ext[i]);
82+
si->hit_total[i] = si->hit_cached[i] + si->hit_rbtree[i];
83+
si->ext_tree[i] = atomic_read(&eti->total_ext_tree);
84+
si->zombie_tree[i] = atomic_read(&eti->total_zombie_tree);
85+
si->ext_node[i] = atomic_read(&eti->total_ext_node);
86+
}
87+
/* read extent_cache only */
7688
si->hit_largest = atomic64_read(&sbi->read_hit_largest);
77-
si->hit_cached = atomic64_read(&sbi->read_hit_cached);
78-
si->hit_rbtree = atomic64_read(&sbi->read_hit_rbtree);
79-
si->hit_total = si->hit_largest + si->hit_cached + si->hit_rbtree;
80-
si->total_ext = atomic64_read(&sbi->total_hit_ext);
81-
si->ext_tree = atomic_read(&sbi->total_ext_tree);
82-
si->zombie_tree = atomic_read(&sbi->total_zombie_tree);
83-
si->ext_node = atomic_read(&sbi->total_ext_node);
89+
si->hit_total[EX_READ] += si->hit_largest;
90+
91+
/* validation check of the segment numbers */
8492
si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
8593
si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS);
8694
si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META);
@@ -294,10 +302,16 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
294302
sizeof(struct nat_entry_set);
295303
for (i = 0; i < MAX_INO_ENTRY; i++)
296304
si->cache_mem += sbi->im[i].ino_num * sizeof(struct ino_entry);
297-
si->cache_mem += atomic_read(&sbi->total_ext_tree) *
305+
306+
for (i = 0; i < NR_EXTENT_CACHES; i++) {
307+
struct extent_tree_info *eti = &sbi->extent_tree[i];
308+
309+
si->ext_mem[i] = atomic_read(&eti->total_ext_tree) *
298310
sizeof(struct extent_tree);
299-
si->cache_mem += atomic_read(&sbi->total_ext_node) *
311+
si->ext_mem[i] += atomic_read(&eti->total_ext_node) *
300312
sizeof(struct extent_node);
313+
si->cache_mem += si->ext_mem[i];
314+
}
301315

302316
si->page_mem = 0;
303317
if (sbi->node_inode) {
@@ -490,16 +504,18 @@ static int stat_show(struct seq_file *s, void *v)
490504
si->bg_node_blks);
491505
seq_printf(s, "BG skip : IO: %u, Other: %u\n",
492506
si->io_skip_bggc, si->other_skip_bggc);
493-
seq_puts(s, "\nExtent Cache:\n");
507+
seq_puts(s, "\nExtent Cache (Read):\n");
494508
seq_printf(s, " - Hit Count: L1-1:%llu L1-2:%llu L2:%llu\n",
495-
si->hit_largest, si->hit_cached,
496-
si->hit_rbtree);
509+
si->hit_largest, si->hit_cached[EX_READ],
510+
si->hit_rbtree[EX_READ]);
497511
seq_printf(s, " - Hit Ratio: %llu%% (%llu / %llu)\n",
498-
!si->total_ext ? 0 :
499-
div64_u64(si->hit_total * 100, si->total_ext),
500-
si->hit_total, si->total_ext);
512+
!si->total_ext[EX_READ] ? 0 :
513+
div64_u64(si->hit_total[EX_READ] * 100,
514+
si->total_ext[EX_READ]),
515+
si->hit_total[EX_READ], si->total_ext[EX_READ]);
501516
seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n",
502-
si->ext_tree, si->zombie_tree, si->ext_node);
517+
si->ext_tree[EX_READ], si->zombie_tree[EX_READ],
518+
si->ext_node[EX_READ]);
503519
seq_puts(s, "\nBalancing F2FS Async:\n");
504520
seq_printf(s, " - DIO (R: %4d, W: %4d)\n",
505521
si->nr_dio_read, si->nr_dio_write);
@@ -566,8 +582,10 @@ static int stat_show(struct seq_file *s, void *v)
566582
(si->base_mem + si->cache_mem + si->page_mem) >> 10);
567583
seq_printf(s, " - static: %llu KB\n",
568584
si->base_mem >> 10);
569-
seq_printf(s, " - cached: %llu KB\n",
585+
seq_printf(s, " - cached all: %llu KB\n",
570586
si->cache_mem >> 10);
587+
seq_printf(s, " - read extent cache: %llu KB\n",
588+
si->ext_mem[EX_READ] >> 10);
571589
seq_printf(s, " - paged : %llu KB\n",
572590
si->page_mem >> 10);
573591
}
@@ -600,10 +618,15 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)
600618
si->sbi = sbi;
601619
sbi->stat_info = si;
602620

603-
atomic64_set(&sbi->total_hit_ext, 0);
604-
atomic64_set(&sbi->read_hit_rbtree, 0);
621+
/* general extent cache stats */
622+
for (i = 0; i < NR_EXTENT_CACHES; i++) {
623+
atomic64_set(&sbi->total_hit_ext[i], 0);
624+
atomic64_set(&sbi->read_hit_rbtree[i], 0);
625+
atomic64_set(&sbi->read_hit_cached[i], 0);
626+
}
627+
628+
/* read extent_cache only */
605629
atomic64_set(&sbi->read_hit_largest, 0);
606-
atomic64_set(&sbi->read_hit_cached, 0);
607630

608631
atomic_set(&sbi->inline_xattr, 0);
609632
atomic_set(&sbi->inline_inode, 0);

0 commit comments

Comments
 (0)