76 kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT]; |
77 kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT]; |
77 |
78 |
78 #ifdef _KERNEL |
79 #ifdef _KERNEL |
79 extern vmem_t *zio_alloc_arena; |
80 extern vmem_t *zio_alloc_arena; |
80 #endif |
81 #endif |
|
82 extern int zfs_mg_alloc_failures; |
81 |
83 |
82 /* |
84 /* |
83 * An allocating zio is one that either currently has the DVA allocate |
85 * An allocating zio is one that either currently has the DVA allocate |
84 * stage set or will have it later in its lifetime. |
86 * stage set or will have it later in its lifetime. |
85 */ |
87 */ |
155 |
157 |
156 ASSERT(zio_data_buf_cache[c] != NULL); |
158 ASSERT(zio_data_buf_cache[c] != NULL); |
157 if (zio_data_buf_cache[c - 1] == NULL) |
159 if (zio_data_buf_cache[c - 1] == NULL) |
158 zio_data_buf_cache[c - 1] = zio_data_buf_cache[c]; |
160 zio_data_buf_cache[c - 1] = zio_data_buf_cache[c]; |
159 } |
161 } |
|
162 |
|
163 /* |
|
164 * The zio write taskqs have 1 thread per cpu, allow 1/2 of the taskqs |
|
165 * to fail 3 times per txg or 8 failures, whichever is greater. |
|
166 */ |
|
167 zfs_mg_alloc_failures = MAX((3 * max_ncpus / 2), 8); |
160 |
168 |
161 zio_inject_init(); |
169 zio_inject_init(); |
162 } |
170 } |
163 |
171 |
164 void |
172 void |
2112 { |
2120 { |
2113 spa_t *spa = zio->io_spa; |
2121 spa_t *spa = zio->io_spa; |
2114 metaslab_class_t *mc = spa_normal_class(spa); |
2122 metaslab_class_t *mc = spa_normal_class(spa); |
2115 blkptr_t *bp = zio->io_bp; |
2123 blkptr_t *bp = zio->io_bp; |
2116 int error; |
2124 int error; |
|
2125 int flags = 0; |
2117 |
2126 |
2118 if (zio->io_gang_leader == NULL) { |
2127 if (zio->io_gang_leader == NULL) { |
2119 ASSERT(zio->io_child_type > ZIO_CHILD_GANG); |
2128 ASSERT(zio->io_child_type > ZIO_CHILD_GANG); |
2120 zio->io_gang_leader = zio; |
2129 zio->io_gang_leader = zio; |
2121 } |
2130 } |
2124 ASSERT3U(BP_GET_NDVAS(bp), ==, 0); |
2133 ASSERT3U(BP_GET_NDVAS(bp), ==, 0); |
2125 ASSERT3U(zio->io_prop.zp_copies, >, 0); |
2134 ASSERT3U(zio->io_prop.zp_copies, >, 0); |
2126 ASSERT3U(zio->io_prop.zp_copies, <=, spa_max_replication(spa)); |
2135 ASSERT3U(zio->io_prop.zp_copies, <=, spa_max_replication(spa)); |
2127 ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp)); |
2136 ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp)); |
2128 |
2137 |
|
2138 /* |
|
2139 * The dump device does not support gang blocks so allocation on |
|
2140 * behalf of the dump device (i.e. ZIO_FLAG_NODATA) must avoid |
|
2141 * the "fast" gang feature. |
|
2142 */ |
|
2143 flags |= (zio->io_flags & ZIO_FLAG_NODATA) ? METASLAB_GANG_AVOID : 0; |
|
2144 flags |= (zio->io_flags & ZIO_FLAG_GANG_CHILD) ? |
|
2145 METASLAB_GANG_CHILD : 0; |
2129 error = metaslab_alloc(spa, mc, zio->io_size, bp, |
2146 error = metaslab_alloc(spa, mc, zio->io_size, bp, |
2130 zio->io_prop.zp_copies, zio->io_txg, NULL, 0); |
2147 zio->io_prop.zp_copies, zio->io_txg, NULL, flags); |
2131 |
2148 |
2132 if (error) { |
2149 if (error) { |
|
2150 spa_dbgmsg(spa, "%s: metaslab allocation failure: zio %p, " |
|
2151 "size %llu, error %d", spa_name(spa), zio, zio->io_size, |
|
2152 error); |
2133 if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE) |
2153 if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE) |
2134 return (zio_write_gang_block(zio)); |
2154 return (zio_write_gang_block(zio)); |
2135 zio->io_error = error; |
2155 zio->io_error = error; |
2136 } |
2156 } |
2137 |
2157 |