summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_buf.c')
-rw-r--r--fs/xfs/xfs_buf.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 217e4f82a44a..11a97bc35f70 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -2158,3 +2158,37 @@ xfs_verify_magic16(
return false;
return dmagic == bp->b_ops->magic16[idx];
}
+
+/* Estimate the amount of parallelism available for a given device. */
+unsigned int
+xfs_buftarg_guess_threads(
+ struct xfs_buftarg *btp)
+{
+ int iomin;
+ int ioopt;
+
+ /*
+ * The device tells us that it is non-rotational, and we take that to
+ * mean there are no moving parts and that the device can handle all
+ * the CPUs throwing IO requests at it.
+ */
+ if (blk_queue_nonrot(btp->bt_bdev->bd_queue))
+ return num_online_cpus();
+
+ /*
+ * The device has a preferred and minimum IO size that suggest a RAID
+ * setup, so infer the number of disks and assume that the parallelism
+ * is equal to the disk count.
+ */
+ iomin = bdev_io_min(btp->bt_bdev);
+ ioopt = bdev_io_opt(btp->bt_bdev);
+ if (iomin > 0 && ioopt > iomin)
+ return ioopt / iomin;
+
+ /*
+ * The device did not indicate that it has any capabilities beyond that
+ * of a rotating disk with a single drive head, so we estimate no
+ * parallelism at all.
+ */
+ return 1;
+}