From ac6361987efa85abf7e2a615747c0f62d065a57b Mon Sep 17 00:00:00 2001 From: mav Date: Fri, 8 Mar 2019 18:49:27 +0000 Subject: [PATCH] MFV/ZoL: Fix zfs_vdev_aggregation_limit bounds checking Update the bounds checking for zfs_vdev_aggregation_limit so that it has a floor of zero and a maximum value of the supported block size for the pool. Additionally add an early return when zfs_vdev_aggregation_limit equals zero to disable aggregation. For very fast solid state or memory devices it may be more expensive to perform the aggregation than to issue the IO immediately. Author: Brian Behlendorf zfsonlinux/zfs@a58df6f53687ac6d1dee21f60de41b2552a43201 MFV/ZoL: Cap maximum aggregate IO size Commit 8542ef8 allowed optional IOs to be aggregated beyond the specified aggregation limit. Since the aggregation limit was also used to enforce the maximum block size, setting `zfs_vdev_aggregation_limit=16777216` could result in an attempt to allocate an ABD larger than 16M. Author: Brian Behlendorf Reviewed by: Matthew Ahrens Reviewed-by: George Melikov Reviewed-by: Giuseppe Di Natale Signed-off-by: Brian Behlendorf Closes #6259 Closes #6270 zfsonlinux/zfs@2d678f779aba26a93314c8ee1142c3985fa25cb6 --- .../opensolaris/uts/common/fs/zfs/vdev_queue.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_queue.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_queue.c index 9394d5b1bb6b..2e8432d4ba4f 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_queue.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_queue.c @@ -673,13 +673,18 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) zio_link_t *zl = NULL; uint64_t maxgap = 0; uint64_t size; + uint64_t limit; + int maxblocksize; boolean_t stretch; avl_tree_t *t; enum zio_flag flags; ASSERT(MUTEX_HELD(&vq->vq_lock)); - if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE) + maxblocksize = spa_maxblocksize(vq->vq_vdev->vdev_spa); + limit = MAX(MIN(zfs_vdev_aggregation_limit, maxblocksize), 0); + + if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE || limit == 0) return (NULL); first = last = zio; @@ -710,7 +715,7 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) t = vdev_queue_type_tree(vq, zio->io_type); while (t != NULL && (dio = AVL_PREV(t, first)) != NULL && (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags && - IO_SPAN(dio, last) <= zfs_vdev_aggregation_limit && + IO_SPAN(dio, last) <= limit && IO_GAP(dio, first) <= maxgap && dio->io_type == zio->io_type) { first = dio; @@ -734,8 +739,9 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) */ while ((dio = AVL_NEXT(t, last)) != NULL && (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags && - (IO_SPAN(first, dio) <= zfs_vdev_aggregation_limit || + (IO_SPAN(first, dio) <= limit || (dio->io_flags & ZIO_FLAG_OPTIONAL)) && + IO_SPAN(first, dio) <= maxblocksize && IO_GAP(last, dio) <= maxgap && dio->io_type == zio->io_type) { last = dio; @@ -789,7 +795,7 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) return (NULL); size = IO_SPAN(first, last); - ASSERT3U(size, <=, SPA_MAXBLOCKSIZE); + ASSERT3U(size, <=, maxblocksize); aio = zio_vdev_delegated_io(first->io_vd, first->io_offset, abd_alloc_for_io(size, B_TRUE), size, first->io_type,