Commit fb731430 authored by David Sterba's avatar David Sterba

btrfs: sysfs: show discard stats and tunables in non-debug build

When discard=async was introduced there were also sysfs knobs and stats
for debugging and tuning, hidden under CONFIG_BTRFS_DEBUG. The defaults
have been set and so far seem to satisfy all users on a range of
workloads. As there are not only tunables (like iops or kbps) but also
stats tracking amount of discardable bytes, that should be available
when the async discard is on (otherwise it's not).

The stats are moved from the per-fs debug directory, so it's under
  /sys/fs/btrfs/FSID/discard

- discard_bitmap_bytes - amount of discarded bytes from data tracked as
                         bitmaps
- discard_extent_bytes - dtto but as extents
- discard_bytes_saved -
- discardable_bytes - amount of bytes that can be discarded
- discardable_extents - number of extents to be discarded
- iops_limit - tunable limit of number of discard IOs to be issued
- kbps_limit - tunable limit of kilobytes per second issued as discard IO
- max_discard_size - tunable limit for size of one IO discard request
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 30b80f3c
...@@ -890,6 +890,7 @@ struct btrfs_fs_info { ...@@ -890,6 +890,7 @@ struct btrfs_fs_info {
struct kobject *space_info_kobj; struct kobject *space_info_kobj;
struct kobject *qgroups_kobj; struct kobject *qgroups_kobj;
struct kobject *discard_kobj;
/* used to keep from writing metadata until there is a nice batch */ /* used to keep from writing metadata until there is a nice batch */
struct percpu_counter dirty_metadata_bytes; struct percpu_counter dirty_metadata_bytes;
...@@ -1109,7 +1110,6 @@ struct btrfs_fs_info { ...@@ -1109,7 +1110,6 @@ struct btrfs_fs_info {
#ifdef CONFIG_BTRFS_DEBUG #ifdef CONFIG_BTRFS_DEBUG
struct kobject *debug_kobj; struct kobject *debug_kobj;
struct kobject *discard_debug_kobj;
struct list_head allocated_roots; struct list_head allocated_roots;
spinlock_t eb_leak_lock; spinlock_t eb_leak_lock;
......
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
* qgroup_attrs /sys/fs/btrfs/<uuid>/qgroups/<level>_<qgroupid> * qgroup_attrs /sys/fs/btrfs/<uuid>/qgroups/<level>_<qgroupid>
* space_info_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type> * space_info_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type>
* raid_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type>/<bg-profile> * raid_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type>/<bg-profile>
* discard_attrs /sys/fs/btrfs/<uuid>/discard
* *
* When built with BTRFS_CONFIG_DEBUG: * When built with BTRFS_CONFIG_DEBUG:
* *
* btrfs_debug_feature_attrs /sys/fs/btrfs/debug * btrfs_debug_feature_attrs /sys/fs/btrfs/debug
* btrfs_debug_mount_attrs /sys/fs/btrfs/<uuid>/debug * btrfs_debug_mount_attrs /sys/fs/btrfs/<uuid>/debug
* discard_debug_attrs /sys/fs/btrfs/<uuid>/debug/discard
*/ */
struct btrfs_feature_attr { struct btrfs_feature_attr {
...@@ -429,12 +429,10 @@ static const struct attribute_group btrfs_static_feature_attr_group = { ...@@ -429,12 +429,10 @@ static const struct attribute_group btrfs_static_feature_attr_group = {
.attrs = btrfs_supported_static_feature_attrs, .attrs = btrfs_supported_static_feature_attrs,
}; };
#ifdef CONFIG_BTRFS_DEBUG
/* /*
* Discard statistics and tunables * Discard statistics and tunables
*/ */
#define discard_to_fs_info(_kobj) to_fs_info((_kobj)->parent->parent) #define discard_to_fs_info(_kobj) to_fs_info(get_btrfs_kobj(_kobj))
static ssize_t btrfs_discardable_bytes_show(struct kobject *kobj, static ssize_t btrfs_discardable_bytes_show(struct kobject *kobj,
struct kobj_attribute *a, struct kobj_attribute *a,
...@@ -583,11 +581,11 @@ BTRFS_ATTR_RW(discard, max_discard_size, btrfs_discard_max_discard_size_show, ...@@ -583,11 +581,11 @@ BTRFS_ATTR_RW(discard, max_discard_size, btrfs_discard_max_discard_size_show,
btrfs_discard_max_discard_size_store); btrfs_discard_max_discard_size_store);
/* /*
* Per-filesystem debugging of discard (when mounted with discard=async). * Per-filesystem stats for discard (when mounted with discard=async).
* *
* Path: /sys/fs/btrfs/<uuid>/debug/discard/ * Path: /sys/fs/btrfs/<uuid>/discard/
*/ */
static const struct attribute *discard_debug_attrs[] = { static const struct attribute *discard_attrs[] = {
BTRFS_ATTR_PTR(discard, discardable_bytes), BTRFS_ATTR_PTR(discard, discardable_bytes),
BTRFS_ATTR_PTR(discard, discardable_extents), BTRFS_ATTR_PTR(discard, discardable_extents),
BTRFS_ATTR_PTR(discard, discard_bitmap_bytes), BTRFS_ATTR_PTR(discard, discard_bitmap_bytes),
...@@ -599,6 +597,8 @@ static const struct attribute *discard_debug_attrs[] = { ...@@ -599,6 +597,8 @@ static const struct attribute *discard_debug_attrs[] = {
NULL, NULL,
}; };
#ifdef CONFIG_BTRFS_DEBUG
/* /*
* Per-filesystem runtime debugging exported via sysfs. * Per-filesystem runtime debugging exported via sysfs.
* *
...@@ -1408,13 +1408,12 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) ...@@ -1408,13 +1408,12 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
kobject_del(fs_info->space_info_kobj); kobject_del(fs_info->space_info_kobj);
kobject_put(fs_info->space_info_kobj); kobject_put(fs_info->space_info_kobj);
} }
#ifdef CONFIG_BTRFS_DEBUG if (fs_info->discard_kobj) {
if (fs_info->discard_debug_kobj) { sysfs_remove_files(fs_info->discard_kobj, discard_attrs);
sysfs_remove_files(fs_info->discard_debug_kobj, kobject_del(fs_info->discard_kobj);
discard_debug_attrs); kobject_put(fs_info->discard_kobj);
kobject_del(fs_info->discard_debug_kobj);
kobject_put(fs_info->discard_debug_kobj);
} }
#ifdef CONFIG_BTRFS_DEBUG
if (fs_info->debug_kobj) { if (fs_info->debug_kobj) {
sysfs_remove_files(fs_info->debug_kobj, btrfs_debug_mount_attrs); sysfs_remove_files(fs_info->debug_kobj, btrfs_debug_mount_attrs);
kobject_del(fs_info->debug_kobj); kobject_del(fs_info->debug_kobj);
...@@ -1982,20 +1981,18 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info) ...@@ -1982,20 +1981,18 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
error = sysfs_create_files(fs_info->debug_kobj, btrfs_debug_mount_attrs); error = sysfs_create_files(fs_info->debug_kobj, btrfs_debug_mount_attrs);
if (error) if (error)
goto failure; goto failure;
#endif
/* Discard directory */ /* Discard directory */
fs_info->discard_debug_kobj = kobject_create_and_add("discard", fs_info->discard_kobj = kobject_create_and_add("discard", fsid_kobj);
fs_info->debug_kobj); if (!fs_info->discard_kobj) {
if (!fs_info->discard_debug_kobj) {
error = -ENOMEM; error = -ENOMEM;
goto failure; goto failure;
} }
error = sysfs_create_files(fs_info->discard_debug_kobj, error = sysfs_create_files(fs_info->discard_kobj, discard_attrs);
discard_debug_attrs);
if (error) if (error)
goto failure; goto failure;
#endif
error = addrm_unknown_feature_attrs(fs_info, true); error = addrm_unknown_feature_attrs(fs_info, true);
if (error) if (error)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment