dm thin: adjust max_sectors_kb based on thinp blocksize
authorMike Snitzer <snitzer@redhat.com>
Thu, 9 Oct 2014 22:43:25 +0000 (18:43 -0400)
committerMike Snitzer <snitzer@redhat.com>
Mon, 10 Nov 2014 20:25:27 +0000 (15:25 -0500)
Allows for filesystems to submit bios that are a factor of the thinp
blocksize, improving dm-thinp efficiency (particularly when the data
volume is RAID).

Also set io_min to max_sectors_kb if it is a factor of the thinp
blocksize.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-thin.c

index 91b430b883fd85fdf18bfe1c1e5a39d336eae020..de55ae9d4926eb8c650b72b6c9e243fce98de400 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/device-mapper.h>
 #include <linux/dm-io.h>
 #include <linux/dm-kcopyd.h>
+#include <linux/log2.h>
 #include <linux/list.h>
 #include <linux/rculist.h>
 #include <linux/init.h>
@@ -3242,15 +3243,42 @@ static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
 {
        struct pool_c *pt = ti->private;
        struct pool *pool = pt->pool;
-       uint64_t io_opt_sectors = limits->io_opt >> SECTOR_SHIFT;
+       sector_t io_opt_sectors = limits->io_opt >> SECTOR_SHIFT;
+
+       /*
+        * Adjust max_sectors_kb to highest possible power-of-2
+        * factor of pool->sectors_per_block.
+        */
+       if (limits->max_hw_sectors & (limits->max_hw_sectors - 1))
+               limits->max_sectors = rounddown_pow_of_two(limits->max_hw_sectors);
+       else
+               limits->max_sectors = limits->max_hw_sectors;
+
+       if (limits->max_sectors < pool->sectors_per_block) {
+               while (!is_factor(pool->sectors_per_block, limits->max_sectors)) {
+                       if ((limits->max_sectors & (limits->max_sectors - 1)) == 0)
+                               limits->max_sectors--;
+                       limits->max_sectors = rounddown_pow_of_two(limits->max_sectors);
+               }
+       } else if (block_size_is_power_of_two(pool)) {
+               /* max_sectors_kb is >= power-of-2 thinp blocksize */
+               while (!is_factor(limits->max_sectors, pool->sectors_per_block)) {
+                       if ((limits->max_sectors & (limits->max_sectors - 1)) == 0)
+                               limits->max_sectors--;
+                       limits->max_sectors = rounddown_pow_of_two(limits->max_sectors);
+               }
+       }
 
        /*
         * If the system-determined stacked limits are compatible with the
         * pool's blocksize (io_opt is a factor) do not override them.
         */
        if (io_opt_sectors < pool->sectors_per_block ||
-           do_div(io_opt_sectors, pool->sectors_per_block)) {
-               blk_limits_io_min(limits, pool->sectors_per_block << SECTOR_SHIFT);
+           !is_factor(io_opt_sectors, pool->sectors_per_block)) {
+               if (is_factor(pool->sectors_per_block, limits->max_sectors))
+                       blk_limits_io_min(limits, limits->max_sectors << SECTOR_SHIFT);
+               else
+                       blk_limits_io_min(limits, pool->sectors_per_block << SECTOR_SHIFT);
                blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT);
        }