Skip to content

Commit

Permalink
Add L2ARC Compression
Browse files Browse the repository at this point in the history
https://www.illumos.org/issues/3137
This issue ticket proposes adding transparent L2ARC compression to
ZFS. The algorithm is hard-coded to be the new LZ4 compression
algorithm, since L2ARC has very specific performance requirements
(high decompression speed).
The feature is controlled via a new secondarycachecompress property
on each dataset, allowing the user to selectively enable
compression only on datasets which can use it.

Patch dated 17/01/2013.
  • Loading branch information
jimmyH committed Feb 8, 2013
1 parent 5276878 commit c8d5f5a
Show file tree
Hide file tree
Showing 12 changed files with 493 additions and 67 deletions.
8 changes: 5 additions & 3 deletions include/sys/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/

#ifndef _SYS_ARC_H
Expand Down Expand Up @@ -78,6 +79,7 @@ typedef enum arc_buf_contents {
#define ARC_PREFETCH (1 << 3) /* I/O is a prefetch */
#define ARC_CACHED (1 << 4) /* I/O was already in cache */
#define ARC_L2CACHE (1 << 5) /* cache in L2ARC */
#define ARC_L2COMPRESS (1 << 6) /* compress in L2ARC */

/*
* The following breakdows of arc_size exist for kstat only.
Expand Down Expand Up @@ -121,9 +123,9 @@ int arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
arc_done_func_t *done, void *private, int priority, int flags,
uint32_t *arc_flags, const zbookmark_t *zb);
zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, const zio_prop_t *zp,
arc_done_func_t *ready, arc_done_func_t *done, void *private,
int priority, int zio_flags, const zbookmark_t *zb);
blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress,
const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *done,
void *private, int priority, int zio_flags, const zbookmark_t *zb);

arc_prune_t *arc_add_prune_callback(arc_prune_func_t *func, void *private);
void arc_remove_prune_callback(arc_prune_t *p);
Expand Down
11 changes: 11 additions & 0 deletions include/sys/dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/

#ifndef _SYS_DBUF_H
Expand Down Expand Up @@ -322,6 +323,16 @@ boolean_t dbuf_is_metadata(dmu_buf_impl_t *db);
(DBUF_IS_METADATA(_db) && \
((_db)->db_objset->os_secondary_cache == ZFS_CACHE_METADATA)))

#define DBUF_IS_L2COMPRESSIBLE(_db) \
((_db)->db_objset->os_secondary_cache_compress == \
ZFS_CACHE_COMPRESS_ALL || \
(DBUF_IS_METADATA(_db) && \
(_db)->db_objset->os_secondary_cache_compress == \
ZFS_CACHE_COMPRESS_METADATA) || \
(!DBUF_IS_METADATA(_db) && \
(_db)->db_objset->os_secondary_cache_compress == \
ZFS_CACHE_COMPRESS_DATA))

#ifdef ZFS_DEBUG

/*
Expand Down
7 changes: 7 additions & 0 deletions include/sys/dmu_objset.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -90,6 +91,7 @@ struct objset {
uint8_t os_logbias;
uint8_t os_primary_cache;
uint8_t os_secondary_cache;
uint8_t os_secondary_cache_compress; /* L2 compression */
uint8_t os_sync;

/* no lock needed: */
Expand Down Expand Up @@ -129,6 +131,11 @@ struct objset {
((os)->os_secondary_cache == ZFS_CACHE_ALL || \
(os)->os_secondary_cache == ZFS_CACHE_METADATA)

#define DMU_OS_IS_L2COMPRESSIBLE(os) \
((os)->os_secondary_cache_compress == ZFS_CACHE_COMPRESS_ALL || \
(os)->os_secondary_cache_compress == ZFS_CACHE_COMPRESS_DATA || \
(os)->os_secondary_cache_compress == ZFS_CACHE_COMPRESS_METADATA)

/* called from zpl */
int dmu_objset_hold(const char *name, void *tag, objset_t **osp);
int dmu_objset_own(const char *name, dmu_objset_type_t type,
Expand Down
9 changes: 9 additions & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -128,6 +129,7 @@ typedef enum {
ZFS_PROP_REFRATIO,
ZFS_PROP_WRITTEN,
ZFS_PROP_CLONES,
ZFS_PROP_SECONDARYCACHECOMPRESS,
ZFS_NUM_PROPS
} zfs_prop_t;

Expand Down Expand Up @@ -316,6 +318,13 @@ typedef enum zfs_cache_type {
ZFS_CACHE_ALL = 2
} zfs_cache_type_t;

typedef enum zfs_cache_compress_type {
ZFS_CACHE_COMPRESS_NONE = 0,
ZFS_CACHE_COMPRESS_DATA = 1,
ZFS_CACHE_COMPRESS_METADATA = 2,
ZFS_CACHE_COMPRESS_ALL = 3
} zfs_cache_compress_type_t;

typedef enum {
ZFS_SYNC_STANDARD = 0,
ZFS_SYNC_ALWAYS = 1,
Expand Down
5 changes: 5 additions & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
zio_done_func_t *done, void *private, int priority, enum zio_flag flags,
boolean_t labels);

extern zio_t *zio_read_null(zio_t *pio, vdev_t *vd, uint64_t offset,
uint64_t size, void *data, int checksum,
zio_done_func_t *done, void *private, int priority, enum zio_flag flags,
boolean_t labels);

extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
uint64_t size, void *data, int checksum,
zio_done_func_t *done, void *private, int priority, enum zio_flag flags,
Expand Down
26 changes: 26 additions & 0 deletions man/man8/zfs.8
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,32 @@ This property can also be referred to by its shortened column name, \fBreserv\fR
Controls what is cached in the secondary cache (L2ARC). If this property is set to \fBall\fR, then both user data and metadata is cached. If this property is set to \fBnone\fR, then neither user data nor metadata is cached. If this property is set to \fBmetadata\fR, then only metadata is cached. The default value is \fBall\fR.
.RE

.sp
.ne 2
.mk
.na
\fB\fBsecondarycachecompress\fR=\fBnone\fR | \fBall\fR | \fBmetadata\fR | \fBdata\fR\fR
.ad
.sp .6
.RS 4n
Controls compression of data on L2ARC devices. The default value is
\fBnone\fR, which means that no compression is requested for any data
when it enters the L2ARC. When set to \fBall\fR, all data from this
dataset is compressed when put into L2ARC and decompressed on cache hit.
When set to \fBmetadata\fR, only metadata is compressed and conversely
when set to \fBdata\fR, only user data is compressed. When multiple
datasets with different values for \fBsecondarycachecompress\fR
reference the same data in ARC, the data is compressed if at least one
dataset requests it (i.e. compression is preferred).

Buffers smaller than 2048 bytes (or 4096 bytes when using L2ARC devices
with 4k sectors) or buffers that cannot be compressed by at least 12.5%
will be stored uncompressed and thus do not incur any performance
penalty on cache hits. Please note that this means buffers from datasets
with a \fBrecordsize\fR smaller than or equal to this limit cannot be
compressed in L2ARC.
.RE

.sp
.ne 2
.mk
Expand Down
13 changes: 13 additions & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ zfs_prop_init(void)
{ NULL }
};

static zprop_index_t cache_compress_table[] = {
{ "none", ZFS_CACHE_COMPRESS_NONE },
{ "metadata", ZFS_CACHE_COMPRESS_METADATA },
{ "data", ZFS_CACHE_COMPRESS_DATA },
{ "all", ZFS_CACHE_COMPRESS_ALL },
{ NULL }
};

static zprop_index_t sync_table[] = {
{ "standard", ZFS_SYNC_STANDARD },
{ "always", ZFS_SYNC_ALWAYS },
Expand Down Expand Up @@ -232,6 +240,11 @@ zfs_prop_init(void)
ZFS_CACHE_ALL, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
"all | none | metadata", "SECONDARYCACHE", cache_table);
zprop_register_index(ZFS_PROP_SECONDARYCACHECOMPRESS,
"secondarycachecompress", ZFS_CACHE_COMPRESS_NONE, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
"all | none | metadata | data", "SECONDARYCACHECOMPRESS",
cache_compress_table);
zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
"latency | throughput", "LOGBIAS", logbias_table);
Expand Down
Loading

0 comments on commit c8d5f5a

Please sign in to comment.