Skip to content

Commit

Permalink
TRIM cache devices on export and remove.
Browse files Browse the repository at this point in the history
With this patch:
 - L2ARC vdevs are trimmed on export, except the labels which are
  preserved to keep import working.
 - L2ARC vdevs are trimmed entirely on remove and pool destroy.
  • Loading branch information
dechamps committed Sep 25, 2012
1 parent 94d6d97 commit 4c1f8e1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/sys/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void arc_fini(void);
*/

void l2arc_add_vdev(spa_t *spa, vdev_t *vd);
void l2arc_remove_vdev(vdev_t *vd);
void l2arc_remove_vdev(vdev_t *vd, int trim);
boolean_t l2arc_vdev_present(vdev_t *vd);
void l2arc_init(void);
void l2arc_fini(void);
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ extern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp,
extern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp);
extern void zio_flush(zio_t *zio, vdev_t *vd);
extern zio_t *zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd,
uint64_t offset, uint64_t size);
uint64_t offset, uint64_t size, enum zio_flag flags);
extern void zio_shrink(zio_t *zio, uint64_t size);

extern int zio_wait(zio_t *zio);
Expand Down
7 changes: 6 additions & 1 deletion module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4856,7 +4856,7 @@ l2arc_add_vdev(spa_t *spa, vdev_t *vd)
* Remove a vdev from the L2ARC.
*/
void
l2arc_remove_vdev(vdev_t *vd)
l2arc_remove_vdev(vdev_t *vd, int trim)
{
l2arc_dev_t *dev, *nextdev, *remdev = NULL;

Expand Down Expand Up @@ -4886,6 +4886,11 @@ l2arc_remove_vdev(vdev_t *vd)
*/
l2arc_evict(remdev, 0, B_TRUE);
list_destroy(remdev->l2ad_buflist);
if (trim && spa_writeable(vd->vdev_spa))
zio_wait(zio_trim(NULL, vd->vdev_spa, vd,
remdev->l2ad_start,
remdev->l2ad_end - remdev->l2ad_start,
ZIO_FLAG_CONFIG_WRITER));
kmem_free(remdev->l2ad_buflist, sizeof (list_t));
kmem_free(remdev, sizeof (l2arc_dev_t));
}
Expand Down
7 changes: 5 additions & 2 deletions module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,10 @@ spa_load_l2cache(spa_t *spa)

if (spa_l2cache_exists(vd->vdev_guid, &pool) &&
pool != 0ULL && l2arc_vdev_present(vd))
l2arc_remove_vdev(vd);
l2arc_remove_vdev(vd, 0);
if (!zfs_notrim && spa_writeable(spa))
zio_wait(zio_trim(NULL, spa, vd, 0,
vd->vdev_psize, ZIO_FLAG_CONFIG_WRITER));
vdev_clear_stats(vd);
vdev_free(vd);
}
Expand Down Expand Up @@ -2935,7 +2938,7 @@ spa_l2cache_drop(spa_t *spa)

if (spa_l2cache_exists(vd->vdev_guid, &pool) &&
pool != 0ULL && l2arc_vdev_present(vd))
l2arc_remove_vdev(vd);
l2arc_remove_vdev(vd, !zfs_notrim);
}
}

Expand Down
2 changes: 1 addition & 1 deletion module/zfs/trim_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ trim_map_vdev_commit(spa_t *spa, zio_t *zio, vdev_t *vd)
avl_remove(&tm->tm_queued_frees, ts);
avl_add(&tm->tm_inflight_frees, ts);
zio_nowait(zio_trim(zio, spa, vd, ts->ts_start,
ts->ts_end - ts->ts_start));
ts->ts_end - ts->ts_start, 0));
}
mutex_exit(&tm->tm_lock);
}
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ vdev_label_init(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason)
*/
if (!zfs_notrim && (reason == VDEV_LABEL_CREATE ||
reason == VDEV_LABEL_SPARE || reason == VDEV_LABEL_L2CACHE))
zio_wait(zio_trim(NULL, spa, vd, 0, vd->vdev_psize));
zio_wait(zio_trim(NULL, spa, vd, 0, vd->vdev_psize, 0));

/*
* Initialize its label.
Expand Down
6 changes: 4 additions & 2 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,14 +982,16 @@ zio_flush(zio_t *zio, vdev_t *vd)
}

zio_t *
zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd, uint64_t offset, uint64_t size)
zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd, uint64_t offset, uint64_t size,
enum zio_flag flags)
{

ASSERT(vd->vdev_ops->vdev_op_leaf);

return zio_ioctl(zio, spa, vd, DKIOCTRIM, offset, size,
NULL, NULL, ZIO_PRIORITY_TRIM,
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY);
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY
| flags);
}

void
Expand Down

0 comments on commit 4c1f8e1

Please sign in to comment.