Skip to content

Commit

Permalink
Exclude special allocation class buffers from L2ARC
Browse files Browse the repository at this point in the history
Special allocation class vdevs may have roughly the same performance as
L2ARC vdevs. Exclude those buffers from being cacheable on L2ARC.

Signed-off-by: George Amanakis <gamanakis@gmail.com>
  • Loading branch information
gamanakis committed Jun 28, 2021
1 parent f20fb19 commit 427da3d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
35 changes: 31 additions & 4 deletions include/sys/dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <sys/zfs_refcount.h>
#include <sys/zrlock.h>
#include <sys/multilist.h>
#include <sys/vdev_impl.h>
#include <sys/spa_impl.h>
#include <sys/dmu_objset.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -442,10 +445,34 @@ dbuf_find_dirty_eq(dmu_buf_impl_t *db, uint64_t txg)
(dbuf_is_metadata(_db) && \
((_db)->db_objset->os_primary_cache == ZFS_CACHE_METADATA)))

#define DBUF_IS_L2CACHEABLE(_db) \
((_db)->db_objset->os_secondary_cache == ZFS_CACHE_ALL || \
(dbuf_is_metadata(_db) && \
((_db)->db_objset->os_secondary_cache == ZFS_CACHE_METADATA)))
/*
* We want to exclude buffers that are on a special allocation class from
* L2ARC.
*/
static inline boolean_t dbuf_is_l2cacheable(dmu_buf_impl_t *db)
{
blkptr_t *bp = db->db_blkptr;
spa_t *spa = db->db_objset->os_spa;
uint64_t vdev = DVA_GET_VDEV(db->db_blkptr->blk_dva);
vdev_t *vd = NULL;

if (bp != NULL) {
vdev_t *rvd = spa->spa_root_vdev;

if (vdev < rvd->vdev_children) {
ASSERT(rvd->vdev_child[vdev] != NULL);
vd = rvd->vdev_child[vdev];
}
}

if ((db->db_objset->os_secondary_cache == ZFS_CACHE_ALL ||
(dbuf_is_metadata(db) &&
db->db_objset->os_secondary_cache == ZFS_CACHE_METADATA)) &&
!(vd != NULL && vd->vdev_alloc_bias == VDEV_BIAS_SPECIAL))
return (B_TRUE);

return (B_FALSE);
}

#define DNODE_LEVEL_IS_L2CACHEABLE(_dn, _level) \
((_dn)->dn_objset->os_secondary_cache == ZFS_CACHE_ALL || \
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags,
DTRACE_SET_STATE(db, "read issued");
mutex_exit(&db->db_mtx);

if (DBUF_IS_L2CACHEABLE(db))
if (dbuf_is_l2cacheable(db))
aflags |= ARC_FLAG_L2CACHE;

dbuf_add_ref(db, NULL);
Expand Down Expand Up @@ -4985,7 +4985,7 @@ dbuf_write(dbuf_dirty_record_t *dr, arc_buf_t *data, dmu_tx_t *tx)
children_ready_cb = dbuf_write_children_ready;

dr->dr_zio = arc_write(pio, os->os_spa, txg,
&dr->dr_bp_copy, data, DBUF_IS_L2CACHEABLE(db),
&dr->dr_bp_copy, data, dbuf_is_l2cacheable(db),
&zp, dbuf_write_ready,
children_ready_cb, dbuf_write_physdone,
dbuf_write_done, db, ZIO_PRIORITY_ASYNC_WRITE,
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ dmu_sync(zio_t *pio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd)
dsa->dsa_tx = NULL;

zio_nowait(arc_write(pio, os->os_spa, txg,
zgd->zgd_bp, dr->dt.dl.dr_data, DBUF_IS_L2CACHEABLE(db),
zgd->zgd_bp, dr->dt.dl.dr_data, dbuf_is_l2cacheable(db),
&zp, dmu_sync_ready, NULL, NULL, dmu_sync_done, dsa,
ZIO_PRIORITY_SYNC_WRITE, ZIO_FLAG_CANFAIL, &zb));

Expand Down

0 comments on commit 427da3d

Please sign in to comment.