@@ -856,14 +856,20 @@ static uint8_t l2arc_thread_exit;
856
856
static kmutex_t l2arc_rebuild_thr_lock ;
857
857
static kcondvar_t l2arc_rebuild_thr_cv ;
858
858
859
- static abd_t * arc_get_data_abd (arc_buf_hdr_t * , uint64_t , void * );
859
+ enum arc_hdr_alloc_flags {
860
+ ARC_HDR_ALLOC_RDATA = 0x1 ,
861
+ ARC_HDR_DO_ADAPT = 0x2 ,
862
+ };
863
+
864
+
865
+ static abd_t * arc_get_data_abd (arc_buf_hdr_t * , uint64_t , void * , boolean_t );
860
866
static void * arc_get_data_buf (arc_buf_hdr_t * , uint64_t , void * );
861
- static void arc_get_data_impl (arc_buf_hdr_t * , uint64_t , void * );
867
+ static void arc_get_data_impl (arc_buf_hdr_t * , uint64_t , void * , boolean_t );
862
868
static void arc_free_data_abd (arc_buf_hdr_t * , abd_t * , uint64_t , void * );
863
869
static void arc_free_data_buf (arc_buf_hdr_t * , void * , uint64_t , void * );
864
870
static void arc_free_data_impl (arc_buf_hdr_t * hdr , uint64_t size , void * tag );
865
871
static void arc_hdr_free_abd (arc_buf_hdr_t * , boolean_t );
866
- static void arc_hdr_alloc_abd (arc_buf_hdr_t * , boolean_t );
872
+ static void arc_hdr_alloc_abd (arc_buf_hdr_t * , int );
867
873
static void arc_access (arc_buf_hdr_t * , kmutex_t * );
868
874
static void arc_buf_watch (arc_buf_t * );
869
875
@@ -1822,7 +1828,7 @@ arc_hdr_decrypt(arc_buf_hdr_t *hdr, spa_t *spa, const zbookmark_phys_t *zb)
1822
1828
ASSERT (HDR_EMPTY_OR_LOCKED (hdr ));
1823
1829
ASSERT (HDR_ENCRYPTED (hdr ));
1824
1830
1825
- arc_hdr_alloc_abd (hdr , B_FALSE );
1831
+ arc_hdr_alloc_abd (hdr , ARC_HDR_DO_ADAPT );
1826
1832
1827
1833
ret = spa_do_crypt_abd (B_FALSE , spa , zb , hdr -> b_crypt_hdr .b_ot ,
1828
1834
B_FALSE , bswap , hdr -> b_crypt_hdr .b_salt , hdr -> b_crypt_hdr .b_iv ,
@@ -1849,7 +1855,7 @@ arc_hdr_decrypt(arc_buf_hdr_t *hdr, spa_t *spa, const zbookmark_phys_t *zb)
1849
1855
* and then loan a buffer from it, rather than allocating a
1850
1856
* linear buffer and wrapping it in an abd later.
1851
1857
*/
1852
- cabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr );
1858
+ cabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr , B_TRUE );
1853
1859
tmp = abd_borrow_buf (cabd , arc_hdr_size (hdr ));
1854
1860
1855
1861
ret = zio_decompress_data (HDR_GET_COMPRESS (hdr ),
@@ -3154,9 +3160,11 @@ arc_buf_destroy_impl(arc_buf_t *buf)
3154
3160
}
3155
3161
3156
3162
static void
3157
- arc_hdr_alloc_abd (arc_buf_hdr_t * hdr , boolean_t alloc_rdata )
3163
+ arc_hdr_alloc_abd (arc_buf_hdr_t * hdr , int alloc_flags )
3158
3164
{
3159
3165
uint64_t size ;
3166
+ boolean_t alloc_rdata = ((alloc_flags & ARC_HDR_ALLOC_RDATA ) != 0 );
3167
+ boolean_t do_adapt = ((alloc_flags & ARC_HDR_DO_ADAPT ) != 0 );
3160
3168
3161
3169
ASSERT3U (HDR_GET_LSIZE (hdr ), > , 0 );
3162
3170
ASSERT (HDR_HAS_L1HDR (hdr ));
@@ -3166,13 +3174,15 @@ arc_hdr_alloc_abd(arc_buf_hdr_t *hdr, boolean_t alloc_rdata)
3166
3174
if (alloc_rdata ) {
3167
3175
size = HDR_GET_PSIZE (hdr );
3168
3176
ASSERT3P (hdr -> b_crypt_hdr .b_rabd , = = , NULL );
3169
- hdr -> b_crypt_hdr .b_rabd = arc_get_data_abd (hdr , size , hdr );
3177
+ hdr -> b_crypt_hdr .b_rabd = arc_get_data_abd (hdr , size , hdr ,
3178
+ do_adapt );
3170
3179
ASSERT3P (hdr -> b_crypt_hdr .b_rabd , != , NULL );
3171
3180
ARCSTAT_INCR (arcstat_raw_size , size );
3172
3181
} else {
3173
3182
size = arc_hdr_size (hdr );
3174
3183
ASSERT3P (hdr -> b_l1hdr .b_pabd , = = , NULL );
3175
- hdr -> b_l1hdr .b_pabd = arc_get_data_abd (hdr , size , hdr );
3184
+ hdr -> b_l1hdr .b_pabd = arc_get_data_abd (hdr , size , hdr ,
3185
+ do_adapt );
3176
3186
ASSERT3P (hdr -> b_l1hdr .b_pabd , != , NULL );
3177
3187
}
3178
3188
@@ -3224,13 +3234,15 @@ arc_hdr_alloc(uint64_t spa, int32_t psize, int32_t lsize,
3224
3234
arc_buf_contents_t type , boolean_t alloc_rdata )
3225
3235
{
3226
3236
arc_buf_hdr_t * hdr ;
3237
+ int flags = ARC_HDR_DO_ADAPT ;
3227
3238
3228
3239
VERIFY (type == ARC_BUFC_DATA || type == ARC_BUFC_METADATA );
3229
3240
if (protected ) {
3230
3241
hdr = kmem_cache_alloc (hdr_full_crypt_cache , KM_PUSHPAGE );
3231
3242
} else {
3232
3243
hdr = kmem_cache_alloc (hdr_full_cache , KM_PUSHPAGE );
3233
3244
}
3245
+ flags |= alloc_rdata ? ARC_HDR_ALLOC_RDATA : 0 ;
3234
3246
3235
3247
ASSERT (HDR_EMPTY (hdr ));
3236
3248
ASSERT3P (hdr -> b_l1hdr .b_freeze_cksum , = = , NULL );
@@ -3254,7 +3266,7 @@ arc_hdr_alloc(uint64_t spa, int32_t psize, int32_t lsize,
3254
3266
* the compressed or uncompressed data depending on the block
3255
3267
* it references and compressed arc enablement.
3256
3268
*/
3257
- arc_hdr_alloc_abd (hdr , alloc_rdata );
3269
+ arc_hdr_alloc_abd (hdr , flags );
3258
3270
ASSERT (zfs_refcount_is_zero (& hdr -> b_l1hdr .b_refcnt ));
3259
3271
3260
3272
return (hdr );
@@ -5028,11 +5040,12 @@ arc_is_overflowing(void)
5028
5040
}
5029
5041
5030
5042
static abd_t *
5031
- arc_get_data_abd (arc_buf_hdr_t * hdr , uint64_t size , void * tag )
5043
+ arc_get_data_abd (arc_buf_hdr_t * hdr , uint64_t size , void * tag ,
5044
+ boolean_t do_adapt )
5032
5045
{
5033
5046
arc_buf_contents_t type = arc_buf_type (hdr );
5034
5047
5035
- arc_get_data_impl (hdr , size , tag );
5048
+ arc_get_data_impl (hdr , size , tag , do_adapt );
5036
5049
if (type == ARC_BUFC_METADATA ) {
5037
5050
return (abd_alloc (size , B_TRUE ));
5038
5051
} else {
@@ -5046,7 +5059,7 @@ arc_get_data_buf(arc_buf_hdr_t *hdr, uint64_t size, void *tag)
5046
5059
{
5047
5060
arc_buf_contents_t type = arc_buf_type (hdr );
5048
5061
5049
- arc_get_data_impl (hdr , size , tag );
5062
+ arc_get_data_impl (hdr , size , tag , B_TRUE );
5050
5063
if (type == ARC_BUFC_METADATA ) {
5051
5064
return (zio_buf_alloc (size ));
5052
5065
} else {
@@ -5120,12 +5133,14 @@ arc_wait_for_eviction(uint64_t amount)
5120
5133
* limit, we'll only signal the reclaim thread and continue on.
5121
5134
*/
5122
5135
static void
5123
- arc_get_data_impl (arc_buf_hdr_t * hdr , uint64_t size , void * tag )
5136
+ arc_get_data_impl (arc_buf_hdr_t * hdr , uint64_t size , void * tag ,
5137
+ boolean_t do_adapt )
5124
5138
{
5125
5139
arc_state_t * state = hdr -> b_l1hdr .b_state ;
5126
5140
arc_buf_contents_t type = arc_buf_type (hdr );
5127
5141
5128
- arc_adapt (size , state );
5142
+ if (do_adapt )
5143
+ arc_adapt (size , state );
5129
5144
5130
5145
/*
5131
5146
* If arc_size is currently overflowing, we must be adding data
@@ -5920,6 +5935,7 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
5920
5935
boolean_t devw = B_FALSE ;
5921
5936
uint64_t size ;
5922
5937
abd_t * hdr_abd ;
5938
+ int alloc_flags = encrypted_read ? ARC_HDR_ALLOC_RDATA : 0 ;
5923
5939
5924
5940
if (* arc_flags & ARC_FLAG_CACHED_ONLY ) {
5925
5941
rc = SET_ERROR (ENOENT );
@@ -6007,8 +6023,9 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
6007
6023
* do this after we've called arc_access() to
6008
6024
* avoid hitting an assert in remove_reference().
6009
6025
*/
6026
+ arc_adapt (arc_hdr_size (hdr ), hdr -> b_l1hdr .b_state );
6010
6027
arc_access (hdr , hash_lock );
6011
- arc_hdr_alloc_abd (hdr , encrypted_read );
6028
+ arc_hdr_alloc_abd (hdr , alloc_flags );
6012
6029
}
6013
6030
6014
6031
if (encrypted_read ) {
@@ -6452,7 +6469,7 @@ arc_release(arc_buf_t *buf, void *tag)
6452
6469
if (arc_can_share (hdr , lastbuf )) {
6453
6470
arc_share_buf (hdr , lastbuf );
6454
6471
} else {
6455
- arc_hdr_alloc_abd (hdr , B_FALSE );
6472
+ arc_hdr_alloc_abd (hdr , ARC_HDR_DO_ADAPT );
6456
6473
abd_copy_from_buf (hdr -> b_l1hdr .b_pabd ,
6457
6474
buf -> b_data , psize );
6458
6475
}
@@ -6687,7 +6704,7 @@ arc_write_ready(zio_t *zio)
6687
6704
if (ARC_BUF_ENCRYPTED (buf )) {
6688
6705
ASSERT3U (psize , > , 0 );
6689
6706
ASSERT (ARC_BUF_COMPRESSED (buf ));
6690
- arc_hdr_alloc_abd (hdr , B_TRUE );
6707
+ arc_hdr_alloc_abd (hdr , ARC_HDR_DO_ADAPT | ARC_HDR_ALLOC_RDATA );
6691
6708
abd_copy (hdr -> b_crypt_hdr .b_rabd , zio -> io_abd , psize );
6692
6709
} else if (zfs_abd_scatter_enabled || !arc_can_share (hdr , buf )) {
6693
6710
/*
@@ -6697,16 +6714,17 @@ arc_write_ready(zio_t *zio)
6697
6714
*/
6698
6715
if (BP_IS_ENCRYPTED (bp )) {
6699
6716
ASSERT3U (psize , > , 0 );
6700
- arc_hdr_alloc_abd (hdr , B_TRUE );
6717
+ arc_hdr_alloc_abd (hdr ,
6718
+ ARC_HDR_DO_ADAPT |ARC_HDR_ALLOC_RDATA );
6701
6719
abd_copy (hdr -> b_crypt_hdr .b_rabd , zio -> io_abd , psize );
6702
6720
} else if (arc_hdr_get_compress (hdr ) != ZIO_COMPRESS_OFF &&
6703
6721
!ARC_BUF_COMPRESSED (buf )) {
6704
6722
ASSERT3U (psize , > , 0 );
6705
- arc_hdr_alloc_abd (hdr , B_FALSE );
6723
+ arc_hdr_alloc_abd (hdr , ARC_HDR_DO_ADAPT );
6706
6724
abd_copy (hdr -> b_l1hdr .b_pabd , zio -> io_abd , psize );
6707
6725
} else {
6708
6726
ASSERT3U (zio -> io_orig_size , = = , arc_hdr_size (hdr ));
6709
- arc_hdr_alloc_abd (hdr , B_FALSE );
6727
+ arc_hdr_alloc_abd (hdr , ARC_HDR_DO_ADAPT );
6710
6728
abd_copy_from_buf (hdr -> b_l1hdr .b_pabd , buf -> b_data ,
6711
6729
arc_buf_size (buf ));
6712
6730
}
@@ -8150,7 +8168,8 @@ l2arc_untransform(zio_t *zio, l2arc_read_callback_t *cb)
8150
8168
* until arc_read_done().
8151
8169
*/
8152
8170
if (BP_IS_ENCRYPTED (bp )) {
8153
- abd_t * eabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr );
8171
+ abd_t * eabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr ,
8172
+ B_TRUE );
8154
8173
8155
8174
zio_crypt_decode_params_bp (bp , salt , iv );
8156
8175
zio_crypt_decode_mac_bp (bp , mac );
@@ -8186,7 +8205,8 @@ l2arc_untransform(zio_t *zio, l2arc_read_callback_t *cb)
8186
8205
*/
8187
8206
if (HDR_GET_COMPRESS (hdr ) != ZIO_COMPRESS_OFF &&
8188
8207
!HDR_COMPRESSION_ENABLED (hdr )) {
8189
- abd_t * cabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr );
8208
+ abd_t * cabd = arc_get_data_abd (hdr , arc_hdr_size (hdr ), hdr ,
8209
+ B_TRUE );
8190
8210
void * tmp = abd_borrow_buf (cabd , arc_hdr_size (hdr ));
8191
8211
8192
8212
ret = zio_decompress_data (HDR_GET_COMPRESS (hdr ),
0 commit comments