Skip to content

Commit 7fe92f8

Browse files
kdaveintel-lab-lkp
authored andcommitted
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 Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7cd10df commit 7fe92f8

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ struct btrfs_fs_info {
891891

892892
struct kobject *space_info_kobj;
893893
struct kobject *qgroups_kobj;
894+
struct kobject *discard_kobj;
894895

895896
/* used to keep from writing metadata until there is a nice batch */
896897
struct percpu_counter dirty_metadata_bytes;
@@ -1108,7 +1109,6 @@ struct btrfs_fs_info {
11081109

11091110
#ifdef CONFIG_BTRFS_DEBUG
11101111
struct kobject *debug_kobj;
1111-
struct kobject *discard_debug_kobj;
11121112
struct list_head allocated_roots;
11131113

11141114
spinlock_t eb_leak_lock;

fs/btrfs/sysfs.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
* qgroup_attrs /sys/fs/btrfs/<uuid>/qgroups/<level>_<qgroupid>
3636
* space_info_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type>
3737
* raid_attrs /sys/fs/btrfs/<uuid>/allocation/<bg-type>/<bg-profile>
38+
* discard_attrs /sys/fs/btrfs/<uuid>/discard
3839
*
3940
* When built with BTRFS_CONFIG_DEBUG:
4041
*
4142
* btrfs_debug_feature_attrs /sys/fs/btrfs/debug
4243
* btrfs_debug_mount_attrs /sys/fs/btrfs/<uuid>/debug
43-
* discard_debug_attrs /sys/fs/btrfs/<uuid>/debug/discard
4444
*/
4545

4646
struct btrfs_feature_attr {
@@ -429,12 +429,10 @@ static const struct attribute_group btrfs_static_feature_attr_group = {
429429
.attrs = btrfs_supported_static_feature_attrs,
430430
};
431431

432-
#ifdef CONFIG_BTRFS_DEBUG
433-
434432
/*
435433
* Discard statistics and tunables
436434
*/
437-
#define discard_to_fs_info(_kobj) to_fs_info((_kobj)->parent->parent)
435+
#define discard_to_fs_info(_kobj) to_fs_info(get_btrfs_kobj(_kobj))
438436

439437
static ssize_t btrfs_discardable_bytes_show(struct kobject *kobj,
440438
struct kobj_attribute *a,
@@ -583,11 +581,11 @@ BTRFS_ATTR_RW(discard, max_discard_size, btrfs_discard_max_discard_size_show,
583581
btrfs_discard_max_discard_size_store);
584582

585583
/*
586-
* Per-filesystem debugging of discard (when mounted with discard=async).
584+
* Per-filesystem stats for discard (when mounted with discard=async).
587585
*
588-
* Path: /sys/fs/btrfs/<uuid>/debug/discard/
586+
* Path: /sys/fs/btrfs/<uuid>/discard/
589587
*/
590-
static const struct attribute *discard_debug_attrs[] = {
588+
static const struct attribute *discard_attrs[] = {
591589
BTRFS_ATTR_PTR(discard, discardable_bytes),
592590
BTRFS_ATTR_PTR(discard, discardable_extents),
593591
BTRFS_ATTR_PTR(discard, discard_bitmap_bytes),
@@ -599,6 +597,8 @@ static const struct attribute *discard_debug_attrs[] = {
599597
NULL,
600598
};
601599

600+
#ifdef CONFIG_BTRFS_DEBUG
601+
602602
/*
603603
* Per-filesystem runtime debugging exported via sysfs.
604604
*
@@ -1427,19 +1427,17 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
14271427
kobject_del(fs_info->space_info_kobj);
14281428
kobject_put(fs_info->space_info_kobj);
14291429
}
1430-
#ifdef CONFIG_BTRFS_DEBUG
1431-
if (fs_info->discard_debug_kobj) {
1432-
sysfs_remove_files(fs_info->discard_debug_kobj,
1433-
discard_debug_attrs);
1434-
kobject_del(fs_info->discard_debug_kobj);
1435-
kobject_put(fs_info->discard_debug_kobj);
1430+
if (fs_info->discard_kobj) {
1431+
sysfs_remove_files(fs_info->discard_kobj, discard_attrs);
1432+
kobject_del(fs_info->discard_kobj);
1433+
kobject_put(fs_info->discard_kobj);
14361434
}
14371435
if (fs_info->debug_kobj) {
14381436
sysfs_remove_files(fs_info->debug_kobj, btrfs_debug_mount_attrs);
14391437
kobject_del(fs_info->debug_kobj);
14401438
kobject_put(fs_info->debug_kobj);
14411439
}
1442-
#endif
1440+
14431441
addrm_unknown_feature_attrs(fs_info, false);
14441442
sysfs_remove_group(fsid_kobj, &btrfs_feature_attr_group);
14451443
sysfs_remove_files(fsid_kobj, btrfs_attrs);
@@ -2001,20 +1999,18 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
20011999
error = sysfs_create_files(fs_info->debug_kobj, btrfs_debug_mount_attrs);
20022000
if (error)
20032001
goto failure;
2002+
#endif
20042003

20052004
/* Discard directory */
2006-
fs_info->discard_debug_kobj = kobject_create_and_add("discard",
2007-
fs_info->debug_kobj);
2008-
if (!fs_info->discard_debug_kobj) {
2005+
fs_info->discard_kobj = kobject_create_and_add("discard", fsid_kobj);
2006+
if (!fs_info->discard_kobj) {
20092007
error = -ENOMEM;
20102008
goto failure;
20112009
}
20122010

2013-
error = sysfs_create_files(fs_info->discard_debug_kobj,
2014-
discard_debug_attrs);
2011+
error = sysfs_create_files(fs_info->discard_kobj, discard_attrs);
20152012
if (error)
20162013
goto failure;
2017-
#endif
20182014

20192015
error = addrm_unknown_feature_attrs(fs_info, true);
20202016
if (error)

0 commit comments

Comments
 (0)