Skip to content

Commit 77f4135

Browse files
Vivek Haldartytso
authored andcommitted
ext4: count hits/misses of extent cache and expose in sysfs
The number of hits and misses for each filesystem is exposed in /sys/fs/ext4/<dev>/extent_cache_{hits, misses}. Tested: fsstress, manual checks. Signed-off-by: Vivek Haldar <haldar@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 9391741 commit 77f4135

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎fs/ext4/ext4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@ struct ext4_sb_info {
11441144
unsigned long s_ext_blocks;
11451145
unsigned long s_ext_extents;
11461146
#endif
1147+
/* ext4 extent cache stats */
1148+
unsigned long extent_cache_hits;
1149+
unsigned long extent_cache_misses;
11471150

11481151
/* for buddy allocator */
11491152
struct ext4_group_info ***s_group_info;

‎fs/ext4/extents.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,13 +2035,15 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
20352035
struct ext4_extent *ex)
20362036
{
20372037
struct ext4_ext_cache *cex;
2038+
struct ext4_sb_info *sbi;
20382039
int ret = 0;
20392040

20402041
/*
20412042
* We borrow i_block_reservation_lock to protect i_cached_extent
20422043
*/
20432044
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
20442045
cex = &EXT4_I(inode)->i_cached_extent;
2046+
sbi = EXT4_SB(inode->i_sb);
20452047

20462048
/* has cache valid data? */
20472049
if (cex->ec_len == 0)
@@ -2057,6 +2059,10 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
20572059
ret = 1;
20582060
}
20592061
errout:
2062+
if (!ret)
2063+
sbi->extent_cache_misses++;
2064+
else
2065+
sbi->extent_cache_hits++;
20602066
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
20612067
return ret;
20622068
}
@@ -3901,4 +3907,3 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
39013907

39023908
return error;
39033909
}
3904-

‎fs/ext4/super.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,18 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
24392439
EXT4_SB(sb)->s_sectors_written_start) >> 1)));
24402440
}
24412441

2442+
static ssize_t extent_cache_hits_show(struct ext4_attr *a,
2443+
struct ext4_sb_info *sbi, char *buf)
2444+
{
2445+
return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_hits);
2446+
}
2447+
2448+
static ssize_t extent_cache_misses_show(struct ext4_attr *a,
2449+
struct ext4_sb_info *sbi, char *buf)
2450+
{
2451+
return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_misses);
2452+
}
2453+
24422454
static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
24432455
struct ext4_sb_info *sbi,
24442456
const char *buf, size_t count)
@@ -2496,6 +2508,8 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
24962508
EXT4_RO_ATTR(delayed_allocation_blocks);
24972509
EXT4_RO_ATTR(session_write_kbytes);
24982510
EXT4_RO_ATTR(lifetime_write_kbytes);
2511+
EXT4_RO_ATTR(extent_cache_hits);
2512+
EXT4_RO_ATTR(extent_cache_misses);
24992513
EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
25002514
inode_readahead_blks_store, s_inode_readahead_blks);
25012515
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
@@ -2511,6 +2525,8 @@ static struct attribute *ext4_attrs[] = {
25112525
ATTR_LIST(delayed_allocation_blocks),
25122526
ATTR_LIST(session_write_kbytes),
25132527
ATTR_LIST(lifetime_write_kbytes),
2528+
ATTR_LIST(extent_cache_hits),
2529+
ATTR_LIST(extent_cache_misses),
25142530
ATTR_LIST(inode_readahead_blks),
25152531
ATTR_LIST(inode_goal),
25162532
ATTR_LIST(mb_stats),

0 commit comments

Comments
 (0)