Skip to content

Commit 415882d

Browse files
amotinbehlendorf
authored andcommitted
Avoid small buffer copying on write
It is wrong for arc_write_ready() to use zfs_abd_scatter_enabled to decide whether to reallocate/copy the buffer, because the answer is OS-specific and depends on the buffer size. Instead of that use abd_size_alloc_linear(), moved into public header. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Brian Atkinson <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes #12425
1 parent 5b860ae commit 415882d

File tree

6 files changed

+6
-5
lines changed

6 files changed

+6
-5
lines changed

include/sys/abd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ abd_t *abd_alloc_linear(size_t, boolean_t);
9191
abd_t *abd_alloc_gang(void);
9292
abd_t *abd_alloc_for_io(size_t, boolean_t);
9393
abd_t *abd_alloc_sametype(abd_t *, size_t);
94+
boolean_t abd_size_alloc_linear(size_t);
9495
void abd_gang_add(abd_t *, abd_t *, boolean_t);
9596
void abd_free(abd_t *);
9697
abd_t *abd_get_offset(abd_t *, size_t);

include/sys/abd_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ abd_t *abd_get_offset_scatter(abd_t *, abd_t *, size_t, size_t);
6868
void abd_free_struct_impl(abd_t *);
6969
void abd_alloc_chunks(abd_t *, size_t);
7070
void abd_free_chunks(abd_t *);
71-
boolean_t abd_size_alloc_linear(size_t);
7271
void abd_update_scatter_stats(abd_t *, abd_stats_op_t);
7372
void abd_update_linear_stats(abd_t *, abd_stats_op_t);
7473
void abd_verify_scatter(abd_t *);

module/os/freebsd/zfs/abd_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ abd_scatter_chunkcnt(abd_t *abd)
131131
boolean_t
132132
abd_size_alloc_linear(size_t size)
133133
{
134-
return (size < zfs_abd_scatter_min_size ? B_TRUE : B_FALSE);
134+
return (!zfs_abd_scatter_enabled || size < zfs_abd_scatter_min_size);
135135
}
136136

137137
void

module/os/linux/zfs/abd_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ abd_alloc_zero_scatter(void)
638638
boolean_t
639639
abd_size_alloc_linear(size_t size)
640640
{
641-
return (size < zfs_abd_scatter_min_size ? B_TRUE : B_FALSE);
641+
return (!zfs_abd_scatter_enabled || size < zfs_abd_scatter_min_size);
642642
}
643643

644644
void

module/zfs/abd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ abd_free_struct(abd_t *abd)
181181
abd_t *
182182
abd_alloc(size_t size, boolean_t is_metadata)
183183
{
184-
if (!zfs_abd_scatter_enabled || abd_size_alloc_linear(size))
184+
if (abd_size_alloc_linear(size))
185185
return (abd_alloc_linear(size, is_metadata));
186186

187187
VERIFY3U(size, <=, SPA_MAXBLOCKSIZE);

module/zfs/arc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6917,7 +6917,8 @@ arc_write_ready(zio_t *zio)
69176917
arc_hdr_alloc_abd(hdr, ARC_HDR_DO_ADAPT | ARC_HDR_ALLOC_RDATA |
69186918
ARC_HDR_USE_RESERVE);
69196919
abd_copy(hdr->b_crypt_hdr.b_rabd, zio->io_abd, psize);
6920-
} else if (zfs_abd_scatter_enabled || !arc_can_share(hdr, buf)) {
6920+
} else if (!abd_size_alloc_linear(arc_buf_size(buf)) ||
6921+
!arc_can_share(hdr, buf)) {
69216922
/*
69226923
* Ideally, we would always copy the io_abd into b_pabd, but the
69236924
* user may have disabled compressed ARC, thus we must check the

0 commit comments

Comments
 (0)