Skip to content

Commit

Permalink
Add ABD version of zio_{,de}compress_data
Browse files Browse the repository at this point in the history
Add zio_{,de}copmress_abd so the callers don't need to do borrow buffers
themselves.

Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
  • Loading branch information
Chunwei Chen committed May 13, 2016
1 parent 3411584 commit f72997f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 39 deletions.
4 changes: 4 additions & 0 deletions include/sys/zio_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ extern size_t zio_compress_data(enum zio_compress c, void *src, void *dst,
size_t s_len);
extern int zio_decompress_data(enum zio_compress c, void *src, void *dst,
size_t s_len, size_t d_len);
extern size_t zio_compress_abd(enum zio_compress c, abd_t *sabd, abd_t *dabd,
size_t s_len);
extern int zio_decompress_abd(enum zio_compress c, abd_t *sabd, abd_t *dabd,
size_t s_len, size_t d_len);

#ifdef __cplusplus
}
Expand Down
23 changes: 7 additions & 16 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6619,7 +6619,6 @@ static boolean_t
l2arc_compress_buf(arc_buf_hdr_t *hdr)
{
abd_t *cdata;
void *ddata;
size_t csize, len, rounded;
l2arc_buf_hdr_t *l2hdr;

Expand All @@ -6634,10 +6633,8 @@ l2arc_compress_buf(arc_buf_hdr_t *hdr)
len = l2hdr->b_asize;
cdata = abd_alloc_linear(len);
ASSERT3P(cdata, !=, NULL);
ddata = abd_borrow_buf_copy(hdr->b_l1hdr.b_tmp_cdata, l2hdr->b_asize);
csize = zio_compress_data(ZIO_COMPRESS_LZ4, ddata,
ABD_TO_BUF(cdata), l2hdr->b_asize);
abd_return_buf(hdr->b_l1hdr.b_tmp_cdata, ddata, l2hdr->b_asize);
csize = zio_compress_abd(ZIO_COMPRESS_LZ4, hdr->b_l1hdr.b_tmp_cdata,
cdata, l2hdr->b_asize);

rounded = P2ROUNDUP(csize, (size_t)SPA_MINBLOCKSIZE);
if (rounded > csize) {
Expand Down Expand Up @@ -6689,7 +6686,7 @@ static void
l2arc_decompress_zio(zio_t *zio, arc_buf_hdr_t *hdr, enum zio_compress c)
{
uint64_t csize;
void *cdata;
abd_t *cdata;

ASSERT(L2ARC_IS_VALID_COMPRESS(c));

Expand All @@ -6712,7 +6709,6 @@ l2arc_decompress_zio(zio_t *zio, arc_buf_hdr_t *hdr, enum zio_compress c)
abd_zero(hdr->b_l1hdr.b_buf->b_data, hdr->b_size);
zio->io_data = zio->io_orig_data = hdr->b_l1hdr.b_buf->b_data;
} else {
void *ddata;
ASSERT(zio->io_data != NULL);
/*
* We copy the compressed data from the start of the arc buffer
Expand All @@ -6725,17 +6721,12 @@ l2arc_decompress_zio(zio_t *zio, arc_buf_hdr_t *hdr, enum zio_compress c)
* which is likely to be much larger).
*/
csize = zio->io_size;
cdata = zio_data_buf_alloc(csize);

abd_copy_to_buf(cdata, zio->io_data, csize);
ddata = abd_borrow_buf(zio->io_data, hdr->b_size);

if (zio_decompress_data(c, cdata, ddata, csize,
cdata = abd_alloc_linear(csize);
abd_copy(cdata, zio->io_data, csize);
if (zio_decompress_abd(c, cdata, zio->io_data, csize,
hdr->b_size) != 0)
zio->io_error = EIO;

abd_return_buf_copy(zio->io_data, ddata, hdr->b_size);
zio_data_buf_free(cdata, csize);
abd_free(cdata, csize);
}

/* Restore the expected uncompressed IO size. */
Expand Down
31 changes: 8 additions & 23 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,10 @@ zio_subblock(zio_t *zio, abd_t *data, uint64_t size)
static void
zio_decompress(zio_t *zio, abd_t *data, uint64_t size)
{
char *buf1, *buf2;
if (zio->io_error == 0) {
buf1 = abd_borrow_buf_copy(zio->io_data, zio->io_size);
buf2 = abd_borrow_buf(data, size);

if (zio_decompress_data(BP_GET_COMPRESS(zio->io_bp),
buf1, buf2, zio->io_size, size) != 0)
zio->io_error = SET_ERROR(EIO);

abd_return_buf_copy(data, buf2, size);
abd_return_buf(zio->io_data, buf1, zio->io_size);
}
if (zio->io_error == 0 &&
zio_decompress_abd(BP_GET_COMPRESS(zio->io_bp),
zio->io_data, data, zio->io_size, size) != 0)
zio->io_error = SET_ERROR(EIO);
}

/*
Expand Down Expand Up @@ -1216,33 +1208,28 @@ zio_write_bp_init(zio_t *zio)
}

if (compress != ZIO_COMPRESS_OFF) {
char *cbuf, *dbuf;
abd_t *cdata;

if (ABD_IS_LINEAR(zio->io_data))
cdata = abd_alloc_linear(lsize);
else
cdata = abd_alloc_scatter(lsize);

cbuf = abd_borrow_buf(cdata, lsize);

dbuf = abd_borrow_buf_copy(zio->io_data, lsize);
psize = zio_compress_data(compress, dbuf, cbuf, lsize);
abd_return_buf(zio->io_data, dbuf, lsize);
psize = zio_compress_abd(compress, zio->io_data, cdata, lsize);

if (psize == 0 || psize == lsize) {
compress = ZIO_COMPRESS_OFF;
abd_return_buf(cdata, cbuf, lsize);
abd_free(cdata, lsize);
} else if (!zp->zp_dedup && psize <= BPE_PAYLOAD_SIZE &&
zp->zp_level == 0 && !DMU_OT_HAS_FILL(zp->zp_type) &&
spa_feature_is_enabled(spa, SPA_FEATURE_EMBEDDED_DATA)) {
void *cbuf = abd_borrow_buf_copy(cdata, psize);
encode_embedded_bp_compressed(bp,
cbuf, compress, lsize, psize);
abd_return_buf(cdata, cbuf, psize);
BPE_SET_ETYPE(bp, BP_EMBEDDED_TYPE_DATA);
BP_SET_TYPE(bp, zio->io_prop.zp_type);
BP_SET_LEVEL(bp, zio->io_prop.zp_level);
abd_return_buf(cdata, cbuf, lsize);
abd_free(cdata, lsize);
bp->blk_birth = zio->io_txg;
zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
Expand All @@ -1266,12 +1253,10 @@ zio_write_bp_init(zio_t *zio)
1ULL << spa->spa_min_ashift);
if (rounded >= lsize) {
compress = ZIO_COMPRESS_OFF;
abd_return_buf(cdata, cbuf, lsize);
abd_free(cdata, lsize);
psize = lsize;
} else {
bzero((char *)cbuf + psize, rounded - psize);
abd_return_buf_copy(cdata, cbuf, lsize);
abd_zero_off(cdata, rounded - psize, psize);
psize = rounded;
zio_push_transform(zio, cdata,
psize, lsize, NULL);
Expand Down
29 changes: 29 additions & 0 deletions module/zfs/zio_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,32 @@ zio_decompress_data(enum zio_compress c, void *src, void *dst,

return (ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level));
}

size_t
zio_compress_abd(enum zio_compress c, abd_t *sabd, abd_t *dabd, size_t s_len)
{
int ret;
void *src, *dst;

src = abd_borrow_buf_copy(sabd, s_len);
dst = abd_borrow_buf(dabd, s_len);
ret = zio_compress_data(c, src, dst, s_len);
abd_return_buf_copy(dabd, dst, s_len);
abd_return_buf(sabd, src, s_len);
return (ret);
}

int
zio_decompress_abd(enum zio_compress c, abd_t *sabd, abd_t *dabd, size_t s_len,
size_t d_len)
{
int ret;
void *src, *dst;

src = abd_borrow_buf_copy(sabd, s_len);
dst = abd_borrow_buf(dabd, d_len);
ret = zio_decompress_data(c, src, dst, s_len, d_len);
abd_return_buf_copy(dabd, dst, d_len);
abd_return_buf(sabd, src, s_len);
return (ret);
}

0 comments on commit f72997f

Please sign in to comment.