btrfs: add tracepoints for extent map shrinker events

Add some tracepoints for the extent map shrinker to help debug and analyse
main events. These have proved useful during development of the shrinker.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana 2024-04-09 17:07:32 +01:00 committed by David Sterba
parent 65bb9fb00b
commit 0d89a15e1a
3 changed files with 116 additions and 1 deletions

View file

@ -1080,6 +1080,7 @@ static long btrfs_scan_inode(struct btrfs_inode *inode, long *scanned, long nr_t
btrfs_set_inode_full_sync(inode);
remove_extent_mapping(inode, em);
trace_btrfs_extent_map_shrinker_remove_em(inode, em);
/* Drop the reference for the tree. */
free_extent_map(em);
nr_dropped++;
@ -1152,6 +1153,12 @@ long btrfs_free_extent_maps(struct btrfs_fs_info *fs_info, long nr_to_scan)
long nr_dropped = 0;
long scanned = 0;
if (trace_btrfs_extent_map_shrinker_scan_enter_enabled()) {
s64 nr = percpu_counter_sum_positive(&fs_info->evictable_extent_maps);
trace_btrfs_extent_map_shrinker_scan_enter(fs_info, nr_to_scan, nr);
}
while (scanned < nr_to_scan) {
struct btrfs_root *root;
unsigned long count;
@ -1184,5 +1191,11 @@ long btrfs_free_extent_maps(struct btrfs_fs_info *fs_info, long nr_to_scan)
btrfs_put_root(root);
}
if (trace_btrfs_extent_map_shrinker_scan_exit_enabled()) {
s64 nr = percpu_counter_sum_positive(&fs_info->evictable_extent_maps);
trace_btrfs_extent_map_shrinker_scan_exit(fs_info, nr_dropped, nr);
}
return nr_dropped;
}

View file

@ -2374,8 +2374,11 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
static long btrfs_nr_cached_objects(struct super_block *sb, struct shrink_control *sc)
{
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
const s64 nr = percpu_counter_sum_positive(&fs_info->evictable_extent_maps);
return percpu_counter_sum_positive(&fs_info->evictable_extent_maps);
trace_btrfs_extent_map_shrinker_count(fs_info, nr);
return nr;
}
static long btrfs_free_cached_objects(struct super_block *sb, struct shrink_control *sc)

View file

@ -2537,6 +2537,105 @@ TRACE_EVENT(btrfs_get_raid_extent_offset,
__entry->devid)
);
TRACE_EVENT(btrfs_extent_map_shrinker_count,
TP_PROTO(const struct btrfs_fs_info *fs_info, long nr),
TP_ARGS(fs_info, nr),
TP_STRUCT__entry_btrfs(
__field( long, nr )
),
TP_fast_assign_btrfs(fs_info,
__entry->nr = nr;
),
TP_printk_btrfs("nr=%ld", __entry->nr)
);
TRACE_EVENT(btrfs_extent_map_shrinker_scan_enter,
TP_PROTO(const struct btrfs_fs_info *fs_info, long nr_to_scan, long nr),
TP_ARGS(fs_info, nr_to_scan, nr),
TP_STRUCT__entry_btrfs(
__field( long, nr_to_scan )
__field( long, nr )
__field( u64, last_root_id )
__field( u64, last_ino )
),
TP_fast_assign_btrfs(fs_info,
__entry->nr_to_scan = nr_to_scan;
__entry->nr = nr;
__entry->last_root_id = fs_info->extent_map_shrinker_last_root;
__entry->last_ino = fs_info->extent_map_shrinker_last_ino;
),
TP_printk_btrfs("nr_to_scan=%ld nr=%ld last_root=%llu(%s) last_ino=%llu",
__entry->nr_to_scan, __entry->nr,
show_root_type(__entry->last_root_id), __entry->last_ino)
);
TRACE_EVENT(btrfs_extent_map_shrinker_scan_exit,
TP_PROTO(const struct btrfs_fs_info *fs_info, long nr_dropped, long nr),
TP_ARGS(fs_info, nr_dropped, nr),
TP_STRUCT__entry_btrfs(
__field( long, nr_dropped )
__field( long, nr )
__field( u64, last_root_id )
__field( u64, last_ino )
),
TP_fast_assign_btrfs(fs_info,
__entry->nr_dropped = nr_dropped;
__entry->nr = nr;
__entry->last_root_id = fs_info->extent_map_shrinker_last_root;
__entry->last_ino = fs_info->extent_map_shrinker_last_ino;
),
TP_printk_btrfs("nr_dropped=%ld nr=%ld last_root=%llu(%s) last_ino=%llu",
__entry->nr_dropped, __entry->nr,
show_root_type(__entry->last_root_id), __entry->last_ino)
);
TRACE_EVENT(btrfs_extent_map_shrinker_remove_em,
TP_PROTO(const struct btrfs_inode *inode, const struct extent_map *em),
TP_ARGS(inode, em),
TP_STRUCT__entry_btrfs(
__field( u64, ino )
__field( u64, root_id )
__field( u64, start )
__field( u64, len )
__field( u64, block_start )
__field( u32, flags )
),
TP_fast_assign_btrfs(inode->root->fs_info,
__entry->ino = btrfs_ino(inode);
__entry->root_id = inode->root->root_key.objectid;
__entry->start = em->start;
__entry->len = em->len;
__entry->block_start = em->block_start;
__entry->flags = em->flags;
),
TP_printk_btrfs(
"ino=%llu root=%llu(%s) start=%llu len=%llu block_start=%llu(%s) flags=%s",
__entry->ino, show_root_type(__entry->root_id),
__entry->start, __entry->len,
show_map_type(__entry->block_start),
show_map_flags(__entry->flags))
);
#endif /* _TRACE_BTRFS_H */
/* This part must be outside protection */