forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds TRIM (a.k.a UNMAP, DISCARD, hole punching) support for disk vdevs. The original patch is from Pawel Jakub Dawidek <[email protected]> who wrote it for FreeBSD. Etienne Dechamps <[email protected]> ported it to ZFS On Linux. The code builds a map of regions that were freed. On every write the code consults the map and eventually removes ranges that were freed before, but are now overwritten. Freed blocks are not TRIMed immediately. There is a tunable that defines how many txg we should wait with TRIMming freed blocks (64 by default). There is a low priority thread that TRIMs ranges when the time comes. During TRIM we keep in-flight ranges on a list to detect colliding writes - we have to delay writes that collide with in-flight TRIMs in case something will be reordered and write will reached the disk before the TRIM. We don't have to do the same for in-flight writes, as colliding writes just remove ranges to TRIM. Most of the code stayed unchanged during the porting to Linux. The only big change is in the vdev disk module, since the FreeBSD and Linux interfaces for issuing discards to block devices is obviously different. On FreeBSD it seems that issuing a DELETE request of any size is sufficient; on Linux we have to be careful not to exceed maximum discard limits. That's why we introduce a new vdev_disk_io_trim() function inspired from the Linux blkdev_issue_discard() function and the pre-existing vdev_disk_physio() function. The new function takes care of splitting discard requests into smaller ones if necessary. In theory, the code should work for main pool disk vdevs, slog disk vdevs, L2ARC disk vdevs, and supports mirror and raidz. File vdevs are not supported yet. Note that the new feature is disabled by default (zfs_notrim=1). To use it, you have to explictly set the module parameter "zfs_notrim" to "0". Be aware that this code is largely untested and brings huge risks of potential data corruption. Use at your own risk and expect data loss.
- Loading branch information
Showing
18 changed files
with
827 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
* or http://www.opensolaris.org/os/licensing. | ||
* See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
/* | ||
* Copyright (c) 2012 Pawel Jakub Dawidek <[email protected]>. | ||
* All rights reserved. | ||
*/ | ||
|
||
#ifndef _SYS_TRIM_MAP_H | ||
#define _SYS_TRIM_MAP_H | ||
|
||
#include <sys/avl.h> | ||
#include <sys/list.h> | ||
#include <sys/spa.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void trim_map_create(vdev_t *vd); | ||
extern void trim_map_destroy(vdev_t *vd); | ||
extern void trim_map_free(zio_t *zio); | ||
extern boolean_t trim_map_write_start(zio_t *zio); | ||
extern void trim_map_write_done(zio_t *zio); | ||
|
||
extern void trim_thread_create(spa_t *spa); | ||
extern void trim_thread_destroy(spa_t *spa); | ||
extern void trim_thread_wakeup(spa_t *spa); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _SYS_TRIM_MAP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.