diff mbox series

[v5,2/5] btrfs: create read policy framework

Message ID 1581937965-16569-3-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series readmirror feature (sysfs and in-memory only approach; with new read_policy device) | expand

Commit Message

Anand Jain Feb. 17, 2020, 11:12 a.m. UTC
As of now we use %pid method to read stripped mirrored data, which means
process id determines the stripe id to be read. This type of routing
typically helps in a system with many small independent processes tying
to read random data. On the other hand the %pid based read IO policy is
inefficient because if there is a single process trying to read large
data the overall disk bandwidth remains under-utilized.

So this patch introduces read policy framework so that we could add more
read policies, such as IO routing based on device's wait-queue or manual
when we have a read-preferred device or a policy based on the target
storage caching.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
v5: Title renamed from:- btrfs: add read_policy framework
    Change log updated.
    Unnecessary comment dropped, added more where necessary.
    Optimize code in the switch remove duplicate code.
    Define BTRFS_READ_POLICY_DEFAULT dropped.
    Rename enum btrfs_read_policy_type to enum btrfs_read_policy.
    Rename BTRFS_READ_BY_PID to BTRFS_READ_POLICY_PID.
v4: -
v3: Declare fs_devices::readmirror as enum btrfs_readmirror_policy_type
v2: Declare fs_devices::readmirror as u8 instead of atomic_t
    A small change in comment and change log wordings.

 fs/btrfs/volumes.c | 13 ++++++++++++-
 fs/btrfs/volumes.h | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

Comments

kernel test robot Feb. 19, 2020, 7:41 a.m. UTC | #1
Hi Anand,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v5.6-rc2]
[also build test WARNING on next-20200219]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Anand-Jain/readmirror-feature-sysfs-and-in-memory-only-approach-with-new-read_policy-device/20200219-113525
base:    11a48a5a18c63fd7621bb050228cebf13566e4d8
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from fs/btrfs/volumes.c:18:0:
   fs/btrfs/volumes.c: In function 'find_live_mirror':
>> fs/btrfs/ctree.h:3143:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    do {        \
       ^
>> fs/btrfs/ctree.h:3089:2: note: in expansion of macro 'btrfs_printk_ratelimited'
     btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
     ^~~~~~~~~~~~~~~~~~~~~~~~
>> fs/btrfs/volumes.c:5367:3: note: in expansion of macro 'btrfs_warn_rl'
      btrfs_warn_rl(fs_info,
      ^~~~~~~~~~~~~
   fs/btrfs/volumes.c:5370:2: note: here
     case BTRFS_READ_POLICY_PID:
     ^~~~

vim +/btrfs_warn_rl +5367 fs/btrfs/volumes.c

  5343	
  5344	static int find_live_mirror(struct btrfs_fs_info *fs_info,
  5345				    struct map_lookup *map, int first,
  5346				    int dev_replace_is_ongoing)
  5347	{
  5348		int i;
  5349		int num_stripes;
  5350		int preferred_mirror;
  5351		int tolerance;
  5352		struct btrfs_device *srcdev;
  5353	
  5354		ASSERT((map->type &
  5355			 (BTRFS_BLOCK_GROUP_RAID1_MASK | BTRFS_BLOCK_GROUP_RAID10)));
  5356	
  5357		if (map->type & BTRFS_BLOCK_GROUP_RAID10)
  5358			num_stripes = map->sub_stripes;
  5359		else
  5360			num_stripes = map->num_stripes;
  5361	
  5362		switch (fs_info->fs_devices->read_policy) {
  5363		default:
  5364			/*
  5365			 * Shouldn't happen, just warn and use pid instead of failing.
  5366			 */
> 5367			btrfs_warn_rl(fs_info,
  5368				      "unknown read_policy type %u, fallback to pid",
  5369				      fs_info->fs_devices->read_policy);
  5370		case BTRFS_READ_POLICY_PID:
  5371			preferred_mirror = first + current->pid % num_stripes;
  5372		}
  5373	
  5374		if (dev_replace_is_ongoing &&
  5375		    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
  5376		     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
  5377			srcdev = fs_info->dev_replace.srcdev;
  5378		else
  5379			srcdev = NULL;
  5380	
  5381		/*
  5382		 * try to avoid the drive that is the source drive for a
  5383		 * dev-replace procedure, only choose it if no other non-missing
  5384		 * mirror is available
  5385		 */
  5386		for (tolerance = 0; tolerance < 2; tolerance++) {
  5387			if (map->stripes[preferred_mirror].dev->bdev &&
  5388			    (tolerance || map->stripes[preferred_mirror].dev != srcdev))
  5389				return preferred_mirror;
  5390			for (i = first; i < first + num_stripes; i++) {
  5391				if (map->stripes[i].dev->bdev &&
  5392				    (tolerance || map->stripes[i].dev != srcdev))
  5393					return i;
  5394			}
  5395		}
  5396	
  5397		/* we couldn't find one that doesn't fail.  Just return something
  5398		 * and the io error handling code will clean up eventually
  5399		 */
  5400		return preferred_mirror;
  5401	}
  5402	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Anand Jain Feb. 19, 2020, 11:40 a.m. UTC | #2
>     In file included from fs/btrfs/volumes.c:18:0:
>     fs/btrfs/volumes.c: In function 'find_live_mirror':

>>> fs/btrfs/ctree.h:3143:4: warning: this statement may fall through [-Wimplicit-fallthrough=]

  This is not a bug. May be we can make the robot happy.

Thanks, Anand
David Sterba Feb. 19, 2020, 12:35 p.m. UTC | #3
On Wed, Feb 19, 2020 at 07:40:47PM +0800, Anand Jain wrote:
> 
> >     In file included from fs/btrfs/volumes.c:18:0:
> >     fs/btrfs/volumes.c: In function 'find_live_mirror':
> 
> >>> fs/btrfs/ctree.h:3143:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
> 
>   This is not a bug. May be we can make the robot happy.

Since 5.5 all fall-trhough switch labels should be annotated properly.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 387f80656476..b6efb87bb0ae 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1209,6 +1209,7 @@  static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
 	fs_devices->opened = 1;
 	fs_devices->latest_bdev = latest_dev->bdev;
 	fs_devices->total_rw_bytes = 0;
+	fs_devices->read_policy = BTRFS_READ_POLICY_PID;
 out:
 	return ret;
 }
@@ -5358,7 +5359,17 @@  static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	else
 		num_stripes = map->num_stripes;
 
-	preferred_mirror = first + current->pid % num_stripes;
+	switch (fs_info->fs_devices->read_policy) {
+	default:
+		/*
+		 * Shouldn't happen, just warn and use pid instead of failing.
+		 */
+		btrfs_warn_rl(fs_info,
+			      "unknown read_policy type %u, fallback to pid",
+			      fs_info->fs_devices->read_policy);
+	case BTRFS_READ_POLICY_PID:
+		preferred_mirror = first + current->pid % num_stripes;
+	}
 
 	if (dev_replace_is_ongoing &&
 	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index f01552a0785e..ed2bba741b6e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -209,6 +209,15 @@  struct btrfs_device {
 BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
 BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
 
+/*
+ * Read policies for the mirrored block groups, read picks the stripe based
+ * on these policies.
+ */
+enum btrfs_read_policy {
+	BTRFS_READ_POLICY_PID,
+	BTRFS_NR_READ_POLICY,
+};
+
 struct btrfs_fs_devices {
 	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
 	u8 metadata_uuid[BTRFS_FSID_SIZE];
@@ -260,6 +269,11 @@  struct btrfs_fs_devices {
 	struct kobject *devices_kobj;
 	struct kobject *devinfo_kobj;
 	struct completion kobj_unregister;
+
+	/*
+	 * policy used to read the mirrored stripes
+	 */
+	enum btrfs_read_policy read_policy;
 };
 
 #define BTRFS_BIO_INLINE_CSUM_SIZE	64