* Given a hdr and a buf, returns whether that buf can share its b_data buffer * with the hdr's b_pabd. */
| 2738 | * with the hdr's b_pabd. |
| 2739 | */ |
| 2740 | static boolean_t |
| 2741 | arc_can_share(arc_buf_hdr_t *hdr, arc_buf_t *buf) |
| 2742 | { |
| 2743 | /* |
| 2744 | * The criteria for sharing a hdr's data are: |
| 2745 | * 1. the buffer is not encrypted |
| 2746 | * 2. the hdr's compression matches the buf's compression |
| 2747 | * 3. the hdr doesn't need to be byteswapped |
| 2748 | * 4. the hdr isn't already being shared |
| 2749 | * 5. the buf is either compressed or it is the last buf in the hdr list |
| 2750 | * |
| 2751 | * Criterion #5 maintains the invariant that shared uncompressed |
| 2752 | * bufs must be the final buf in the hdr's b_buf list. Reading this, you |
| 2753 | * might ask, "if a compressed buf is allocated first, won't that be the |
| 2754 | * last thing in the list?", but in that case it's impossible to create |
| 2755 | * a shared uncompressed buf anyway (because the hdr must be compressed |
| 2756 | * to have the compressed buf). You might also think that #3 is |
| 2757 | * sufficient to make this guarantee, however it's possible |
| 2758 | * (specifically in the rare L2ARC write race mentioned in |
| 2759 | * arc_buf_alloc_impl()) there will be an existing uncompressed buf that |
| 2760 | * is shareable, but wasn't at the time of its allocation. Rather than |
| 2761 | * allow a new shared uncompressed buf to be created and then shuffle |
| 2762 | * the list around to make it the last element, this simply disallows |
| 2763 | * sharing if the new buf isn't the first to be added. |
| 2764 | */ |
| 2765 | ASSERT3P(buf->b_hdr, ==, hdr); |
| 2766 | boolean_t hdr_compressed = |
| 2767 | arc_hdr_get_compress(hdr) != ZIO_COMPRESS_OFF; |
| 2768 | boolean_t buf_compressed = ARC_BUF_COMPRESSED(buf) != 0; |
| 2769 | return (!ARC_BUF_ENCRYPTED(buf) && |
| 2770 | buf_compressed == hdr_compressed && |
| 2771 | hdr->b_l1hdr.b_byteswap == DMU_BSWAP_NUMFUNCS && |
| 2772 | !HDR_SHARED_DATA(hdr) && |
| 2773 | (ARC_BUF_LAST(buf) || ARC_BUF_COMPRESSED(buf))); |
| 2774 | } |
| 2775 | |
| 2776 | /* |
| 2777 | * Allocate a buf for this hdr. If you care about the data that's in the hdr, |
no test coverage detected