Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
  28  * Copyright (c) 2014 Integros [integros.com]

  29  */
  30 
  31 #include <sys/zfs_context.h>
  32 #include <sys/vdev_impl.h>
  33 #include <sys/spa_impl.h>
  34 #include <sys/zio.h>
  35 #include <sys/avl.h>
  36 #include <sys/dsl_pool.h>
  37 #include <sys/metaslab_impl.h>
  38 #include <sys/abd.h>
  39 
  40 /*
  41  * ZFS I/O Scheduler
  42  * ---------------
  43  *
  44  * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios.  The
  45  * I/O scheduler determines when and in what order those operations are
  46  * issued.  The I/O scheduler divides operations into five I/O classes
  47  * prioritized in the following order: sync read, sync write, async read,
  48  * async write, and scrub/resilver.  Each queue defines the minimum and


 388 static int
 389 vdev_queue_class_min_active(zio_priority_t p)
 390 {
 391         switch (p) {
 392         case ZIO_PRIORITY_SYNC_READ:
 393                 return (zfs_vdev_sync_read_min_active);
 394         case ZIO_PRIORITY_SYNC_WRITE:
 395                 return (zfs_vdev_sync_write_min_active);
 396         case ZIO_PRIORITY_ASYNC_READ:
 397                 return (zfs_vdev_async_read_min_active);
 398         case ZIO_PRIORITY_ASYNC_WRITE:
 399                 return (zfs_vdev_async_write_min_active);
 400         case ZIO_PRIORITY_SCRUB:
 401                 return (zfs_vdev_scrub_min_active);
 402         case ZIO_PRIORITY_REMOVAL:
 403                 return (zfs_vdev_removal_min_active);
 404         case ZIO_PRIORITY_INITIALIZING:
 405                 return (zfs_vdev_initializing_min_active);
 406         default:
 407                 panic("invalid priority %u", p);
 408                 return (0);
 409         }
 410 }
 411 
 412 static int
 413 vdev_queue_max_async_writes(spa_t *spa)
 414 {
 415         int writes;
 416         uint64_t dirty = spa->spa_dsl_pool->dp_dirty_total;
 417         uint64_t min_bytes = zfs_dirty_data_max *
 418             zfs_vdev_async_write_active_min_dirty_percent / 100;
 419         uint64_t max_bytes = zfs_dirty_data_max *
 420             zfs_vdev_async_write_active_max_dirty_percent / 100;
 421 
 422         /*
 423          * Sync tasks correspond to interactive user actions. To reduce the
 424          * execution time of those actions we push data out as fast as possible.
 425          */
 426         if (spa_has_pending_synctask(spa)) {
 427                 return (zfs_vdev_async_write_max_active);
 428         }


 451 static int
 452 vdev_queue_class_max_active(spa_t *spa, zio_priority_t p)
 453 {
 454         switch (p) {
 455         case ZIO_PRIORITY_SYNC_READ:
 456                 return (zfs_vdev_sync_read_max_active);
 457         case ZIO_PRIORITY_SYNC_WRITE:
 458                 return (zfs_vdev_sync_write_max_active);
 459         case ZIO_PRIORITY_ASYNC_READ:
 460                 return (zfs_vdev_async_read_max_active);
 461         case ZIO_PRIORITY_ASYNC_WRITE:
 462                 return (vdev_queue_max_async_writes(spa));
 463         case ZIO_PRIORITY_SCRUB:
 464                 return (zfs_vdev_scrub_max_active);
 465         case ZIO_PRIORITY_REMOVAL:
 466                 return (zfs_vdev_removal_max_active);
 467         case ZIO_PRIORITY_INITIALIZING:
 468                 return (zfs_vdev_initializing_max_active);
 469         default:
 470                 panic("invalid priority %u", p);
 471                 return (0);
 472         }
 473 }
 474 
 475 /*
 476  * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
 477  * there is no eligible class.
 478  */
 479 static zio_priority_t
 480 vdev_queue_class_to_issue(vdev_queue_t *vq)
 481 {
 482         spa_t *spa = vq->vq_vdev->vdev_spa;
 483         zio_priority_t p;
 484 
 485         if (avl_numnodes(&vq->vq_active_tree) >= zfs_vdev_max_active)
 486                 return (ZIO_PRIORITY_NUM_QUEUEABLE);
 487 
 488         /* find a queue that has not reached its minimum # outstanding i/os */
 489         for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
 490                 if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 &&
 491                     vq->vq_class[p].vqc_active <




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
  28  * Copyright (c) 2014 Integros [integros.com]
  29  * Copyright 2019 Joyent, Inc.
  30  */
  31 
  32 #include <sys/zfs_context.h>
  33 #include <sys/vdev_impl.h>
  34 #include <sys/spa_impl.h>
  35 #include <sys/zio.h>
  36 #include <sys/avl.h>
  37 #include <sys/dsl_pool.h>
  38 #include <sys/metaslab_impl.h>
  39 #include <sys/abd.h>
  40 
  41 /*
  42  * ZFS I/O Scheduler
  43  * ---------------
  44  *
  45  * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios.  The
  46  * I/O scheduler determines when and in what order those operations are
  47  * issued.  The I/O scheduler divides operations into five I/O classes
  48  * prioritized in the following order: sync read, sync write, async read,
  49  * async write, and scrub/resilver.  Each queue defines the minimum and


 389 static int
 390 vdev_queue_class_min_active(zio_priority_t p)
 391 {
 392         switch (p) {
 393         case ZIO_PRIORITY_SYNC_READ:
 394                 return (zfs_vdev_sync_read_min_active);
 395         case ZIO_PRIORITY_SYNC_WRITE:
 396                 return (zfs_vdev_sync_write_min_active);
 397         case ZIO_PRIORITY_ASYNC_READ:
 398                 return (zfs_vdev_async_read_min_active);
 399         case ZIO_PRIORITY_ASYNC_WRITE:
 400                 return (zfs_vdev_async_write_min_active);
 401         case ZIO_PRIORITY_SCRUB:
 402                 return (zfs_vdev_scrub_min_active);
 403         case ZIO_PRIORITY_REMOVAL:
 404                 return (zfs_vdev_removal_min_active);
 405         case ZIO_PRIORITY_INITIALIZING:
 406                 return (zfs_vdev_initializing_min_active);
 407         default:
 408                 panic("invalid priority %u", p);

 409         }
 410 }
 411 
 412 static int
 413 vdev_queue_max_async_writes(spa_t *spa)
 414 {
 415         int writes;
 416         uint64_t dirty = spa->spa_dsl_pool->dp_dirty_total;
 417         uint64_t min_bytes = zfs_dirty_data_max *
 418             zfs_vdev_async_write_active_min_dirty_percent / 100;
 419         uint64_t max_bytes = zfs_dirty_data_max *
 420             zfs_vdev_async_write_active_max_dirty_percent / 100;
 421 
 422         /*
 423          * Sync tasks correspond to interactive user actions. To reduce the
 424          * execution time of those actions we push data out as fast as possible.
 425          */
 426         if (spa_has_pending_synctask(spa)) {
 427                 return (zfs_vdev_async_write_max_active);
 428         }


 451 static int
 452 vdev_queue_class_max_active(spa_t *spa, zio_priority_t p)
 453 {
 454         switch (p) {
 455         case ZIO_PRIORITY_SYNC_READ:
 456                 return (zfs_vdev_sync_read_max_active);
 457         case ZIO_PRIORITY_SYNC_WRITE:
 458                 return (zfs_vdev_sync_write_max_active);
 459         case ZIO_PRIORITY_ASYNC_READ:
 460                 return (zfs_vdev_async_read_max_active);
 461         case ZIO_PRIORITY_ASYNC_WRITE:
 462                 return (vdev_queue_max_async_writes(spa));
 463         case ZIO_PRIORITY_SCRUB:
 464                 return (zfs_vdev_scrub_max_active);
 465         case ZIO_PRIORITY_REMOVAL:
 466                 return (zfs_vdev_removal_max_active);
 467         case ZIO_PRIORITY_INITIALIZING:
 468                 return (zfs_vdev_initializing_max_active);
 469         default:
 470                 panic("invalid priority %u", p);

 471         }
 472 }
 473 
 474 /*
 475  * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
 476  * there is no eligible class.
 477  */
 478 static zio_priority_t
 479 vdev_queue_class_to_issue(vdev_queue_t *vq)
 480 {
 481         spa_t *spa = vq->vq_vdev->vdev_spa;
 482         zio_priority_t p;
 483 
 484         if (avl_numnodes(&vq->vq_active_tree) >= zfs_vdev_max_active)
 485                 return (ZIO_PRIORITY_NUM_QUEUEABLE);
 486 
 487         /* find a queue that has not reached its minimum # outstanding i/os */
 488         for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
 489                 if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 &&
 490                     vq->vq_class[p].vqc_active <