usr/src/uts/common/fs/zfs/zio.c
changeset 4055 9b8dd5af941d
parent 3882 f58e2c1a879e
child 4451 24fbf2d7a5d7
equal deleted inserted replaced
4054:44a43a2654b3 4055:9b8dd5af941d
    82 /*
    82 /*
    83  * ==========================================================================
    83  * ==========================================================================
    84  * I/O kmem caches
    84  * I/O kmem caches
    85  * ==========================================================================
    85  * ==========================================================================
    86  */
    86  */
       
    87 kmem_cache_t *zio_cache;
    87 kmem_cache_t *zio_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
    88 kmem_cache_t *zio_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
    88 kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
    89 kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
    89 
    90 
    90 #ifdef _KERNEL
    91 #ifdef _KERNEL
    91 extern vmem_t *zio_alloc_arena;
    92 extern vmem_t *zio_alloc_arena;
    98 	vmem_t *data_alloc_arena = NULL;
    99 	vmem_t *data_alloc_arena = NULL;
    99 
   100 
   100 #ifdef _KERNEL
   101 #ifdef _KERNEL
   101 	data_alloc_arena = zio_alloc_arena;
   102 	data_alloc_arena = zio_alloc_arena;
   102 #endif
   103 #endif
       
   104 
       
   105 	zio_cache = kmem_cache_create("zio_cache", sizeof (zio_t), 0,
       
   106 	    NULL, NULL, NULL, NULL, NULL, 0);
   103 
   107 
   104 	/*
   108 	/*
   105 	 * For small buffers, we want a cache for each multiple of
   109 	 * For small buffers, we want a cache for each multiple of
   106 	 * SPA_MINBLOCKSIZE.  For medium-size buffers, we want a cache
   110 	 * SPA_MINBLOCKSIZE.  For medium-size buffers, we want a cache
   107 	 * for each quarter-power of 2.  For large buffers, we want
   111 	 * for each quarter-power of 2.  For large buffers, we want
   171 			kmem_cache_destroy(zio_data_buf_cache[c]);
   175 			kmem_cache_destroy(zio_data_buf_cache[c]);
   172 		}
   176 		}
   173 		zio_data_buf_cache[c] = NULL;
   177 		zio_data_buf_cache[c] = NULL;
   174 	}
   178 	}
   175 
   179 
       
   180 	kmem_cache_destroy(zio_cache);
       
   181 
   176 	zio_inject_fini();
   182 	zio_inject_fini();
   177 }
   183 }
   178 
   184 
   179 /*
   185 /*
   180  * ==========================================================================
   186  * ==========================================================================
   301 	zio_t *zio;
   307 	zio_t *zio;
   302 
   308 
   303 	ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
   309 	ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
   304 	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
   310 	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
   305 
   311 
   306 	zio = kmem_zalloc(sizeof (zio_t), KM_SLEEP);
   312 	zio = kmem_cache_alloc(zio_cache, KM_SLEEP);
       
   313 	bzero(zio, sizeof (zio_t));
   307 	zio->io_parent = pio;
   314 	zio->io_parent = pio;
   308 	zio->io_spa = spa;
   315 	zio->io_spa = spa;
   309 	zio->io_txg = txg;
   316 	zio->io_txg = txg;
   310 	if (bp != NULL) {
   317 	if (bp != NULL) {
   311 		zio->io_bp = bp;
   318 		zio->io_bp = bp;
   747 		cv_wait(&zio->io_cv, &zio->io_lock);
   754 		cv_wait(&zio->io_cv, &zio->io_lock);
   748 	mutex_exit(&zio->io_lock);
   755 	mutex_exit(&zio->io_lock);
   749 
   756 
   750 	error = zio->io_error;
   757 	error = zio->io_error;
   751 	mutex_destroy(&zio->io_lock);
   758 	mutex_destroy(&zio->io_lock);
   752 	kmem_free(zio, sizeof (zio_t));
   759 	kmem_cache_free(zio_cache, zio);
   753 
   760 
   754 	return (error);
   761 	return (error);
   755 }
   762 }
   756 
   763 
   757 void
   764 void
   927 		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
   934 		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
   928 		    &pio->io_children_notdone);
   935 		    &pio->io_children_notdone);
   929 	}
   936 	}
   930 
   937 
   931 	/*
   938 	/*
   932 	 * Note: this I/O is now done, and will shortly be
   939 	 * Note: this I/O is now done, and will shortly be freed, so there is no
   933 	 * kmem_free()'d, so there is no need to clear this (or any
   940 	 * need to clear this (or any other) flag.
   934 	 * other) flag.
       
   935 	 */
   941 	 */
   936 	if (zio->io_flags & ZIO_FLAG_CONFIG_GRABBED)
   942 	if (zio->io_flags & ZIO_FLAG_CONFIG_GRABBED)
   937 		spa_config_exit(spa, zio);
   943 		spa_config_exit(spa, zio);
   938 
   944 
   939 	if (zio->io_waiter != NULL) {
   945 	if (zio->io_waiter != NULL) {
   941 		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
   947 		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
   942 		zio->io_stalled = zio->io_stage;
   948 		zio->io_stalled = zio->io_stage;
   943 		cv_broadcast(&zio->io_cv);
   949 		cv_broadcast(&zio->io_cv);
   944 		mutex_exit(&zio->io_lock);
   950 		mutex_exit(&zio->io_lock);
   945 	} else {
   951 	} else {
   946 		kmem_free(zio, sizeof (zio_t));
   952 		kmem_cache_free(zio_cache, zio);
   947 	}
   953 	}
   948 }
   954 }
   949 
   955 
   950 /*
   956 /*
   951  * ==========================================================================
   957  * ==========================================================================