Skip to content

Commit

Permalink
TRIM the whole vdev on create/add/attach.
Browse files Browse the repository at this point in the history
With this patch, ZFS will attempt to TRIM the whole vdev in the
following cases:

 - zpool create, zpool add, zpool attach any vdev
 - zpool import spare and L2ARC devices

We do this to make sure we start from a "clean state". This way, the
physical device knows that all the data it held before it was added to
the pool is now obsolete. This is similar to what mke2fs does.
  • Loading branch information
dechamps committed Sep 20, 2012
1 parent dccbfaf commit 8cbb5cd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ extern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp,
blkptr_t *old_bp, uint64_t size, boolean_t use_slog);
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 void zio_trim(zio_t *zio, vdev_t *vd, uint64_t offset, uint64_t size);
extern zio_t *zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd,
uint64_t offset, uint64_t size);
extern void zio_shrink(zio_t *zio, uint64_t size);

extern int zio_wait(zio_t *zio);
Expand Down
3 changes: 2 additions & 1 deletion module/zfs/trim_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ trim_map_vdev_commit(spa_t *spa, zio_t *zio, vdev_t *vd)
list_remove(&tm->tm_head, ts);
avl_remove(&tm->tm_queued_frees, ts);
avl_add(&tm->tm_inflight_frees, ts);
zio_trim(zio, vd, ts->ts_start, ts->ts_end - ts->ts_start);
zio_nowait(zio_trim(zio, spa, vd, ts->ts_start,
ts->ts_end - ts->ts_start));
}
mutex_exit(&tm->tm_lock);
}
Expand Down
10 changes: 10 additions & 0 deletions module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,16 @@ vdev_label_init(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason)
return (0);
ASSERT(reason == VDEV_LABEL_REPLACE);
}

/*
* TRIM the whole thing so that we start with a clean slate.
* It's just an optimization, so we don't care if it fails.
* Don't TRIM if removing so that we don't interfere with zpool
* disaster recovery.
*/
if (reason == VDEV_LABEL_CREATE || reason == VDEV_LABEL_SPARE
|| reason == VDEV_LABEL_L2CACHE)
zio_wait(zio_trim(NULL, spa, vd, 0, vd->vdev_psize));

/*
* Initialize its label.
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,15 @@ zio_flush(zio_t *zio, vdev_t *vd)
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY));
}

void
zio_trim(zio_t *zio, vdev_t *vd, uint64_t offset, uint64_t size)
zio_t *
zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd, uint64_t offset, uint64_t size)
{

ASSERT(vd->vdev_ops->vdev_op_leaf);

zio_nowait(zio_ioctl(zio, zio->io_spa, vd, DKIOCTRIM, offset, size,
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);
}

void
Expand Down

0 comments on commit 8cbb5cd

Please sign in to comment.