Inband dedupe for btrfs-progs
Subsystems (3)
v8 cover Inband dedupe for btrfs-progs
Patchset can be fetched from github:
https://github.com/adam900710/btrfs-progs.git dedupe_20160606
Inband dedupe(in-memory backend only) ioctl support for btrfs-progs.
User/reviewer/tester can still use previous btrfs-progs patchset to test, this update is just cleanuping unsupported functions, like on-disk backend and any on-disk format change.
V8 changes:
Move dedup props and on-disk backend support out of the patchset Change command group name to "dedupe-inband", to avoid confusion with possible out-of-band dedupe. Suggested by Mark.
Rebase to latest devel branch.
v7 changes:
Update ctree.h to follow kernel structure change
Update print-tree to follow kernel structure change
Qu Wenruo (4):
btrfs-progs: Basic framework for dedupe-inband command group
btrfs-progs: dedupe: Add enable command for dedupe command group
btrfs-progs: dedupe: Add disable support for inband dedupelication
btrfs-progs: dedupe: Add status subcommand
Documentation/Makefile.in | 1 + Documentation/btrfs-dedupe-inband.asciidoc | 152 ++++++++++++++ Documentation/btrfs.asciidoc | 4 + Makefile.in | 3 +- btrfs-completion | 6 +- btrfs.c | 2 + cmds-dedupe-ib.c | 319 +++++++++++++++++++++++++++++ commands.h | 2 + ioctl.h | 23 +++ 9 files changed, 510 insertions(+), 2 deletions(-) create mode 100644 Documentation/btrfs-dedupe-inband.asciidoc create mode 100644 cmds-dedupe-ib.c
Signature · 1 line
2.8.3
PATCH v8 1/4 btrfs-progs: Basic framework for dedupe-inband command group
Add basic ioctl header and command group framework for later use. Alone with basic man page doc.
--- Documentation/Makefile.in | 1 + Documentation/btrfs-dedupe-inband.asciidoc | 40 +++++++++++++++++++++++++ Documentation/btrfs.asciidoc | 4 +++ Makefile.in | 3 +- btrfs.c | 2 ++ cmds-dedupe-ib.c | 48 ++++++++++++++++++++++++++++++ commands.h | 2 ++ ioctl.h | 21 +++++++++++++ 8 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Documentation/btrfs-dedupe-inband.asciidoc create mode 100644 cmds-dedupe-ib.c
Documentation/Makefile.in +1 -0
@@ -28,6 +28,7 @@ MAN8_TXT += btrfs-qgroup.asciidoc MAN8_TXT += btrfs-replace.asciidoc MAN8_TXT += btrfs-restore.asciidoc MAN8_TXT += btrfs-property.asciidoc +MAN8_TXT += btrfs-dedupe-inband.asciidoc # Category 5 manual page MAN5_TXT += btrfs-man5.asciidoc
Documentation/btrfs-dedupe-inband.asciidoc new file +40 -0
@@ -0,0 +1,40 @@ +btrfs-dedupe(8) +============== + +NAME +---- +btrfs-dedupe-inband - manage in-band (write time) de-duplication of a btrfs +filesystem + +SYNOPSIS +-------- +*btrfs dedupe-inband* <subcommand> <args> + +DESCRIPTION +----------- +*btrfs dedupe-inband* is used to enable/disable or show current in-band de-duplication +status of a btrfs filesystem. + +Kernel support for in-band de-duplication starts from 4.8. + +WARNING: In-band de-duplication is still an experimental feautre of btrfs, +use with caution. + +SUBCOMMAND +---------- +Nothing yet + +EXIT STATUS +----------- +*btrfs dedupe-inband* returns a zero exit status if it succeeds. Non zero is +returned in case of failure. + +AVAILABILITY +------------ +*btrfs* is part of btrfs-progs. +Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for +further details. + +SEE ALSO +-------- +`mkfs.btrfs`(8),
Documentation/btrfs.asciidoc +4 -0
@@ -43,6 +43,10 @@ COMMANDS Do off-line check on a btrfs filesystem. + See `btrfs-check`(8) for details. +*dedupe*:: + Control btrfs in-band(write time) de-duplication. + + See `btrfs-dedupe`(8) for details. + *device*:: Manage devices managed by btrfs, including add/delete/scan and so on. +
Makefile.in +2 -1
@@ -86,7 +86,8 @@ cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \ cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \ cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \ - cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o + cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \ + cmds-dedupe-ib.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o utils-lib.o rbtree-utils.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
btrfs.c +2 -0
@@ -199,6 +199,8 @@ static const struct cmd_group btrfs_cmd_group = { { "receive", cmd_receive, cmd_receive_usage, NULL, 0 }, { "quota", cmd_quota, NULL, "a_cmd_group, 0 }, { "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 }, + { "dedupe-inband", cmd_dedupe_ib, NULL, &dedupe_ib_cmd_group, + 0 }, { "replace", cmd_replace, NULL, &replace_cmd_group, 0 }, { "help", cmd_help, cmd_help_usage, NULL, 0 }, { "version", cmd_version, cmd_version_usage, NULL, 0 },
cmds-dedupe-ib.c new file +48 -0
48 lines not on this page · raw message
commands.h +2 -0
@@ -93,6 +93,7 @@ extern const struct cmd_group inspect_cmd_group;extern const struct cmd_group property_cmd_group;extern const struct cmd_group quota_cmd_group;extern const struct cmd_group qgroup_cmd_group; +extern const struct cmd_group dedupe_ib_cmd_group;extern const struct cmd_group replace_cmd_group;extern const struct cmd_group rescue_cmd_group;
@@ -118,6 +119,7 @@ int cmd_send(int argc, char **argv);int cmd_receive (int argc,char **argv);int cmd_quota (int argc,char **argv);int cmd_qgroup (int argc,char **argv); +int cmd_dedupe_ib (int argc,char **argv);int cmd_replace (int argc,char **argv);int cmd_restore (int argc,char **argv);int cmd_select_super (int argc,char **argv);
ioctl.h +21 -0
@@ -503,6 +503,27 @@ struct btrfs_ioctl_get_dev_stats {__u64 unused[128 -2 -BTRFS_DEV_STAT_VALUES_MAX ];/* pad to 1k */ }; +/* +* de-duplication control modes +* For re-config, enable will handle it +*/ +#define BTRFS_DEDUPE_CTL_ENABLE 1 +#define BTRFS_DEDUPE_CTL_DISABLE 2 +#define BTRFS_DEDUPE_CTL_STATUS 3 +#define BTRFS_DEDUPE_CTL_LAST 4 +struct btrfs_ioctl_dedupe_args { +__u16 cmd;/* In: command(see above macro) */ +__u64 blocksize;/* In/Out: For enable/status */ +__u64 limit_nr;/* In/Out: For enable/status */ +__u64 limit_mem;/* In/Out: For enable/status */ +__u64 current_nr;/* Out: For status output */ +__u16 backend;/* In/Out: For enable/status */ +__u16 hash_type;/* In/Out: For enable/status */ +u8 status;/* Out: For status output */ +/* pad to 512 bytes */ +u8 __unused[473 ]; +}; +/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */ #define BTRFS_QUOTA_CTL_ENABLE 1#define BTRFS_QUOTA_CTL_DISABLE 2
Signature · 1 line
2.8.3
PATCH v8 1/4 btrfs-progs: Basic framework for dedupe-inband command group
In reply to Qu WenruoAdd basic ioctl header and command group framework for later use. Alone with basic man page doc.
---
Add missing dedupe-in.h
--- Documentation/Makefile.in | 1 + Documentation/btrfs-dedupe-inband.asciidoc | 40 +++++++++++++++++++++++++ Documentation/btrfs.asciidoc | 4 +++ Makefile.in | 3 +- btrfs.c | 2 ++ cmds-dedupe-ib.c | 48 ++++++++++++++++++++++++++++++ commands.h | 2 ++ dedupe-ib.h | 41 +++++++++++++++++++++++++ ioctl.h | 21 +++++++++++++ 9 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 Documentation/btrfs-dedupe-inband.asciidoc create mode 100644 cmds-dedupe-ib.c create mode 100644 dedupe-ib.h
Documentation/Makefile.in +1 -0
@@ -28,6 +28,7 @@ MAN8_TXT += btrfs-qgroup.asciidoc MAN8_TXT += btrfs-replace.asciidoc MAN8_TXT += btrfs-restore.asciidoc MAN8_TXT += btrfs-property.asciidoc +MAN8_TXT += btrfs-dedupe-inband.asciidoc # Category 5 manual page MAN5_TXT += btrfs-man5.asciidoc
Documentation/btrfs-dedupe-inband.asciidoc new file +40 -0
@@ -0,0 +1,40 @@ +btrfs-dedupe(8) +============== + +NAME +---- +btrfs-dedupe-inband - manage in-band (write time) de-duplication of a btrfs +filesystem + +SYNOPSIS +-------- +*btrfs dedupe-inband* <subcommand> <args> + +DESCRIPTION +----------- +*btrfs dedupe-inband* is used to enable/disable or show current in-band de-duplication +status of a btrfs filesystem. + +Kernel support for in-band de-duplication starts from 4.8. + +WARNING: In-band de-duplication is still an experimental feautre of btrfs, +use with caution. + +SUBCOMMAND +---------- +Nothing yet + +EXIT STATUS +----------- +*btrfs dedupe-inband* returns a zero exit status if it succeeds. Non zero is +returned in case of failure. + +AVAILABILITY +------------ +*btrfs* is part of btrfs-progs. +Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for +further details. + +SEE ALSO +-------- +`mkfs.btrfs`(8),
Documentation/btrfs.asciidoc +4 -0
@@ -43,6 +43,10 @@ COMMANDS Do off-line check on a btrfs filesystem. + See `btrfs-check`(8) for details. +*dedupe*:: + Control btrfs in-band(write time) de-duplication. + + See `btrfs-dedupe`(8) for details. + *device*:: Manage devices managed by btrfs, including add/delete/scan and so on. +
Makefile.in +2 -1
@@ -86,7 +86,8 @@ cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \ cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \ cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \ - cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o + cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \ + cmds-dedupe-ib.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o utils-lib.o rbtree-utils.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
btrfs.c +2 -0
@@ -199,6 +199,8 @@ static const struct cmd_group btrfs_cmd_group = { { "receive", cmd_receive, cmd_receive_usage, NULL, 0 }, { "quota", cmd_quota, NULL, "a_cmd_group, 0 }, { "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 }, + { "dedupe-inband", cmd_dedupe_ib, NULL, &dedupe_ib_cmd_group, + 0 }, { "replace", cmd_replace, NULL, &replace_cmd_group, 0 }, { "help", cmd_help, cmd_help_usage, NULL, 0 }, { "version", cmd_version, cmd_version_usage, NULL, 0 },
cmds-dedupe-ib.c new file +48 -0
48 lines not on this page · raw message
commands.h +2 -0
@@ -93,6 +93,7 @@ extern const struct cmd_group inspect_cmd_group;extern const struct cmd_group property_cmd_group;extern const struct cmd_group quota_cmd_group;extern const struct cmd_group qgroup_cmd_group; +extern const struct cmd_group dedupe_ib_cmd_group;extern const struct cmd_group replace_cmd_group;extern const struct cmd_group rescue_cmd_group;
@@ -118,6 +119,7 @@ int cmd_send(int argc, char **argv);int cmd_receive (int argc,char **argv);int cmd_quota (int argc,char **argv);int cmd_qgroup (int argc,char **argv); +int cmd_dedupe_ib (int argc,char **argv);int cmd_replace (int argc,char **argv);int cmd_restore (int argc,char **argv);int cmd_select_super (int argc,char **argv);
dedupe-ib.h new file +41 -0
41 lines not on this page · raw message
ioctl.h +21 -0
@@ -503,6 +503,27 @@ struct btrfs_ioctl_get_dev_stats {__u64 unused[128 -2 -BTRFS_DEV_STAT_VALUES_MAX ];/* pad to 1k */ }; +/* +* de-duplication control modes +* For re-config, enable will handle it +*/ +#define BTRFS_DEDUPE_CTL_ENABLE 1 +#define BTRFS_DEDUPE_CTL_DISABLE 2 +#define BTRFS_DEDUPE_CTL_STATUS 3 +#define BTRFS_DEDUPE_CTL_LAST 4 +struct btrfs_ioctl_dedupe_args { +__u16 cmd;/* In: command(see above macro) */ +__u64 blocksize;/* In/Out: For enable/status */ +__u64 limit_nr;/* In/Out: For enable/status */ +__u64 limit_mem;/* In/Out: For enable/status */ +__u64 current_nr;/* Out: For status output */ +__u16 backend;/* In/Out: For enable/status */ +__u16 hash_type;/* In/Out: For enable/status */ +u8 status;/* Out: For status output */ +/* pad to 512 bytes */ +u8 __unused[473 ]; +}; +/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */ #define BTRFS_QUOTA_CTL_ENABLE 1#define BTRFS_QUOTA_CTL_DISABLE 2
Signature · 1 line
2.8.3
PATCH v8 2/4 btrfs-progs: dedupe: Add enable command for dedupe command group
In reply to Qu WenruoAdd enable subcommand for dedupe commmand group.
--- Documentation/btrfs-dedupe-inband.asciidoc | 106 ++++++++++++++++++++- btrfs-completion | 6 +- cmds-dedupe-ib.c | 148 +++++++++++++++++++++++++++++ ioctl.h | 2 + 4 files changed, 260 insertions(+), 2 deletions(-)
Documentation/btrfs-dedupe-inband.asciidoc +105 -1
@@ -22,7 +22,111 @@ use with caution. SUBCOMMAND ---------- -Nothing yet +*enable* [options] <path>:: +Enable in-band de-duplication for a filesystem. ++ +`Options` ++ +-s|--storage-backend <BACKEND>:::: +Specify de-duplication hash storage backend. +Only 'inmemory' backend is supported yet. +If not specified, default value is 'inmemory'. ++ +Refer to *BACKENDS* sector for more information. + +-b|--blocksize <BLOCKSIZE>:::: +Specify dedupe block size. +Supported values are power of 2 from '16K' to '8M'. +Default value is '128K'. ++ +Refer to *BLOCKSIZE* sector for more information. + +-a|--hash-algorithm <HASH>:::: +Specify hash algorithm. +Only 'sha256' is supported yet. + +-l|--limit-hash <LIMIT>:::: +Specify maximum number of hashes stored in memory. +Only works for 'inmemory' backend. +Conflicts with '-m' option. ++ +Only positive values are valid. +Default value is '32K'. + +-m|--limit-memory <LIMIT>:::: +Specify maximum memory used for hashes. +Only works for 'inmemory' backend. +Conflicts with '-l' option. ++ +Only value larger than or equal to '1024' is valid. +No default value. ++ +NOTE: Memory limit will be rounded down to kernel internal hash size, +so the memory limit shown in 'btrfs dedupe status' may be different +from the <LIMIT>. + +WARNING: Too large value for '-l' or '-m' will easily trigger OOM. +Please use with caution according to system memory. + +NOTE: In-band de-duplication is not compactible with compression yet. +And compression has higher priority than in-band de-duplication, means if +compression and de-duplication is enabled at the same time, only compression +will work. + +BACKENDS +-------- +Btrfs in-band de-duplication will support different storage backends, with +different use case and features. + +In-memory backend:: +This backend provides backward-compatibility, and more fine-tuning options. +But hash pool is non-persistent and may exhaust kernel memory if not setup +properly. ++ +This backend can be used on old btrfs(without '-O dedupe' mkfs option). +When used on old btrfs, this backend needs to be enabled manually after mount. ++ +Designed for fast hash search speed, in-memory backend will keep all dedupe +hashes in memory. (Although overall performance is still much the same with +'ondisk' backend if all 'ondisk' hash can be cached in memory) ++ +And only keeps limited number of hash in memory to avoid exhausting memory. +Hashes over the limit will be dropped following Last-Recent-Use behavior. +So this backend has a consistent overhead for given limit but can\'t ensure +all duplicated blocks will be de-duplicated. ++ +After umount and mount, in-memory backend need to refill its hash pool. + +On-disk backend:: +This backend provides persistent hash pool, with more smart memory management +for hash pool. +But it\'s not backward-compatible, meaning it must be used with '-O dedupe' mkfs +option and older kernel can\'t mount it read-write. ++ +Designed for de-duplication rate, hash pool is stored as btrfs B+ tree on disk. +This behavior may cause extra disk IO for hash search under high memory +pressure. ++ +After umount and mount, on-disk backend still has its hash on disk, no need to +refill its dedupe hash pool. + +Currently, only 'inmemory' backend is supported in btrfs-progs. + +DEDUPE BLOCK SIZE +---------------- +In-band de-duplication is done at dedupe block size. +Any data smaller than dedupe block size won\'t go through in-band +de-duplication. + +And dedupe block size affects dedupe rate and fragmentation heavily. + +Smaller block size will cause more fragments, but higher dedupe rate. + +Larger block size will cause less fragments, but lower dedupe rate. + +In-band de-duplication rate is highly related to the workload pattern. +So it\'s highly recommended to align dedupe block size to the workload +block size to make full use of de-duplication. EXIT STATUS -----------
btrfs-completion +5 -1
@@ -29,7 +29,7 @@ _btrfs() local cmd=${words[1]} - commands='subvolume filesystem balance device scrub check rescue restore inspect-internal property send receive quota qgroup replace help version' + commands='subvolume filesystem balance device scrub check rescue restore inspect-internal property send receive quota qgroup dedupe replace help version' commands_subvolume='create delete list snapshot find-new get-default set-default show sync' commands_filesystem='defragment sync resize show df label usage' commands_balance='start pause cancel resume status'
@@ -40,6 +40,7 @@ _btrfs() commands_property='get set list' commands_quota='enable disable rescan' commands_qgroup='assign remove create destroy show limit' + commands_dedupe='enable' commands_replace='start status cancel' if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
@@ -94,6 +95,9 @@ _btrfs() qgroup) opts="$commands_qgroup" ;; + dedupe) + opts="$commands_dedupe" + ;; replace) opts="$commands_replace" ;;
cmds-dedupe-ib.c +148 -0
162 lines not on this page · raw message
ioctl.h +2 -0
@@ -735,6 +735,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_dev_replace_args)#define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \ struct btrfs_ioctl_same_args) +#define BTRFS_IOC_DEDUPE_CTL _IOWR(BTRFS_IOCTL_MAGIC, 55, \ + struct btrfs_ioctl_dedupe_args)#define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ struct btrfs_ioctl_feature_flags)#define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
Signature · 1 line
2.8.3
PATCH v8 3/4 btrfs-progs: dedupe: Add disable support for inband dedupelication
In reply to Qu WenruoAdd disable subcommand for dedupe command group.
--- Documentation/btrfs-dedupe-inband.asciidoc | 5 ++++ btrfs-completion | 2 +- cmds-dedupe-ib.c | 42 ++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-)
Documentation/btrfs-dedupe-inband.asciidoc +5 -0
@@ -22,6 +22,11 @@ use with caution. SUBCOMMAND ---------- +*disable* <path>:: +Disable in-band de-duplication for a filesystem. ++ +This will trash all stored dedupe hash. ++ *enable* [options] <path>:: Enable in-band de-duplication for a filesystem. +
btrfs-completion +1 -1
@@ -40,7 +40,7 @@ _btrfs() commands_property='get set list' commands_quota='enable disable rescan' commands_qgroup='assign remove create destroy show limit' - commands_dedupe='enable' + commands_dedupe='enable disable' commands_replace='start status cancel' if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
cmds-dedupe-ib.c +42 -0
52 lines not on this page · raw message
Signature · 1 line
2.8.3
PATCH v8 4/4 btrfs-progs: dedupe: Add status subcommand
In reply to Qu WenruoAdd status subcommand for dedupe command group.
--- Documentation/btrfs-dedupe-inband.asciidoc | 3 ++ btrfs-completion | 2 +- cmds-dedupe-ib.c | 81 ++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-)
Documentation/btrfs-dedupe-inband.asciidoc +3 -0
@@ -78,6 +78,9 @@ And compression has higher priority than in-band de-duplication, means if compression and de-duplication is enabled at the same time, only compression will work. +*status* <path>:: +Show current in-band de-duplication status of a filesystem. + BACKENDS -------- Btrfs in-band de-duplication will support different storage backends, with
btrfs-completion +1 -1
@@ -40,7 +40,7 @@ _btrfs() commands_property='get set list' commands_quota='enable disable rescan' commands_qgroup='assign remove create destroy show limit' - commands_dedupe='enable disable' + commands_dedupe='enable disable status' commands_replace='start status cancel' if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
cmds-dedupe-ib.c +81 -0
93 lines not on this page · raw message
Signature · 1 line
2.8.3