* Free up buf->b_data and pull the arc_buf_t off of the arc_buf_hdr_t's * list and free it. */
| 3125 | * list and free it. |
| 3126 | */ |
| 3127 | static void |
| 3128 | arc_buf_destroy_impl(arc_buf_t *buf) |
| 3129 | { |
| 3130 | arc_buf_hdr_t *hdr = buf->b_hdr; |
| 3131 | |
| 3132 | /* |
| 3133 | * Free up the data associated with the buf but only if we're not |
| 3134 | * sharing this with the hdr. If we are sharing it with the hdr, the |
| 3135 | * hdr is responsible for doing the free. |
| 3136 | */ |
| 3137 | if (buf->b_data != NULL) { |
| 3138 | /* |
| 3139 | * We're about to change the hdr's b_flags. We must either |
| 3140 | * hold the hash_lock or be undiscoverable. |
| 3141 | */ |
| 3142 | ASSERT(HDR_EMPTY_OR_LOCKED(hdr)); |
| 3143 | |
| 3144 | arc_cksum_verify(buf); |
| 3145 | arc_buf_unwatch(buf); |
| 3146 | |
| 3147 | if (arc_buf_is_shared(buf)) { |
| 3148 | arc_hdr_clear_flags(hdr, ARC_FLAG_SHARED_DATA); |
| 3149 | } else { |
| 3150 | uint64_t size = arc_buf_size(buf); |
| 3151 | arc_free_data_buf(hdr, buf->b_data, size, buf); |
| 3152 | ARCSTAT_INCR(arcstat_overhead_size, -size); |
| 3153 | } |
| 3154 | buf->b_data = NULL; |
| 3155 | |
| 3156 | ASSERT(hdr->b_l1hdr.b_bufcnt > 0); |
| 3157 | hdr->b_l1hdr.b_bufcnt -= 1; |
| 3158 | |
| 3159 | if (ARC_BUF_ENCRYPTED(buf)) { |
| 3160 | hdr->b_crypt_hdr.b_ebufcnt -= 1; |
| 3161 | |
| 3162 | /* |
| 3163 | * If we have no more encrypted buffers and we've |
| 3164 | * already gotten a copy of the decrypted data we can |
| 3165 | * free b_rabd to save some space. |
| 3166 | */ |
| 3167 | if (hdr->b_crypt_hdr.b_ebufcnt == 0 && |
| 3168 | HDR_HAS_RABD(hdr) && hdr->b_l1hdr.b_pabd != NULL && |
| 3169 | !HDR_IO_IN_PROGRESS(hdr)) { |
| 3170 | arc_hdr_free_abd(hdr, B_TRUE); |
| 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | arc_buf_t *lastbuf = arc_buf_remove(hdr, buf); |
| 3176 | |
| 3177 | if (ARC_BUF_SHARED(buf) && !ARC_BUF_COMPRESSED(buf)) { |
| 3178 | /* |
| 3179 | * If the current arc_buf_t is sharing its data buffer with the |
| 3180 | * hdr, then reassign the hdr's b_pabd to share it with the new |
| 3181 | * buffer at the end of the list. The shared buffer is always |
| 3182 | * the last one on the hdr's buffer list. |
| 3183 | * |
| 3184 | * There is an equivalent case for compressed bufs, but since |
no test coverage detected