Re: [dm-devel] [PATCH 08/27] btrfs: use bdev_max_active_zones instead of open coding it

2022-04-19 Thread Anand Jain

On 4/15/22 12:52, Christoph Hellwig wrote:

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
Acked-by: David Sterba 


LGTM.

Reviewed-by: Anand Jain 



---
  fs/btrfs/zoned.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 1b1b310c3c510..f72cad7391a11 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -350,7 +350,6 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, 
bool populate_cache)
struct btrfs_fs_info *fs_info = device->fs_info;
struct btrfs_zoned_device_info *zone_info = NULL;
struct block_device *bdev = device->bdev;
-   struct request_queue *queue = bdev_get_queue(bdev);
unsigned int max_active_zones;
unsigned int nactive;
sector_t nr_sectors;
@@ -410,7 +409,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, 
bool populate_cache)
if (!IS_ALIGNED(nr_sectors, zone_sectors))
zone_info->nr_zones++;
  
-	max_active_zones = queue_max_active_zones(queue);

+   max_active_zones = bdev_max_active_zones(bdev);
if (max_active_zones && max_active_zones < BTRFS_MIN_ACTIVE_ZONES) {
btrfs_err_in_rcu(fs_info,
  "zoned: %s: max active zones %u is too small, need at least %u active zones",


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH RFC] btrfs: sysfs: add /debug/io_accounting/ directory

2022-01-21 Thread Anand Jain

On 21/01/2022 13:24, Qu Wenruo wrote:

[BACKGROUND]
There is a series of btrfs autodefrag bugs in v5.16, that would cause
way more IO than previous kernels.

Unfortunately there isn't any test case covering autodefrag, nor there
is anyway to show the io accounting of a btrfs.

[WORKAROUND]
I originally want to implement a dm target to do the io accounting for
all filesystems, but can not find a good enough interface (the status
interface has only 3 pre-defined workload).

Thus I turned to btrfs specific io accounting first.
One thing specific to btrfs is its integrated volume management/RAID.

Without proper profiles specification, default profile will cause
metadata IO to be accounted twice (DUP profile) and only data IO is
accounted correctly.

So for btrfs this patch will introduce a new sysfs directory in
/sys/fs/btrfs//debug/io_accounting/

And have the following files:

- meta_read:Metadata bytes read
- meta_write:   Metadata bytes written
- data_read:Data bytes read
- data_write:   Data bytes written
(including both zoned append and regular write)

And all these accounting is in logical address space, meaning profile
will not affect the values.

All those values can be reset by simply "echo 0".

Signed-off-by: Qu Wenruo 
---
Reason for RFC:

- (To DM guys) Is there any good way to implement a dm target to do the IO
   accounting?
   A more generic one can help more filesystems.

- (To Btrfs guys) Is the sysfs interface fine?


 I am in for it. It can be a non debug feature IMO.
 More below.


---
  fs/btrfs/ctree.h   | 11 +++
  fs/btrfs/disk-io.c |  1 +
  fs/btrfs/sysfs.c   | 77 ++
  fs/btrfs/volumes.c | 24 +++
  4 files changed, 113 insertions(+)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b4a9b1c58d22..3983bceaef7f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1035,10 +1035,21 @@ struct btrfs_fs_info {
  #ifdef CONFIG_BTRFS_DEBUG
struct kobject *debug_kobj;
struct kobject *discard_debug_kobj;
+   struct kobject *io_accounting_debug_kobj;
struct list_head allocated_roots;
  
  	spinlock_t eb_leak_lock;

struct list_head allocated_ebs;
+
+   spinlock_t io_accounting_lock;
+   /*
+* The IO accounting unit are all in byte, and are in logical address
+* space, which is before the RAID/DUP mapping.
+*/
+   u64 meta_read;
+   u64 meta_write;
+   u64 data_read;
+   u64 data_write;
  #endif
  };
  
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c

index 87a5addbedf6..41b56fde6e97 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3065,6 +3065,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->allocated_roots);
INIT_LIST_HEAD(&fs_info->allocated_ebs);
spin_lock_init(&fs_info->eb_leak_lock);
+   spin_lock_init(&fs_info->io_accounting_lock);
  #endif
extent_map_tree_init(&fs_info->mapping_tree);
btrfs_init_block_rsv(&fs_info->global_block_rsv,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index beb7f72d50b8..dfdef93bdeab 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -40,6 +40,7 @@
   * btrfs_debug_feature_attrs  /sys/fs/btrfs/debug
   * btrfs_debug_mount_attrs/sys/fs/btrfs//debug
   * discard_debug_attrs
/sys/fs/btrfs//debug/discard
+ * io_accounting_debug_attrs   /sys/fs/btrfs//debug/io_accounting
   */
  
  struct btrfs_feature_attr {

@@ -616,6 +617,62 @@ static const struct attribute_group 
btrfs_debug_feature_attr_group = {
.attrs = btrfs_debug_feature_attrs,
  };
  
+/* IO accounting */

+#define io_accounting_to_fs_info(_kobj)
to_fs_info((_kobj)->parent->parent)
+
+#define DECLARE_IO_ACCOUNTING_OPS(name)
\
+static ssize_t io_accounting_##name##_show(struct kobject *kobj,   \
+  struct kobj_attribute *a,\
+  char *buf)   \
+{  \
+   struct btrfs_fs_info *fs_info = io_accounting_to_fs_info(kobj); \
+   u64 result; \
+   \
+   spin_lock(&fs_info->io_accounting_lock); \
+   result = fs_info->name;  \
+   spin_unlock(&fs_info->io_accounting_lock);   \
+   return sysfs_emit(buf, "%llu\n", result); \
+}  \
+static ssize_t io_accounting_##name##_store(struct kobject *kobj,  \
+   struct kobj_attribute *a,   \
+   const char *buf,\
+

Re: [dm-devel] [PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it

2021-10-13 Thread Anand Jain

On 13/10/2021 13:10, Christoph Hellwig wrote:

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig 


Looks good.

Reviewed-by: Anand Jain 

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] don't use ->bd_inode to access the block device size

2021-10-13 Thread Anand Jain

On 13/10/2021 13:10, Christoph Hellwig wrote:

Hi Jens,

various drivers currently poke directy at the block device inode, which
is a bit of a mess.  This series cleans up the places that read the
block device size to use the proper helpers.  I have separate patches
for many of the other bd_inode uses, but this series is already big
enough as-is,

I wondered about adding a helper for looking at the size in byte units
to avoid the SECTOR_SHIFT shifts in various places.  But given that
I could not come up with a good name and 




block devices fundamentally
work in sector size granularity I decided against that.


Yes.  However,  POV of its usage outside the block-layer, a wrapper 
helper is a lot better. No.? If you agree, how about naming it bdev_size()?


Thanks, Anand



Diffstat:
  block/fops.c|2 +-
  drivers/block/drbd/drbd_int.h   |3 +--
  drivers/md/bcache/super.c   |2 +-
  drivers/md/bcache/util.h|4 
  drivers/md/bcache/writeback.c   |2 +-
  drivers/md/dm-bufio.c   |2 +-
  drivers/md/dm-cache-metadata.c  |2 +-
  drivers/md/dm-cache-target.c|2 +-
  drivers/md/dm-clone-target.c|2 +-
  drivers/md/dm-dust.c|5 ++---
  drivers/md/dm-ebs-target.c  |2 +-
  drivers/md/dm-era-target.c  |2 +-
  drivers/md/dm-exception-store.h |2 +-
  drivers/md/dm-flakey.c  |3 +--
  drivers/md/dm-integrity.c   |6 +++---
  drivers/md/dm-linear.c  |3 +--
  drivers/md/dm-log-writes.c  |4 ++--
  drivers/md/dm-log.c |2 +-
  drivers/md/dm-mpath.c   |2 +-
  drivers/md/dm-raid.c|6 +++---
  drivers/md/dm-switch.c  |2 +-
  drivers/md/dm-table.c   |3 +--
  drivers/md/dm-thin-metadata.c   |2 +-
  drivers/md/dm-thin.c|2 +-
  drivers/md/dm-verity-target.c   |3 +--
  drivers/md/dm-writecache.c  |2 +-
  drivers/md/dm-zoned-target.c|2 +-
  drivers/md/md.c |   26 +++---
  drivers/mtd/devices/block2mtd.c |5 +++--
  drivers/nvme/target/io-cmd-bdev.c   |4 ++--
  drivers/target/target_core_iblock.c |5 +++--
  fs/affs/super.c |2 +-
  fs/btrfs/dev-replace.c  |2 +-
  fs/btrfs/disk-io.c  |3 ++-
  fs/btrfs/ioctl.c|4 ++--
  fs/btrfs/volumes.c  |7 ---
  fs/buffer.c |4 ++--
  fs/cramfs/inode.c   |2 +-
  fs/ext4/super.c |2 +-
  fs/fat/inode.c  |5 +
  fs/hfs/mdb.c|2 +-
  fs/hfsplus/wrapper.c|2 +-
  fs/jfs/resize.c |5 ++---
  fs/jfs/super.c  |5 ++---
  fs/nfs/blocklayout/dev.c|4 ++--
  fs/nilfs2/ioctl.c   |2 +-
  fs/nilfs2/super.c   |2 +-
  fs/nilfs2/the_nilfs.c   |3 ++-
  fs/ntfs/super.c |8 +++-
  fs/ntfs3/super.c|3 +--
  fs/pstore/blk.c |4 ++--
  fs/reiserfs/super.c |7 ++-
  fs/squashfs/super.c |5 +++--
  fs/udf/lowlevel.c   |5 ++---
  fs/udf/super.c  |9 +++--
  include/linux/genhd.h   |6 ++
  56 files changed, 100 insertions(+), 117 deletions(-)



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel