Skip to content

Commit 2a15acb

Browse files
committed
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. Signed-off-by: Alexander Motin <[email protected]> Sponsored-By: iXsystems, Inc.
1 parent ab8a8f0 commit 2a15acb

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
@@ -132,7 +132,7 @@ abd_scatter_chunkcnt(abd_t *abd)
132132
boolean_t
133133
abd_size_alloc_linear(size_t size)
134134
{
135-
return (size < zfs_abd_scatter_min_size ? B_TRUE : B_FALSE);
135+
return (!zfs_abd_scatter_enabled || size < zfs_abd_scatter_min_size);
136136
}
137137

138138
void

module/os/linux/zfs/abd_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ abd_alloc_zero_scatter(void)
632632
boolean_t
633633
abd_size_alloc_linear(size_t size)
634634
{
635-
return (size < zfs_abd_scatter_min_size ? B_TRUE : B_FALSE);
635+
return (!zfs_abd_scatter_enabled || size < zfs_abd_scatter_min_size);
636636
}
637637

638638
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
@@ -6872,7 +6872,8 @@ arc_write_ready(zio_t *zio)
68726872
ASSERT(ARC_BUF_COMPRESSED(buf));
68736873
arc_hdr_alloc_abd(hdr, ARC_HDR_DO_ADAPT|ARC_HDR_ALLOC_RDATA);
68746874
abd_copy(hdr->b_crypt_hdr.b_rabd, zio->io_abd, psize);
6875-
} else if (zfs_abd_scatter_enabled || !arc_can_share(hdr, buf)) {
6875+
} else if (!abd_size_alloc_linear(arc_buf_size(buf)) ||
6876+
!arc_can_share(hdr, buf)) {
68766877
/*
68776878
* Ideally, we would always copy the io_abd into b_pabd, but the
68786879
* user may have disabled compressed ARC, thus we must check the

0 commit comments

Comments
 (0)