* [PATCH] Btrfs-progs: add dedup subcommand
2013-05-14 12:08 [RFC PATCH V4 0/2] Online data deduplication Liu Bo
@ 2013-05-14 12:08 ` Liu Bo
0 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-05-14 12:08 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, jbacik, g2p.code
This aims to add deduplication subcommand, 'btrfs dedup command <path>',
ie. register/unregister'.
It can be used to enable or disable dedup support for a filesystem.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
Makefile | 2 +-
btrfs.c | 1 +
cmds-dedup.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
commands.h | 2 +
ctree.h | 2 +
ioctl.h | 5 +++
6 files changed, 112 insertions(+), 1 deletions(-)
create mode 100644 cmds-dedup.c
diff --git a/Makefile b/Makefile
index 9c195b3..c423184 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
- cmds-restore.o
+ cmds-restore.o cmds-dedup.o
libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o
libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
diff --git a/btrfs.c b/btrfs.c
index 691adef..956905c 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -254,6 +254,7 @@ const struct cmd_group btrfs_cmd_group = {
{ "quota", cmd_quota, NULL, "a_cmd_group, 0 },
{ "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 },
{ "replace", cmd_replace, NULL, &replace_cmd_group, 0 },
+ { "dedup", cmd_dedup, NULL, &dedup_cmd_group, 0 },
{ "help", cmd_help, cmd_help_usage, NULL, 0 },
{ "version", cmd_version, cmd_version_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
diff --git a/cmds-dedup.c b/cmds-dedup.c
new file mode 100644
index 0000000..a977585
--- /dev/null
+++ b/cmds-dedup.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2013 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "ctree.h"
+#include "ioctl.h"
+
+#include "commands.h"
+#include "utils.h"
+
+static const char * const dedup_cmd_group_usage[] = {
+ "btrfs dedup <command> [options] <path>",
+ NULL
+};
+
+int dedup_ctl(int cmd, int argc, char **argv)
+{
+ int ret = 0;
+ int fd;
+ int e;
+ char *path = argv[1];
+
+ if (check_argc_exact(argc, 2))
+ return -1;
+
+ fd = open_file_or_dir(path);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return -EACCES;
+ }
+
+ ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, cmd);
+ e = errno;
+ close(fd);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: dedup command failed: %s\n",
+ strerror(e));
+ if (cmd == BTRFS_DEDUP_CTL_UNREG)
+ fprintf(stderr, "please refer to 'dmesg | tail' for more info\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static const char * const cmd_dedup_reg_usage[] = {
+ "btrfs dedup register <path>",
+ "Enable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_reg(int argc, char **argv)
+{
+ int ret = dedup_ctl(BTRFS_DEDUP_CTL_REG, argc, argv);
+ if (ret < 0)
+ usage(cmd_dedup_reg_usage);
+ return ret;
+}
+
+static const char * const cmd_dedup_unreg_usage[] = {
+ "btrfs dedup unregister <path>",
+ "Disable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_unreg(int argc, char **argv)
+{
+ int ret = dedup_ctl(BTRFS_DEDUP_CTL_UNREG, argc, argv);
+ if (ret < 0)
+ usage(cmd_dedup_unreg_usage);
+ return ret;
+}
+
+const struct cmd_group dedup_cmd_group = {
+ dedup_cmd_group_usage, NULL, {
+ { "register", cmd_dedup_reg, cmd_dedup_reg_usage, NULL, 0 },
+ { "unregister", cmd_dedup_unreg, cmd_dedup_unreg_usage, 0, 0 },
+ { 0, 0, 0, 0, 0 }
+ }
+};
+
+int cmd_dedup(int argc, char **argv)
+{
+ return handle_command_group(&dedup_cmd_group, argc, argv);
+}
diff --git a/commands.h b/commands.h
index 15c616d..d31afa4 100644
--- a/commands.h
+++ b/commands.h
@@ -90,6 +90,7 @@ extern const struct cmd_group receive_cmd_group;
extern const struct cmd_group quota_cmd_group;
extern const struct cmd_group qgroup_cmd_group;
extern const struct cmd_group replace_cmd_group;
+extern const struct cmd_group dedup_cmd_group;
extern const char * const cmd_send_usage[];
extern const char * const cmd_receive_usage[];
@@ -112,6 +113,7 @@ int cmd_restore(int argc, char **argv);
int cmd_select_super(int argc, char **argv);
int cmd_dump_super(int argc, char **argv);
int cmd_debug_tree(int argc, char **argv);
+int cmd_dedup(int argc, char **argv);
/* subvolume exported functions */
int test_issubvolume(char *path);
diff --git a/ctree.h b/ctree.h
index 9442e03..903969d 100644
--- a/ctree.h
+++ b/ctree.h
@@ -455,6 +455,7 @@ struct btrfs_super_block {
*/
#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
+#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
@@ -467,6 +468,7 @@ struct btrfs_super_block {
BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
BTRFS_FEATURE_INCOMPAT_RAID56 | \
+ BTRFS_FEATURE_INCOMPAT_DEDUP | \
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
/*
diff --git a/ioctl.h b/ioctl.h
index e841913..106901f 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -384,6 +384,10 @@ struct btrfs_ioctl_send_args {
__u64 reserved[4]; /* in */
};
+/* deduplication control ioctl modes */
+#define BTRFS_DEDUP_CTL_REG 1
+#define BTRFS_DEDUP_CTL_UNREG 2
+
#define BTRFS_QUOTA_CTL_ENABLE 1
#define BTRFS_QUOTA_CTL_DISABLE 2
#define BTRFS_QUOTA_CTL_RESCAN 3
@@ -528,6 +532,7 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_get_dev_stats)
#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
struct btrfs_ioctl_dev_replace_args)
+#define BTRFS_IOC_DEDUP_CTL _IOW(BTRFS_IOCTL_MAGIC, 55, int)
#ifdef __cplusplus
}
--
1.7.7
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH] Btrfs-progs: add dedup subcommand
2013-07-31 15:37 [RFC PATCH v5 0/5] Online " Liu Bo
@ 2013-07-31 15:37 ` Liu Bo
2013-07-31 16:30 ` Stefan Behrens
2013-08-01 22:01 ` Mark Fasheh
0 siblings, 2 replies; 34+ messages in thread
From: Liu Bo @ 2013-07-31 15:37 UTC (permalink / raw)
To: linux-btrfs
This aims to add deduplication subcommand, 'btrfs dedup command <path>',
ie. register/unregister'.
It can be used to enable or disable dedup support for a filesystem.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
Makefile | 2 +-
btrfs.c | 1 +
cmds-dedup.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
commands.h | 2 +
ctree.h | 2 +
ioctl.h | 5 +++
6 files changed, 112 insertions(+), 1 deletions(-)
create mode 100644 cmds-dedup.c
diff --git a/Makefile b/Makefile
index da7438e..5b4a07d 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
- cmds-restore.o
+ cmds-restore.o cmds-dedup.o
libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o
libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
diff --git a/btrfs.c b/btrfs.c
index 691adef..956905c 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -254,6 +254,7 @@ const struct cmd_group btrfs_cmd_group = {
{ "quota", cmd_quota, NULL, "a_cmd_group, 0 },
{ "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 },
{ "replace", cmd_replace, NULL, &replace_cmd_group, 0 },
+ { "dedup", cmd_dedup, NULL, &dedup_cmd_group, 0 },
{ "help", cmd_help, cmd_help_usage, NULL, 0 },
{ "version", cmd_version, cmd_version_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
diff --git a/cmds-dedup.c b/cmds-dedup.c
new file mode 100644
index 0000000..a977585
--- /dev/null
+++ b/cmds-dedup.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2013 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "ctree.h"
+#include "ioctl.h"
+
+#include "commands.h"
+#include "utils.h"
+
+static const char * const dedup_cmd_group_usage[] = {
+ "btrfs dedup <command> [options] <path>",
+ NULL
+};
+
+int dedup_ctl(int cmd, int argc, char **argv)
+{
+ int ret = 0;
+ int fd;
+ int e;
+ char *path = argv[1];
+
+ if (check_argc_exact(argc, 2))
+ return -1;
+
+ fd = open_file_or_dir(path);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return -EACCES;
+ }
+
+ ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, cmd);
+ e = errno;
+ close(fd);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: dedup command failed: %s\n",
+ strerror(e));
+ if (cmd == BTRFS_DEDUP_CTL_UNREG)
+ fprintf(stderr, "please refer to 'dmesg | tail' for more info\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static const char * const cmd_dedup_reg_usage[] = {
+ "btrfs dedup register <path>",
+ "Enable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_reg(int argc, char **argv)
+{
+ int ret = dedup_ctl(BTRFS_DEDUP_CTL_REG, argc, argv);
+ if (ret < 0)
+ usage(cmd_dedup_reg_usage);
+ return ret;
+}
+
+static const char * const cmd_dedup_unreg_usage[] = {
+ "btrfs dedup unregister <path>",
+ "Disable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_unreg(int argc, char **argv)
+{
+ int ret = dedup_ctl(BTRFS_DEDUP_CTL_UNREG, argc, argv);
+ if (ret < 0)
+ usage(cmd_dedup_unreg_usage);
+ return ret;
+}
+
+const struct cmd_group dedup_cmd_group = {
+ dedup_cmd_group_usage, NULL, {
+ { "register", cmd_dedup_reg, cmd_dedup_reg_usage, NULL, 0 },
+ { "unregister", cmd_dedup_unreg, cmd_dedup_unreg_usage, 0, 0 },
+ { 0, 0, 0, 0, 0 }
+ }
+};
+
+int cmd_dedup(int argc, char **argv)
+{
+ return handle_command_group(&dedup_cmd_group, argc, argv);
+}
diff --git a/commands.h b/commands.h
index 15c616d..d31afa4 100644
--- a/commands.h
+++ b/commands.h
@@ -90,6 +90,7 @@ extern const struct cmd_group receive_cmd_group;
extern const struct cmd_group quota_cmd_group;
extern const struct cmd_group qgroup_cmd_group;
extern const struct cmd_group replace_cmd_group;
+extern const struct cmd_group dedup_cmd_group;
extern const char * const cmd_send_usage[];
extern const char * const cmd_receive_usage[];
@@ -112,6 +113,7 @@ int cmd_restore(int argc, char **argv);
int cmd_select_super(int argc, char **argv);
int cmd_dump_super(int argc, char **argv);
int cmd_debug_tree(int argc, char **argv);
+int cmd_dedup(int argc, char **argv);
/* subvolume exported functions */
int test_issubvolume(char *path);
diff --git a/ctree.h b/ctree.h
index 6f086bf..e86ff96 100644
--- a/ctree.h
+++ b/ctree.h
@@ -467,6 +467,7 @@ struct btrfs_super_block {
#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
+#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
@@ -479,6 +480,7 @@ struct btrfs_super_block {
BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
BTRFS_FEATURE_INCOMPAT_RAID56 | \
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
+ BTRFS_FEATURE_INCOMPAT_DEDUP | \
BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
/*
diff --git a/ioctl.h b/ioctl.h
index abe6dd4..fba1898 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -417,6 +417,10 @@ struct btrfs_ioctl_get_dev_stats {
__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
};
+/* deduplication control ioctl modes */
+#define BTRFS_DEDUP_CTL_REG 1
+#define BTRFS_DEDUP_CTL_UNREG 2
+
/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
#define BTRFS_QUOTA_CTL_ENABLE 1
#define BTRFS_QUOTA_CTL_DISABLE 2
@@ -537,6 +541,7 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_get_dev_stats)
#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
struct btrfs_ioctl_dev_replace_args)
+#define BTRFS_IOC_DEDUP_CTL _IOW(BTRFS_IOCTL_MAGIC, 55, int)
#ifdef __cplusplus
}
--
1.7.7
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-07-31 15:37 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
@ 2013-07-31 16:30 ` Stefan Behrens
2013-08-01 10:17 ` Liu Bo
2013-08-01 22:01 ` Mark Fasheh
1 sibling, 1 reply; 34+ messages in thread
From: Stefan Behrens @ 2013-07-31 16:30 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs
On Wed, 31 Jul 2013 23:37:46 +0800, Liu Bo wrote:
> This aims to add deduplication subcommand, 'btrfs dedup command <path>',
> ie. register/unregister'.
>
> It can be used to enable or disable dedup support for a filesystem.
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
> Makefile | 2 +-
> btrfs.c | 1 +
> cmds-dedup.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> commands.h | 2 +
> ctree.h | 2 +
> ioctl.h | 5 +++
> 6 files changed, 112 insertions(+), 1 deletions(-)
> create mode 100644 cmds-dedup.c
No manpage?
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-07-31 16:30 ` Stefan Behrens
@ 2013-08-01 10:17 ` Liu Bo
0 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-08-01 10:17 UTC (permalink / raw)
To: Stefan Behrens; +Cc: linux-btrfs
On Wed, Jul 31, 2013 at 06:30:37PM +0200, Stefan Behrens wrote:
> On Wed, 31 Jul 2013 23:37:46 +0800, Liu Bo wrote:
> > This aims to add deduplication subcommand, 'btrfs dedup command <path>',
> > ie. register/unregister'.
> >
> > It can be used to enable or disable dedup support for a filesystem.
> >
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> > ---
> > Makefile | 2 +-
> > btrfs.c | 1 +
> > cmds-dedup.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > commands.h | 2 +
> > ctree.h | 2 +
> > ioctl.h | 5 +++
> > 6 files changed, 112 insertions(+), 1 deletions(-)
> > create mode 100644 cmds-dedup.c
>
> No manpage?
>
Good reminder, thanks very much.
-liubo
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-07-31 15:37 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
2013-07-31 16:30 ` Stefan Behrens
@ 2013-08-01 22:01 ` Mark Fasheh
2013-08-02 2:29 ` Liu Bo
1 sibling, 1 reply; 34+ messages in thread
From: Mark Fasheh @ 2013-08-01 22:01 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs
On Wed, Jul 31, 2013 at 11:37:46PM +0800, Liu Bo wrote:
> This aims to add deduplication subcommand, 'btrfs dedup command <path>',
> ie. register/unregister'.
>
> It can be used to enable or disable dedup support for a filesystem.
This seems to me like it should be a switch on btrfstune instead of a
subcommand of the btrfs binary.
--Mark
--
Mark Fasheh
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-08-01 22:01 ` Mark Fasheh
@ 2013-08-02 2:29 ` Liu Bo
0 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-08-02 2:29 UTC (permalink / raw)
To: Mark Fasheh; +Cc: linux-btrfs
On Thu, Aug 01, 2013 at 03:01:37PM -0700, Mark Fasheh wrote:
> On Wed, Jul 31, 2013 at 11:37:46PM +0800, Liu Bo wrote:
> > This aims to add deduplication subcommand, 'btrfs dedup command <path>',
> > ie. register/unregister'.
> >
> > It can be used to enable or disable dedup support for a filesystem.
>
> This seems to me like it should be a switch on btrfstune instead of a
> subcommand of the btrfs binary.
btrfstune is designed to play with flags if I understand it correctly.
Dedup is not about flipping a flag, but creating/deleting a tree.
But I'm OK with this idea :)
-liubo
^ permalink raw reply [flat|nested] 34+ messages in thread
* [RFC PATCH v8 00/14] Online(inband) data deduplication
@ 2013-12-30 8:12 Liu Bo
2013-12-30 8:12 ` [PATCH v8 01/14] Btrfs: skip merge part for delayed data refs Liu Bo
` (16 more replies)
0 siblings, 17 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
Hello,
Here is the New Year patch bomb :-)
Data deduplication is a specialized data compression technique for eliminating
duplicate copies of repeating data.[1]
This patch set is also related to "Content based storage" in project ideas[2],
it introduces inband data deduplication for btrfs and dedup/dedupe is for short.
PATCH 1 is a hang fix with deduplication on, but it's also useful without
dedup in practice use.
PATCH 2 and 3 are targetting delayed refs' scalability problems, which are
uncovered by the dedup feature.
PATCH 4 is a speed-up improvement, which is about dedup and quota.
PATCH 5-8 is the preparation work for dedup implementation.
PATCH 9 shows how we implement dedup feature.
PATCH 10 fixes a backref walking bug with dedup.
PATCH 11 fixes a free space bug of dedup extents on error handling.
PATCH 12 adds the ioctl to control dedup feature.
PATCH 13 fixes the metadata ENOSPC problem with dedup which has been there
WAY TOO LONG.
PATCH 14 fixes a race bug on dedup writes.
And there is also a btrfs-progs patch(PATCH 15) which offers all details about
how to control the dedup feature.
I've tested this with xfstests by adding a inline dedup 'enable & on' in xfstests'
mount and scratch_mount.
TODO:
* a bit-to-bit comparison callback.
All comments are welcome!
[1]: http://en.wikipedia.org/wiki/Data_deduplication
[2]: https://btrfs.wiki.kernel.org/index.php/Project_ideas#Content_based_storage
v8:
- fix the race crash of dedup ref again.
- fix the metadata ENOSPC problem with dedup.
v7:
- rebase onto the lastest btrfs
- break a big patch into smaller ones to make reviewers happy.
- kill mount options of dedup and use ioctl method instead.
- fix two crash due to the special dedup ref
For former patch sets:
v6: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27512
v5: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27257
v4: http://thread.gmane.org/gmane.comp.file-systems.btrfs/25751
v3: http://comments.gmane.org/gmane.comp.file-systems.btrfs/25433
v2: http://comments.gmane.org/gmane.comp.file-systems.btrfs/24959
Liu Bo (14):
Btrfs: skip merge part for delayed data refs
Btrfs: improve the delayed refs process in rm case
Btrfs: introduce a head ref rbtree
Btrfs: disable qgroups accounting when quata_enable is 0
Btrfs: introduce dedup tree and relatives
Btrfs: introduce dedup tree operations
Btrfs: introduce dedup state
Btrfs: make ordered extent aware of dedup
Btrfs: online(inband) data dedup
Btrfs: skip dedup reference during backref walking
Btrfs: don't return space for dedup extent
Btrfs: add ioctl of dedup control
Btrfs: fix dedupe 'ENOSPC' problem
Btrfs: fix a crash of dedup ref
fs/btrfs/backref.c | 9 +
fs/btrfs/ctree.c | 2 +-
fs/btrfs/ctree.h | 86 ++++++
fs/btrfs/delayed-ref.c | 161 +++++++----
fs/btrfs/delayed-ref.h | 8 +
fs/btrfs/disk-io.c | 40 +++
fs/btrfs/extent-tree.c | 208 ++++++++++++--
fs/btrfs/extent_io.c | 22 +-
fs/btrfs/extent_io.h | 16 ++
fs/btrfs/file-item.c | 244 +++++++++++++++++
fs/btrfs/inode.c | 635 ++++++++++++++++++++++++++++++++++++++-----
fs/btrfs/ioctl.c | 167 ++++++++++++
fs/btrfs/ordered-data.c | 38 ++-
fs/btrfs/ordered-data.h | 13 +-
fs/btrfs/qgroup.c | 3 +
fs/btrfs/relocation.c | 3 +
fs/btrfs/transaction.c | 4 +-
include/trace/events/btrfs.h | 3 +-
include/uapi/linux/btrfs.h | 11 +
19 files changed, 1501 insertions(+), 172 deletions(-)
--
1.8.2.1
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH v8 01/14] Btrfs: skip merge part for delayed data refs
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 02/14] Btrfs: improve the delayed refs process in rm case Liu Bo
` (15 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
When we have data deduplication on, we'll hang on the merge part
because it needs to verify every queued delayed data refs related to
this disk offset but we may have millions refs.
And in the case of delayed data refs, we don't usually have too much
data refs to merge.
So it's safe to shut it down for data refs.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/delayed-ref.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index e4d467b..b0d5d79 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -320,6 +320,13 @@ void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans,
struct rb_node *node;
u64 seq = 0;
+ /*
+ * We don't have too much refs to merge in the case of delayed data
+ * refs.
+ */
+ if (head->is_data)
+ return;
+
spin_lock(&fs_info->tree_mod_seq_lock);
if (!list_empty(&fs_info->tree_mod_seq_list)) {
struct seq_list *elem;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 02/14] Btrfs: improve the delayed refs process in rm case
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
2013-12-30 8:12 ` [PATCH v8 01/14] Btrfs: skip merge part for delayed data refs Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 03/14] Btrfs: introduce a head ref rbtree Liu Bo
` (14 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
While removing a file with dedup extents, we could have a great number of
delayed refs pending to process, and these refs refer to droping
a ref of the extent, which is of BTRFS_DROP_DELAYED_REF type.
But in order to prevent an extent's ref count from going down to zero when
there still are pending delayed refs, we first select those "adding a ref"
ones, which is of BTRFS_ADD_DELAYED_REF type.
So in removing case, all of our delayed refs are of BTRFS_DROP_DELAYED_REF type,
but we have to walk all the refs issued to the extent to find any
BTRFS_ADD_DELAYED_REF types and end up there is no such thing, and then start
over again to find BTRFS_DROP_DELAYED_REF.
This is really unnecessary, we can improve this by tracking how many
BTRFS_ADD_DELAYED_REF refs we have and search by the right type.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/delayed-ref.c | 10 ++++++++++
fs/btrfs/delayed-ref.h | 3 +++
fs/btrfs/extent-tree.c | 17 ++++++++++++++++-
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index b0d5d79..9596649 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -543,6 +543,10 @@ update_existing_head_ref(struct btrfs_delayed_ref_node *existing,
* update the reference mod on the head to reflect this new operation
*/
existing->ref_mod += update->ref_mod;
+
+ WARN_ON_ONCE(update->ref_mod > 1);
+ if (update->ref_mod == 1)
+ existing_ref->add_cnt++;
}
/*
@@ -604,6 +608,12 @@ static noinline void add_delayed_ref_head(struct btrfs_fs_info *fs_info,
head_ref->must_insert_reserved = must_insert_reserved;
head_ref->is_data = is_data;
+ /* track added ref, more comments in select_delayed_ref() */
+ if (count_mod == 1)
+ head_ref->add_cnt = 1;
+ else
+ head_ref->add_cnt = 0;
+
INIT_LIST_HEAD(&head_ref->cluster);
mutex_init(&head_ref->mutex);
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 70b962c..9377b27 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -84,6 +84,9 @@ struct btrfs_delayed_ref_head {
struct list_head cluster;
struct btrfs_delayed_extent_op *extent_op;
+
+ int add_cnt;
+
/*
* when a new extent is allocated, it is just reserved in memory
* The actual extent isn't inserted into the extent allocation tree
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 009980c..a6fb5fa 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2287,6 +2287,16 @@ select_delayed_ref(struct btrfs_delayed_ref_head *head)
struct rb_node *node;
struct btrfs_delayed_ref_node *ref;
int action = BTRFS_ADD_DELAYED_REF;
+
+ /*
+ * track the count of BTRFS_ADD_DELAYED_REF,
+ * in the case that there's no BTRFS_ADD_DELAYED_REF while there're a
+ * a great number of BTRFS_DROP_DELAYED_REF,
+ * it'll waste time on searching BTRFS_ADD_DELAYED_REF, usually this
+ * happens with dedup enabled.
+ */
+ if (head->add_cnt == 0)
+ action = BTRFS_DROP_DELAYED_REF;
again:
/*
* select delayed ref of type BTRFS_ADD_DELAYED_REF first.
@@ -2301,8 +2311,11 @@ again:
rb_node);
if (ref->bytenr != head->node.bytenr)
break;
- if (ref->action == action)
+ if (ref->action == action) {
+ if (action == BTRFS_ADD_DELAYED_REF)
+ head->add_cnt--;
return ref;
+ }
node = rb_prev(node);
}
if (action == BTRFS_ADD_DELAYED_REF) {
@@ -2378,6 +2391,8 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,
* there are still refs with lower seq numbers in the
* process of being added. Don't run this ref yet.
*/
+ if (ref->action == BTRFS_ADD_DELAYED_REF)
+ locked_ref->add_cnt++;
list_del_init(&locked_ref->cluster);
btrfs_delayed_ref_unlock(locked_ref);
locked_ref = NULL;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 03/14] Btrfs: introduce a head ref rbtree
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
2013-12-30 8:12 ` [PATCH v8 01/14] Btrfs: skip merge part for delayed data refs Liu Bo
2013-12-30 8:12 ` [PATCH v8 02/14] Btrfs: improve the delayed refs process in rm case Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 04/14] Btrfs: disable qgroups accounting when quata_enable is 0 Liu Bo
` (13 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
The way how we process delayed refs is
1) get a bunch of head refs,
2) pick up one head ref,
3) go one node back for any delayed ref updates.
The head ref is also linked in the same rbtree as the delayed ref is,
so in 1) stage, we have to walk one by one including not only head refs, but
delayed refs.
When we have a great number of delayed refs pending to process,
this'll cost time a lot.
Here we introduce a head ref specific rbtree, it only has head refs, so troubles
go away.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/delayed-ref.c | 126 +++++++++++++++++++++++++++++--------------------
fs/btrfs/delayed-ref.h | 5 ++
fs/btrfs/disk-io.c | 3 ++
fs/btrfs/extent-tree.c | 21 ++++++---
fs/btrfs/transaction.c | 4 +-
5 files changed, 99 insertions(+), 60 deletions(-)
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 9596649..9e1a1c9 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -161,35 +161,61 @@ static struct btrfs_delayed_ref_node *tree_insert(struct rb_root *root,
return NULL;
}
+/* insert a new ref to head ref rbtree */
+static struct btrfs_delayed_ref_head *htree_insert(struct rb_root *root,
+ struct rb_node *node)
+{
+ struct rb_node **p = &root->rb_node;
+ struct rb_node *parent_node = NULL;
+ struct btrfs_delayed_ref_head *entry;
+ struct btrfs_delayed_ref_head *ins;
+ u64 bytenr;
+
+ ins = rb_entry(node, struct btrfs_delayed_ref_head, href_node);
+ bytenr = ins->node.bytenr;
+ while (*p) {
+ parent_node = *p;
+ entry = rb_entry(parent_node, struct btrfs_delayed_ref_head,
+ href_node);
+
+ if (bytenr < entry->node.bytenr)
+ p = &(*p)->rb_left;
+ else if (bytenr > entry->node.bytenr)
+ p = &(*p)->rb_right;
+ else
+ return entry;
+ }
+
+ rb_link_node(node, parent_node, p);
+ rb_insert_color(node, root);
+ return NULL;
+}
+
/*
* find an head entry based on bytenr. This returns the delayed ref
* head if it was able to find one, or NULL if nothing was in that spot.
* If return_bigger is given, the next bigger entry is returned if no exact
* match is found.
*/
-static struct btrfs_delayed_ref_node *find_ref_head(struct rb_root *root,
- u64 bytenr,
- struct btrfs_delayed_ref_node **last,
- int return_bigger)
+static struct btrfs_delayed_ref_head *
+find_ref_head(struct rb_root *root, u64 bytenr,
+ struct btrfs_delayed_ref_head **last, int return_bigger)
{
struct rb_node *n;
- struct btrfs_delayed_ref_node *entry;
+ struct btrfs_delayed_ref_head *entry;
int cmp = 0;
again:
n = root->rb_node;
entry = NULL;
while (n) {
- entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node);
- WARN_ON(!entry->in_tree);
+ entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node);
if (last)
*last = entry;
- if (bytenr < entry->bytenr)
+ if (bytenr < entry->node.bytenr)
cmp = -1;
- else if (bytenr > entry->bytenr)
- cmp = 1;
- else if (!btrfs_delayed_ref_is_head(entry))
+ else if (bytenr > entry->node.bytenr)
cmp = 1;
else
cmp = 0;
@@ -203,12 +229,12 @@ again:
}
if (entry && return_bigger) {
if (cmp > 0) {
- n = rb_next(&entry->rb_node);
+ n = rb_next(&entry->href_node);
if (!n)
n = rb_first(root);
- entry = rb_entry(n, struct btrfs_delayed_ref_node,
- rb_node);
- bytenr = entry->bytenr;
+ entry = rb_entry(n, struct btrfs_delayed_ref_head,
+ href_node);
+ bytenr = entry->node.bytenr;
return_bigger = 0;
goto again;
}
@@ -246,6 +272,12 @@ static inline void drop_delayed_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_node *ref)
{
rb_erase(&ref->rb_node, &delayed_refs->root);
+ if (btrfs_delayed_ref_is_head(ref)) {
+ struct btrfs_delayed_ref_head *head;
+
+ head = btrfs_delayed_node_to_head(ref);
+ rb_erase(&head->href_node, &delayed_refs->href_root);
+ }
ref->in_tree = 0;
btrfs_put_delayed_ref(ref);
delayed_refs->num_entries--;
@@ -386,42 +418,35 @@ int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans,
int count = 0;
struct btrfs_delayed_ref_root *delayed_refs;
struct rb_node *node;
- struct btrfs_delayed_ref_node *ref;
- struct btrfs_delayed_ref_head *head;
+ struct btrfs_delayed_ref_head *head = NULL;
delayed_refs = &trans->transaction->delayed_refs;
- if (start == 0) {
- node = rb_first(&delayed_refs->root);
- } else {
- ref = NULL;
- find_ref_head(&delayed_refs->root, start + 1, &ref, 1);
- if (ref) {
- node = &ref->rb_node;
- } else
- node = rb_first(&delayed_refs->root);
+ node = rb_first(&delayed_refs->href_root);
+
+ if (start) {
+ find_ref_head(&delayed_refs->href_root, start + 1, &head, 1);
+ if (head)
+ node = &head->href_node;
}
again:
while (node && count < 32) {
- ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node);
- if (btrfs_delayed_ref_is_head(ref)) {
- head = btrfs_delayed_node_to_head(ref);
- if (list_empty(&head->cluster)) {
- list_add_tail(&head->cluster, cluster);
- delayed_refs->run_delayed_start =
- head->node.bytenr;
- count++;
-
- WARN_ON(delayed_refs->num_heads_ready == 0);
- delayed_refs->num_heads_ready--;
- } else if (count) {
- /* the goal of the clustering is to find extents
- * that are likely to end up in the same extent
- * leaf on disk. So, we don't want them spread
- * all over the tree. Stop now if we've hit
- * a head that was already in use
- */
- break;
- }
+ head = rb_entry(node, struct btrfs_delayed_ref_head, href_node);
+ if (list_empty(&head->cluster)) {
+ list_add_tail(&head->cluster, cluster);
+ delayed_refs->run_delayed_start =
+ head->node.bytenr;
+ count++;
+
+ WARN_ON(delayed_refs->num_heads_ready == 0);
+ delayed_refs->num_heads_ready--;
+ } else if (count) {
+ /* the goal of the clustering is to find extents
+ * that are likely to end up in the same extent
+ * leaf on disk. So, we don't want them spread
+ * all over the tree. Stop now if we've hit
+ * a head that was already in use
+ */
+ break;
}
node = rb_next(node);
}
@@ -433,7 +458,7 @@ again:
* clusters. start from the beginning and try again
*/
start = 0;
- node = rb_first(&delayed_refs->root);
+ node = rb_first(&delayed_refs->href_root);
goto again;
}
return 1;
@@ -629,6 +654,7 @@ static noinline void add_delayed_ref_head(struct btrfs_fs_info *fs_info,
*/
kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
} else {
+ htree_insert(&delayed_refs->href_root, &head_ref->href_node);
delayed_refs->num_heads++;
delayed_refs->num_heads_ready++;
delayed_refs->num_entries++;
@@ -886,14 +912,10 @@ int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
struct btrfs_delayed_ref_head *
btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr)
{
- struct btrfs_delayed_ref_node *ref;
struct btrfs_delayed_ref_root *delayed_refs;
delayed_refs = &trans->transaction->delayed_refs;
- ref = find_ref_head(&delayed_refs->root, bytenr, NULL, 0);
- if (ref)
- return btrfs_delayed_node_to_head(ref);
- return NULL;
+ return find_ref_head(&delayed_refs->href_root, bytenr, NULL, 0);
}
void btrfs_delayed_ref_exit(void)
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 9377b27..6a0295b 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -83,6 +83,8 @@ struct btrfs_delayed_ref_head {
struct list_head cluster;
+ struct rb_node href_node;
+
struct btrfs_delayed_extent_op *extent_op;
int add_cnt;
@@ -121,6 +123,9 @@ struct btrfs_delayed_data_ref {
struct btrfs_delayed_ref_root {
struct rb_root root;
+ /* head ref rbtree */
+ struct rb_root href_root;
+
/* this spin lock protects the rbtree and the entries inside */
spinlock_t lock;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8072cfa..435ef13 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3842,6 +3842,9 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
ref->in_tree = 0;
rb_erase(&ref->rb_node, &delayed_refs->root);
+ if (head)
+ rb_erase(&head->href_node, &delayed_refs->href_root);
+
delayed_refs->num_entries--;
spin_unlock(&delayed_refs->lock);
if (head) {
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a6fb5fa..dc8ea97 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2453,6 +2453,10 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,
ref->in_tree = 0;
rb_erase(&ref->rb_node, &delayed_refs->root);
+ if (btrfs_delayed_ref_is_head(ref)) {
+ rb_erase(&locked_ref->href_node,
+ &delayed_refs->href_root);
+ }
delayed_refs->num_entries--;
if (!btrfs_delayed_ref_is_head(ref)) {
/*
@@ -2655,7 +2659,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
{
struct rb_node *node;
struct btrfs_delayed_ref_root *delayed_refs;
- struct btrfs_delayed_ref_node *ref;
+ struct btrfs_delayed_ref_head *head;
struct list_head cluster;
int ret;
u64 delayed_start;
@@ -2785,18 +2789,18 @@ again:
spin_lock(&delayed_refs->lock);
}
- node = rb_first(&delayed_refs->root);
+ node = rb_first(&delayed_refs->href_root);
if (!node)
goto out;
count = (unsigned long)-1;
while (node) {
- ref = rb_entry(node, struct btrfs_delayed_ref_node,
- rb_node);
- if (btrfs_delayed_ref_is_head(ref)) {
- struct btrfs_delayed_ref_head *head;
+ head = rb_entry(node, struct btrfs_delayed_ref_head,
+ href_node);
+ if (btrfs_delayed_ref_is_head(&head->node)) {
+ struct btrfs_delayed_ref_node *ref;
- head = btrfs_delayed_node_to_head(ref);
+ ref = &head->node;
atomic_inc(&ref->refs);
spin_unlock(&delayed_refs->lock);
@@ -2810,6 +2814,8 @@ again:
btrfs_put_delayed_ref(ref);
cond_resched();
goto again;
+ } else {
+ WARN_ON(1);
}
node = rb_next(node);
}
@@ -5971,6 +5977,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
*/
head->node.in_tree = 0;
rb_erase(&head->node.rb_node, &delayed_refs->root);
+ rb_erase(&head->href_node, &delayed_refs->href_root);
delayed_refs->num_entries--;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index c6a872a..1451637 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -62,7 +62,8 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
WARN_ON(atomic_read(&transaction->use_count) == 0);
if (atomic_dec_and_test(&transaction->use_count)) {
BUG_ON(!list_empty(&transaction->list));
- WARN_ON(transaction->delayed_refs.root.rb_node);
+ WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.root));
+ WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root));
while (!list_empty(&transaction->pending_chunks)) {
struct extent_map *em;
@@ -184,6 +185,7 @@ loop:
cur_trans->start_time = get_seconds();
cur_trans->delayed_refs.root = RB_ROOT;
+ cur_trans->delayed_refs.href_root = RB_ROOT;
cur_trans->delayed_refs.num_entries = 0;
cur_trans->delayed_refs.num_heads_ready = 0;
cur_trans->delayed_refs.num_heads = 0;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 04/14] Btrfs: disable qgroups accounting when quata_enable is 0
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (2 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 03/14] Btrfs: introduce a head ref rbtree Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 05/14] Btrfs: introduce dedup tree and relatives Liu Bo
` (12 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
It's unnecessary to do qgroups accounting without enabling quota.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.c | 2 +-
fs/btrfs/delayed-ref.c | 18 ++++++++++++++----
fs/btrfs/qgroup.c | 3 +++
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 316136b..160fa3e 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -407,7 +407,7 @@ u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
tree_mod_log_write_lock(fs_info);
spin_lock(&fs_info->tree_mod_seq_lock);
- if (!elem->seq) {
+ if (elem && !elem->seq) {
elem->seq = btrfs_inc_tree_mod_seq_major(fs_info);
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
}
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 9e1a1c9..3ec3d08 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -691,8 +691,13 @@ static noinline void add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
ref->is_head = 0;
ref->in_tree = 1;
- if (need_ref_seq(for_cow, ref_root))
- seq = btrfs_get_tree_mod_seq(fs_info, &trans->delayed_ref_elem);
+ if (need_ref_seq(for_cow, ref_root)) {
+ struct seq_list *elem = NULL;
+
+ if (fs_info->quota_enabled)
+ elem = &trans->delayed_ref_elem;
+ seq = btrfs_get_tree_mod_seq(fs_info, elem);
+ }
ref->seq = seq;
full_ref = btrfs_delayed_node_to_tree_ref(ref);
@@ -750,8 +755,13 @@ static noinline void add_delayed_data_ref(struct btrfs_fs_info *fs_info,
ref->is_head = 0;
ref->in_tree = 1;
- if (need_ref_seq(for_cow, ref_root))
- seq = btrfs_get_tree_mod_seq(fs_info, &trans->delayed_ref_elem);
+ if (need_ref_seq(for_cow, ref_root)) {
+ struct seq_list *elem = NULL;
+
+ if (fs_info->quota_enabled)
+ elem = &trans->delayed_ref_elem;
+ seq = btrfs_get_tree_mod_seq(fs_info, elem);
+ }
ref->seq = seq;
full_ref = btrfs_delayed_node_to_data_ref(ref);
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 4e6ef49..1cb58f9 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1188,6 +1188,9 @@ int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans,
{
struct qgroup_update *u;
+ if (!trans->root->fs_info->quota_enabled)
+ return 0;
+
BUG_ON(!trans->delayed_ref_elem.seq);
u = kmalloc(sizeof(*u), GFP_NOFS);
if (!u)
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 05/14] Btrfs: introduce dedup tree and relatives
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (3 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 04/14] Btrfs: disable qgroups accounting when quata_enable is 0 Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 06/14] Btrfs: introduce dedup tree operations Liu Bo
` (11 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
This is a preparation step for online/inband dedup tree.
It introduces dedup tree and its relatives, including hash driver and
some structures.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.h | 73 ++++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/disk-io.c | 36 ++++++++++++++++++++++
fs/btrfs/extent-tree.c | 2 ++
include/trace/events/btrfs.h | 3 +-
4 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 54ab861..0e5718a 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -33,6 +33,7 @@
#include <asm/kmap_types.h>
#include <linux/pagemap.h>
#include <linux/btrfs.h>
+#include <crypto/hash.h>
#include "extent_io.h"
#include "extent_map.h"
#include "async-thread.h"
@@ -101,6 +102,9 @@ struct btrfs_ordered_sum;
/* for storing items that use the BTRFS_UUID_KEY* types */
#define BTRFS_UUID_TREE_OBJECTID 9ULL
+/* dedup tree(experimental) */
+#define BTRFS_DEDUP_TREE_OBJECTID 10ULL
+
/* for storing balance parameters in the root tree */
#define BTRFS_BALANCE_OBJECTID -4ULL
@@ -521,6 +525,7 @@ struct btrfs_super_block {
#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
+#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
#define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
@@ -532,6 +537,7 @@ struct btrfs_super_block {
BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
BTRFS_FEATURE_INCOMPAT_RAID56 | \
BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
+ BTRFS_FEATURE_INCOMPAT_DEDUP | \
BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
/*
@@ -903,6 +909,51 @@ struct btrfs_csum_item {
u8 csum;
} __attribute__ ((__packed__));
+/* dedup */
+enum btrfs_dedup_type {
+ BTRFS_DEDUP_SHA256 = 0,
+ BTRFS_DEDUP_LAST = 1,
+};
+
+static int btrfs_dedup_lens[] = { 4, 0 };
+static int btrfs_dedup_sizes[] = { 32, 0 }; /* 256bit, 32bytes */
+
+struct btrfs_dedup_item {
+ /* disk length of dedup range */
+ __le64 len;
+
+ u8 type;
+ u8 compression;
+ u8 encryption;
+
+ /* spare for later use */
+ __le16 other_encoding;
+
+ /* hash/fingerprints go here */
+} __attribute__ ((__packed__));
+
+struct btrfs_dedup_hash {
+ u64 bytenr;
+ u64 num_bytes;
+
+ /* hash algorithm */
+ int type;
+
+ int compression;
+
+ /* last field is a variable length array of dedup hash */
+ u64 hash[];
+};
+
+static inline int btrfs_dedup_hash_size(int type)
+{
+ WARN_ON((btrfs_dedup_lens[type] * sizeof(u64)) !=
+ btrfs_dedup_sizes[type]);
+
+ return sizeof(struct btrfs_dedup_hash) + btrfs_dedup_sizes[type];
+}
+
+
struct btrfs_dev_stats_item {
/*
* grow this item struct at the end for future enhancements and keep
@@ -1304,6 +1355,7 @@ struct btrfs_fs_info {
struct btrfs_root *dev_root;
struct btrfs_root *fs_root;
struct btrfs_root *csum_root;
+ struct btrfs_root *dedup_root;
struct btrfs_root *quota_root;
struct btrfs_root *uuid_root;
@@ -1655,6 +1707,14 @@ struct btrfs_fs_info {
struct semaphore uuid_tree_rescan_sem;
unsigned int update_uuid_tree_gen:1;
+
+ /* reference to deduplication algorithm driver via cryptoapi */
+ struct crypto_shash *dedup_driver;
+
+ /* dedup blocksize */
+ u64 dedup_bs;
+
+ int dedup_type;
};
/*
@@ -1968,6 +2028,8 @@ struct btrfs_ioctl_defrag_range_args {
*/
#define BTRFS_STRING_ITEM_KEY 253
+#define BTRFS_DEDUP_ITEM_KEY 254
+
/*
* Flags for mount options.
*
@@ -2980,6 +3042,14 @@ static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
return btrfs_item_size(eb, e) - offset;
}
+/* btrfs_dedup_item */
+BTRFS_SETGET_FUNCS(dedup_len, struct btrfs_dedup_item, len, 64);
+BTRFS_SETGET_FUNCS(dedup_compression, struct btrfs_dedup_item, compression, 8);
+BTRFS_SETGET_FUNCS(dedup_encryption, struct btrfs_dedup_item, encryption, 8);
+BTRFS_SETGET_FUNCS(dedup_other_encoding, struct btrfs_dedup_item,
+ other_encoding, 16);
+BTRFS_SETGET_FUNCS(dedup_type, struct btrfs_dedup_item, type, 8);
+
/* btrfs_dev_stats_item */
static inline u64 btrfs_dev_stats_value(struct extent_buffer *eb,
struct btrfs_dev_stats_item *ptr,
@@ -3443,6 +3513,8 @@ static inline int btrfs_need_cleaner_sleep(struct btrfs_root *root)
static inline void free_fs_info(struct btrfs_fs_info *fs_info)
{
+ if (fs_info->dedup_driver)
+ crypto_free_shash(fs_info->dedup_driver);
kfree(fs_info->balance_ctl);
kfree(fs_info->delayed_root);
kfree(fs_info->extent_root);
@@ -3615,6 +3687,7 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
struct bio *bio, u64 file_start, int contig);
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
struct list_head *list, int search_commit);
+
/* inode.c */
struct btrfs_delalloc_work {
struct inode *inode;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 435ef13..2c83de7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -152,6 +152,7 @@ static struct btrfs_lockdep_keyset {
{ .id = BTRFS_FS_TREE_OBJECTID, .name_stem = "fs" },
{ .id = BTRFS_CSUM_TREE_OBJECTID, .name_stem = "csum" },
{ .id = BTRFS_QUOTA_TREE_OBJECTID, .name_stem = "quota" },
+ { .id = BTRFS_DEDUP_TREE_OBJECTID, .name_stem = "dedup" },
{ .id = BTRFS_TREE_LOG_OBJECTID, .name_stem = "log" },
{ .id = BTRFS_TREE_RELOC_OBJECTID, .name_stem = "treloc" },
{ .id = BTRFS_DATA_RELOC_TREE_OBJECTID, .name_stem = "dreloc" },
@@ -1595,6 +1596,9 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
if (location->objectid == BTRFS_UUID_TREE_OBJECTID)
return fs_info->uuid_root ? fs_info->uuid_root :
ERR_PTR(-ENOENT);
+ if (location->objectid == BTRFS_DEDUP_TREE_OBJECTID)
+ return fs_info->dedup_root ? fs_info->dedup_root :
+ ERR_PTR(-ENOENT);
again:
root = btrfs_lookup_fs_root(fs_info, location->objectid);
if (root) {
@@ -2047,6 +2051,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
free_root_extent_buffers(info->csum_root);
free_root_extent_buffers(info->quota_root);
free_root_extent_buffers(info->uuid_root);
+ free_root_extent_buffers(info->dedup_root);
if (chunk_root)
free_root_extent_buffers(info->chunk_root);
}
@@ -2082,6 +2087,19 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info)
}
}
+static struct crypto_shash *
+btrfs_build_dedup_driver(struct btrfs_fs_info *info)
+{
+ switch (info->dedup_type) {
+ case BTRFS_DEDUP_SHA256:
+ return crypto_alloc_shash("sha256", 0, 0);
+ default:
+ pr_err("btrfs: unrecognized dedup type\n");
+ break;
+ }
+ return ERR_PTR(-EINVAL);
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2104,6 +2122,7 @@ int open_ctree(struct super_block *sb,
struct btrfs_root *dev_root;
struct btrfs_root *quota_root;
struct btrfs_root *uuid_root;
+ struct btrfs_root *dedup_root;
struct btrfs_root *log_tree_root;
int ret;
int err = -EINVAL;
@@ -2193,6 +2212,8 @@ int open_ctree(struct super_block *sb,
atomic64_set(&fs_info->tree_mod_seq, 0);
fs_info->sb = sb;
fs_info->max_inline = 8192 * 1024;
+ fs_info->dedup_bs = 0;
+ fs_info->dedup_type = BTRFS_DEDUP_SHA256;
fs_info->metadata_ratio = 0;
fs_info->defrag_inodes = RB_ROOT;
fs_info->free_chunk_space = 0;
@@ -2468,6 +2489,14 @@ int open_ctree(struct super_block *sb,
goto fail_alloc;
}
+ fs_info->dedup_driver = btrfs_build_dedup_driver(fs_info);
+ if (IS_ERR(fs_info->dedup_driver)) {
+ pr_info("BTRFS: Cannot load sha256 driver\n");
+ err = PTR_ERR(fs_info->dedup_driver);
+ fs_info->dedup_driver = NULL;
+ goto fail_alloc;
+ }
+
btrfs_init_workers(&fs_info->generic_worker,
"genwork", 1, NULL);
@@ -2719,6 +2748,13 @@ retry_root_backup:
generation != btrfs_super_uuid_tree_generation(disk_super);
}
+ location.objectid = BTRFS_DEDUP_TREE_OBJECTID;
+ dedup_root = btrfs_read_tree_root(tree_root, &location);
+ if (!IS_ERR(dedup_root)) {
+ dedup_root->track_dirty = 1;
+ fs_info->dedup_root = dedup_root;
+ }
+
fs_info->generation = generation;
fs_info->last_trans_committed = generation;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index dc8ea97..aa40a5e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4759,6 +4759,8 @@ static void init_global_block_rsv(struct btrfs_fs_info *fs_info)
if (fs_info->quota_root)
fs_info->quota_root->block_rsv = &fs_info->global_block_rsv;
fs_info->chunk_root->block_rsv = &fs_info->chunk_block_rsv;
+ if (fs_info->dedup_root)
+ fs_info->dedup_root->block_rsv = &fs_info->global_block_rsv;
update_global_block_rsv(fs_info);
}
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 4832d75..1656581 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -40,6 +40,7 @@ struct extent_buffer;
{ BTRFS_ROOT_TREE_DIR_OBJECTID, "ROOT_TREE_DIR" }, \
{ BTRFS_CSUM_TREE_OBJECTID, "CSUM_TREE" }, \
{ BTRFS_TREE_LOG_OBJECTID, "TREE_LOG" }, \
+ { BTRFS_DEDUP_TREE_OBJECTID, "DEDUP_TREE" }, \
{ BTRFS_QUOTA_TREE_OBJECTID, "QUOTA_TREE" }, \
{ BTRFS_TREE_RELOC_OBJECTID, "TREE_RELOC" }, \
{ BTRFS_UUID_TREE_OBJECTID, "UUID_RELOC" }, \
@@ -48,7 +49,7 @@ struct extent_buffer;
#define show_root_type(obj) \
obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) || \
(obj >= BTRFS_ROOT_TREE_OBJECTID && \
- obj <= BTRFS_QUOTA_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
+ obj <= BTRFS_DEDUP_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
#define BTRFS_GROUP_FLAGS \
{ BTRFS_BLOCK_GROUP_DATA, "DATA"}, \
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 06/14] Btrfs: introduce dedup tree operations
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (4 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 05/14] Btrfs: introduce dedup tree and relatives Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 07/14] Btrfs: introduce dedup state Liu Bo
` (10 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
The operations consist of finding matched items, adding new items and
removing items.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.h | 9 +++
fs/btrfs/file-item.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 219 insertions(+)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0e5718a..52b2843 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3688,6 +3688,15 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
struct list_head *list, int search_commit);
+int noinline_for_stack
+btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash);
+int noinline_for_stack
+btrfs_insert_dedup_extent(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_dedup_hash *hash);
+int noinline_for_stack
+btrfs_free_dedup_extent(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root, u64 hash, u64 bytenr);
/* inode.c */
struct btrfs_delalloc_work {
struct inode *inode;
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 6f38488..fd95692 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -884,3 +884,213 @@ out:
fail_unlock:
goto out;
}
+
+/* 1 means we find one, 0 means we dont. */
+int noinline_for_stack
+btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash)
+{
+ struct btrfs_key key;
+ struct btrfs_path *path;
+ struct extent_buffer *leaf;
+ struct btrfs_root *dedup_root;
+ struct btrfs_dedup_item *item;
+ u64 hash_value;
+ u64 length;
+ u64 dedup_size;
+ int compression;
+ int found = 0;
+ int index;
+ int ret;
+
+ if (!hash) {
+ WARN_ON(1);
+ return 0;
+ }
+ if (!root->fs_info->dedup_root) {
+ WARN(1, KERN_INFO "dedup not enabled\n");
+ return 0;
+ }
+ dedup_root = root->fs_info->dedup_root;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return 0;
+
+ /*
+ * For SHA256 dedup algorithm, we store the last 64bit as the
+ * key.objectid, and the rest in the tree item.
+ */
+ index = btrfs_dedup_lens[hash->type] - 1;
+ dedup_size = btrfs_dedup_sizes[hash->type] - sizeof(u64);
+
+ hash_value = hash->hash[index];
+
+ key.objectid = hash_value;
+ key.offset = (u64)-1;
+ btrfs_set_key_type(&key, BTRFS_DEDUP_ITEM_KEY);
+
+ ret = btrfs_search_slot(NULL, dedup_root, &key, path, 0, 0);
+ if (ret < 0)
+ goto out;
+ if (ret == 0) {
+ WARN_ON(1);
+ goto out;
+ }
+
+prev_slot:
+ /* this will do match checks. */
+ ret = btrfs_previous_item(dedup_root, path, hash_value,
+ BTRFS_DEDUP_ITEM_KEY);
+ if (ret)
+ goto out;
+
+ leaf = path->nodes[0];
+ btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
+ if (key.objectid != hash_value)
+ goto out;
+
+ item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dedup_item);
+ /* disk length of dedup range */
+ length = btrfs_dedup_len(leaf, item);
+
+ compression = btrfs_dedup_compression(leaf, item);
+ if (compression > BTRFS_COMPRESS_TYPES) {
+ WARN_ON(1);
+ goto out;
+ }
+
+ if (btrfs_dedup_type(leaf, item) != hash->type)
+ goto prev_slot;
+
+ if (memcmp_extent_buffer(leaf, hash->hash, (unsigned long)(item + 1),
+ dedup_size)) {
+ pr_info("goto prev\n");
+ goto prev_slot;
+ }
+
+ hash->bytenr = key.offset;
+ hash->num_bytes = length;
+ hash->compression = compression;
+ found = 1;
+out:
+ btrfs_free_path(path);
+ return found;
+}
+
+int noinline_for_stack
+btrfs_insert_dedup_extent(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_dedup_hash *hash)
+{
+ struct btrfs_key key;
+ struct btrfs_path *path;
+ struct extent_buffer *leaf;
+ struct btrfs_root *dedup_root;
+ struct btrfs_dedup_item *dedup_item;
+ u64 ins_size;
+ u64 dedup_size;
+ int index;
+ int ret;
+
+ if (!hash) {
+ WARN_ON(1);
+ return 0;
+ }
+
+ WARN_ON(hash->num_bytes > root->fs_info->dedup_bs);
+
+ if (!root->fs_info->dedup_root) {
+ WARN(1, KERN_INFO "dedup not enabled\n");
+ return 0;
+ }
+ dedup_root = root->fs_info->dedup_root;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ /*
+ * For SHA256 dedup algorithm, we store the last 64bit as the
+ * key.objectid, and the rest in the tree item.
+ */
+ index = btrfs_dedup_lens[hash->type] - 1;
+ dedup_size = btrfs_dedup_sizes[hash->type] - sizeof(u64);
+
+ ins_size = sizeof(*dedup_item) + dedup_size;
+
+ key.objectid = hash->hash[index];
+ key.offset = hash->bytenr;
+ btrfs_set_key_type(&key, BTRFS_DEDUP_ITEM_KEY);
+
+ path->leave_spinning = 1;
+ ret = btrfs_insert_empty_item(trans, dedup_root, path, &key, ins_size);
+ if (ret < 0)
+ goto out;
+ leaf = path->nodes[0];
+
+ dedup_item = btrfs_item_ptr(leaf, path->slots[0],
+ struct btrfs_dedup_item);
+ /* disk length of dedup range */
+ btrfs_set_dedup_len(leaf, dedup_item, hash->num_bytes);
+ btrfs_set_dedup_compression(leaf, dedup_item, hash->compression);
+ btrfs_set_dedup_encryption(leaf, dedup_item, 0);
+ btrfs_set_dedup_other_encoding(leaf, dedup_item, 0);
+ btrfs_set_dedup_type(leaf, dedup_item, hash->type);
+
+ write_extent_buffer(leaf, hash->hash, (unsigned long)(dedup_item + 1),
+ dedup_size);
+
+ btrfs_mark_buffer_dirty(leaf);
+out:
+ WARN_ON(ret == -EEXIST);
+ btrfs_free_path(path);
+ return ret;
+}
+
+int noinline_for_stack
+btrfs_free_dedup_extent(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root, u64 hash, u64 bytenr)
+{
+ struct btrfs_key key;
+ struct btrfs_path *path;
+ struct extent_buffer *leaf;
+ struct btrfs_root *dedup_root;
+ int ret = 0;
+
+ if (!root->fs_info->dedup_root)
+ return 0;
+
+ dedup_root = root->fs_info->dedup_root;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return ret;
+
+ key.objectid = hash;
+ key.offset = bytenr;
+ btrfs_set_key_type(&key, BTRFS_DEDUP_ITEM_KEY);
+
+ ret = btrfs_search_slot(trans, dedup_root, &key, path, -1, 1);
+ if (ret < 0)
+ goto out;
+ if (ret) {
+ WARN_ON(1);
+ ret = -ENOENT;
+ goto out;
+ }
+
+ leaf = path->nodes[0];
+
+ ret = -ENOENT;
+ btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
+ if (btrfs_key_type(&key) != BTRFS_DEDUP_ITEM_KEY)
+ goto out;
+ if (key.objectid != hash || key.offset != bytenr)
+ goto out;
+
+ ret = btrfs_del_item(trans, dedup_root, path);
+ WARN_ON(ret);
+out:
+ btrfs_free_path(path);
+ return ret;
+}
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 07/14] Btrfs: introduce dedup state
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (5 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 06/14] Btrfs: introduce dedup tree operations Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 08/14] Btrfs: make ordered extent aware of dedup Liu Bo
` (9 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
This introduces dedup state and relative operations to mark and unmark
the dedup data range, it'll be used in later patches.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/extent_io.c | 14 ++++++++++++++
fs/btrfs/extent_io.h | 5 +++++
2 files changed, 19 insertions(+)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 8e457fc..54cef32 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1251,6 +1251,20 @@ int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
cached_state, mask);
}
+int set_extent_dedup(struct extent_io_tree *tree, u64 start, u64 end,
+ struct extent_state **cached_state, gfp_t mask)
+{
+ return set_extent_bit(tree, start, end, EXTENT_DEDUP, 0,
+ cached_state, mask);
+}
+
+int clear_extent_dedup(struct extent_io_tree *tree, u64 start, u64 end,
+ struct extent_state **cached_state, gfp_t mask)
+{
+ return clear_extent_bit(tree, start, end, EXTENT_DEDUP, 0, 0,
+ cached_state, mask);
+}
+
/*
* either insert or lock state struct between start and end use mask to tell
* us if waiting is desired.
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 19620c5..5c6a78d 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -20,6 +20,7 @@
#define EXTENT_NEED_WAIT (1 << 13)
#define EXTENT_DAMAGED (1 << 14)
#define EXTENT_NORESERVE (1 << 15)
+#define EXTENT_DEDUP (1 << 16)
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
@@ -227,6 +228,10 @@ int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
struct extent_state **cached_state, gfp_t mask);
int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
struct extent_state **cached_state, gfp_t mask);
+int set_extent_dedup(struct extent_io_tree *tree, u64 start, u64 end,
+ struct extent_state **cached_state, gfp_t mask);
+int clear_extent_dedup(struct extent_io_tree *tree, u64 start, u64 end,
+ struct extent_state **cached_state, gfp_t mask);
int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask);
int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 08/14] Btrfs: make ordered extent aware of dedup
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (6 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 07/14] Btrfs: introduce dedup state Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 09/14] Btrfs: online(inband) data dedup Liu Bo
` (8 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
This adds a dedup flag and dedup hash into ordered extent so that
we can insert dedup extents to dedup tree at endio time.
The benefit is simplicity, we don't need to fall back to cleanup dedup
structures if the write is cancelled for some reasons.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ordered-data.c | 38 ++++++++++++++++++++++++++++++++------
fs/btrfs/ordered-data.h | 13 ++++++++++++-
2 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 69582d5..a61c327 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -183,7 +183,8 @@ static inline struct rb_node *tree_search(struct btrfs_ordered_inode_tree *tree,
*/
static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
u64 start, u64 len, u64 disk_len,
- int type, int dio, int compress_type)
+ int type, int dio, int compress_type,
+ int dedup, struct btrfs_dedup_hash *hash)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_ordered_inode_tree *tree;
@@ -199,10 +200,23 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
entry->start = start;
entry->len = len;
if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) &&
- !(type == BTRFS_ORDERED_NOCOW))
+ !(type == BTRFS_ORDERED_NOCOW) && !dedup)
entry->csum_bytes_left = disk_len;
entry->disk_len = disk_len;
entry->bytes_left = len;
+ entry->dedup = dedup;
+ entry->hash = NULL;
+
+ if (!dedup && hash) {
+ entry->hash = kzalloc(btrfs_dedup_hash_size(hash->type),
+ GFP_NOFS);
+ if (!entry->hash) {
+ kmem_cache_free(btrfs_ordered_extent_cache, entry);
+ return -ENOMEM;
+ }
+ memcpy(entry->hash, hash, btrfs_dedup_hash_size(hash->type));
+ }
+
entry->inode = igrab(inode);
entry->compress_type = compress_type;
entry->truncated_len = (u64)-1;
@@ -251,7 +265,17 @@ int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
{
return __btrfs_add_ordered_extent(inode, file_offset, start, len,
disk_len, type, 0,
- BTRFS_COMPRESS_NONE);
+ BTRFS_COMPRESS_NONE, 0, NULL);
+}
+
+int btrfs_add_ordered_extent_dedup(struct inode *inode, u64 file_offset,
+ u64 start, u64 len, u64 disk_len, int type,
+ int dedup, struct btrfs_dedup_hash *hash,
+ int compress_type)
+{
+ return __btrfs_add_ordered_extent(inode, file_offset, start, len,
+ disk_len, type, 0,
+ compress_type, dedup, hash);
}
int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
@@ -259,16 +283,17 @@ int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
{
return __btrfs_add_ordered_extent(inode, file_offset, start, len,
disk_len, type, 1,
- BTRFS_COMPRESS_NONE);
+ BTRFS_COMPRESS_NONE, 0, NULL);
}
int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset,
u64 start, u64 len, u64 disk_len,
- int type, int compress_type)
+ int type, int compress_type,
+ struct btrfs_dedup_hash *hash)
{
return __btrfs_add_ordered_extent(inode, file_offset, start, len,
disk_len, type, 0,
- compress_type);
+ compress_type, 0, hash);
}
/*
@@ -501,6 +526,7 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
list_del(&sum->list);
kfree(sum);
}
+ kfree(entry->hash);
kmem_cache_free(btrfs_ordered_extent_cache, entry);
}
}
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 9b0450f..75f3ec2 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -109,6 +109,9 @@ struct btrfs_ordered_extent {
/* compression algorithm */
int compress_type;
+ /* whether this ordered extent is marked for dedup or not */
+ int dedup;
+
/* reference count */
atomic_t refs;
@@ -135,6 +138,9 @@ struct btrfs_ordered_extent {
struct completion completion;
struct btrfs_work flush_work;
struct list_head work_list;
+
+ /* dedup hash of sha256 type */
+ struct btrfs_dedup_hash *hash;
};
/*
@@ -168,11 +174,16 @@ int btrfs_dec_test_first_ordered_pending(struct inode *inode,
int uptodate);
int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
u64 start, u64 len, u64 disk_len, int type);
+int btrfs_add_ordered_extent_dedup(struct inode *inode, u64 file_offset,
+ u64 start, u64 len, u64 disk_len, int type,
+ int dedup, struct btrfs_dedup_hash *hash,
+ int compress_type);
int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
u64 start, u64 len, u64 disk_len, int type);
int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset,
u64 start, u64 len, u64 disk_len,
- int type, int compress_type);
+ int type, int compress_type,
+ struct btrfs_dedup_hash *hash);
void btrfs_add_ordered_sum(struct inode *inode,
struct btrfs_ordered_extent *entry,
struct btrfs_ordered_sum *sum);
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 09/14] Btrfs: online(inband) data dedup
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (7 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 08/14] Btrfs: make ordered extent aware of dedup Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 10/14] Btrfs: skip dedup reference during backref walking Liu Bo
` (7 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
The main part of data dedup.
This introduces a FORMAT CHANGE.
Btrfs provides online(inband/synchronous) and block-level dedup.
It maps naturally to btrfs's block back-reference, which enables us
to store multiple copies of data as single copy with references
on that copy.
The workflow is
(1) write some data,
(2) get the hash of these data based on btrfs's dedup blocksize.
(3) find matched extents by hash and decide whether to mark it
as a duplicate one or not. If no, write the data onto disk,
otherwise, add a reference to the matched extent.
Btrfs's built-in dedup supports normal writes and compressed writes.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/extent-tree.c | 150 ++++++++++--
fs/btrfs/extent_io.c | 8 +-
fs/btrfs/extent_io.h | 11 +
fs/btrfs/inode.c | 640 +++++++++++++++++++++++++++++++++++++++++++------
4 files changed, 712 insertions(+), 97 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index aa40a5e..f14db92 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1119,8 +1119,16 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
key.offset = parent;
} else {
key.type = BTRFS_EXTENT_DATA_REF_KEY;
- key.offset = hash_extent_data_ref(root_objectid,
- owner, offset);
+
+ /*
+ * we've not got the right offset and owner, so search by -1
+ * here.
+ */
+ if (root_objectid == BTRFS_DEDUP_TREE_OBJECTID)
+ key.offset = (u64)-1;
+ else
+ key.offset = hash_extent_data_ref(root_objectid,
+ owner, offset);
}
again:
recow = 0;
@@ -1147,6 +1155,10 @@ again:
goto fail;
}
+ if (ret > 0 && root_objectid == BTRFS_DEDUP_TREE_OBJECTID &&
+ path->slots[0] > 0)
+ path->slots[0]--;
+
leaf = path->nodes[0];
nritems = btrfs_header_nritems(leaf);
while (1) {
@@ -1170,14 +1182,22 @@ again:
ref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_extent_data_ref);
- if (match_extent_data_ref(leaf, ref, root_objectid,
- owner, offset)) {
- if (recow) {
- btrfs_release_path(path);
- goto again;
+ if (root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ if (btrfs_extent_data_ref_root(leaf, ref) ==
+ root_objectid) {
+ err = 0;
+ break;
+ }
+ } else {
+ if (match_extent_data_ref(leaf, ref, root_objectid,
+ owner, offset)) {
+ if (recow) {
+ btrfs_release_path(path);
+ goto again;
+ }
+ err = 0;
+ break;
}
- err = 0;
- break;
}
path->slots[0]++;
}
@@ -1321,6 +1341,32 @@ static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
return ret;
}
+static noinline u64 extent_data_ref_offset(struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct btrfs_extent_inline_ref *iref)
+{
+ struct btrfs_key key;
+ struct extent_buffer *leaf;
+ struct btrfs_extent_data_ref *ref1;
+ u64 offset = 0;
+
+ leaf = path->nodes[0];
+ btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
+ if (iref) {
+ WARN_ON(btrfs_extent_inline_ref_type(leaf, iref) !=
+ BTRFS_EXTENT_DATA_REF_KEY);
+ ref1 = (struct btrfs_extent_data_ref *)(&iref->offset);
+ offset = btrfs_extent_data_ref_offset(leaf, ref1);
+ } else if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
+ ref1 = btrfs_item_ptr(leaf, path->slots[0],
+ struct btrfs_extent_data_ref);
+ offset = btrfs_extent_data_ref_offset(leaf, ref1);
+ } else {
+ WARN_ON(1);
+ }
+ return offset;
+}
+
static noinline u32 extent_data_ref_count(struct btrfs_root *root,
struct btrfs_path *path,
struct btrfs_extent_inline_ref *iref)
@@ -1587,7 +1633,8 @@ again:
err = -ENOENT;
while (1) {
if (ptr >= end) {
- WARN_ON(ptr > end);
+ WARN_ON(ptr > end &&
+ root_objectid != BTRFS_DEDUP_TREE_OBJECTID);
break;
}
iref = (struct btrfs_extent_inline_ref *)ptr;
@@ -1602,14 +1649,25 @@ again:
if (type == BTRFS_EXTENT_DATA_REF_KEY) {
struct btrfs_extent_data_ref *dref;
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
- if (match_extent_data_ref(leaf, dref, root_objectid,
- owner, offset)) {
- err = 0;
- break;
+
+ if (root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ if (btrfs_extent_data_ref_root(leaf, dref) ==
+ root_objectid) {
+ err = 0;
+ break;
+ }
+ } else {
+ if (match_extent_data_ref(leaf, dref,
+ root_objectid, owner,
+ offset)) {
+ err = 0;
+ break;
+ }
+ if (hash_extent_data_ref_item(leaf, dref) <
+ hash_extent_data_ref(root_objectid, owner,
+ offset))
+ break;
}
- if (hash_extent_data_ref_item(leaf, dref) <
- hash_extent_data_ref(root_objectid, owner, offset))
- break;
} else {
u64 ref_offset;
ref_offset = btrfs_extent_inline_ref_offset(leaf, iref);
@@ -5686,11 +5744,13 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
struct btrfs_extent_inline_ref *iref;
int ret;
int is_data;
- int extent_slot = 0;
- int found_extent = 0;
- int num_to_del = 1;
+ int extent_slot;
+ int found_extent;
+ int num_to_del;
u32 item_size;
u64 refs;
+ u64 orig_root_obj;
+ u64 dedup_hash;
bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
SKINNY_METADATA);
@@ -5698,6 +5758,13 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
if (!path)
return -ENOMEM;
+again:
+ extent_slot = 0;
+ found_extent = 0;
+ num_to_del = 1;
+ orig_root_obj = root_objectid;
+ dedup_hash = 0;
+
path->reada = 1;
path->leave_spinning = 1;
@@ -5739,6 +5806,12 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
#endif
if (!found_extent) {
BUG_ON(iref);
+
+ if (is_data &&
+ root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ dedup_hash = extent_data_ref_offset(root, path,
+ NULL);
+ }
ret = remove_extent_backref(trans, extent_root, path,
NULL, refs_to_drop,
is_data);
@@ -5796,6 +5869,10 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
}
extent_slot = path->slots[0];
}
+ } else if (ret == -ENOENT &&
+ root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ ret = 0;
+ goto out;
} else if (WARN_ON(ret == -ENOENT)) {
btrfs_print_leaf(extent_root, path->nodes[0]);
btrfs_err(info,
@@ -5888,7 +5965,28 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
}
add_pinned_bytes(root->fs_info, -num_bytes, owner_objectid,
root_objectid);
+
+ /*
+ * special case for dedup
+ *
+ * We assume the last ref(ref==1) is backref pointing to dedup.
+ *
+ * root_obj == 1 means that it's a free space cache inode,
+ * and it always uses PREALLOC, so it never has dedup extent.
+ */
+ if (is_data && refs == 1 &&
+ orig_root_obj != BTRFS_ROOT_TREE_OBJECTID) {
+ btrfs_release_path(path);
+ root_objectid = BTRFS_DEDUP_TREE_OBJECTID;
+ parent = 0;
+
+ goto again;
+ }
} else {
+ if (!dedup_hash && is_data &&
+ root_objectid == BTRFS_DEDUP_TREE_OBJECTID)
+ dedup_hash = extent_data_ref_offset(root, path, iref);
+
if (found_extent) {
BUG_ON(is_data && refs_to_drop !=
extent_data_ref_count(root, path, iref));
@@ -5915,6 +6013,18 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
btrfs_abort_transaction(trans, extent_root, ret);
goto out;
}
+
+ if (root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ ret = btrfs_free_dedup_extent(trans, root,
+ dedup_hash,
+ bytenr);
+ if (ret) {
+ btrfs_abort_transaction(trans,
+ extent_root,
+ ret);
+ goto out;
+ }
+ }
}
ret = update_block_group(root, bytenr, num_bytes, 0);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 54cef32..cd319e8 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2354,7 +2354,7 @@ int end_extent_writepage(struct page *page, int err, u64 start, u64 end)
* Scheduling is not allowed, so the extent state tree is expected
* to have one and only one object corresponding to this IO.
*/
-static void end_bio_extent_writepage(struct bio *bio, int err)
+void end_bio_extent_writepage(struct bio *bio, int err)
{
struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
struct extent_io_tree *tree;
@@ -2605,8 +2605,8 @@ struct bio *btrfs_io_bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
}
-static int __must_check submit_one_bio(int rw, struct bio *bio,
- int mirror_num, unsigned long bio_flags)
+int __must_check submit_one_bio(int rw, struct bio *bio, int mirror_num,
+ unsigned long bio_flags)
{
int ret = 0;
struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
@@ -2645,7 +2645,7 @@ static int merge_bio(int rw, struct extent_io_tree *tree, struct page *page,
}
-static int submit_extent_page(int rw, struct extent_io_tree *tree,
+int submit_extent_page(int rw, struct extent_io_tree *tree,
struct page *page, sector_t sector,
size_t size, unsigned long offset,
struct block_device *bdev,
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 5c6a78d..1825901 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -350,6 +350,17 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
int mirror_num);
+int submit_extent_page(int rw, struct extent_io_tree *tree, struct page *page,
+ sector_t sector, size_t size, unsigned long offset,
+ struct block_device *bdev, struct bio **bio_ret,
+ unsigned long max_pages, bio_end_io_t end_io_func,
+ int mirror_num, unsigned long prev_bio_flags,
+ unsigned long bio_flags);
+void end_bio_extent_writepage(struct bio *bio, int err);
+int __must_check submit_one_bio(int rw, struct bio *bio, int mirror_num,
+ unsigned long bio_flags);
+
+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
noinline u64 find_lock_delalloc_range(struct inode *inode,
struct extent_io_tree *tree,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f1a7744..3a221bb 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -43,6 +43,7 @@
#include <linux/btrfs.h>
#include <linux/blkdev.h>
#include <linux/posix_acl_xattr.h>
+#include <asm/unaligned.h>
#include "ctree.h"
#include "disk-io.h"
#include "transaction.h"
@@ -104,6 +105,17 @@ static struct extent_map *create_pinned_em(struct inode *inode, u64 start,
u64 block_start, u64 block_len,
u64 orig_block_len, u64 ram_bytes,
int type);
+static noinline int cow_file_range_dedup(struct inode *inode,
+ struct page *locked_page,
+ u64 start, u64 end, int *page_started,
+ unsigned long *nr_written, int unlock,
+ struct btrfs_dedup_hash *hash);
+static int run_locked_range(struct extent_io_tree *tree, struct inode *inode,
+ struct page *locked_page, u64 start, u64 end,
+ get_extent_t *get_extent, int mode,
+ struct btrfs_dedup_hash *hash);
+static int btrfs_inode_test_compress(struct inode *inode);
+
static int btrfs_dirty_inode(struct inode *inode);
@@ -296,6 +308,7 @@ struct async_extent {
unsigned long nr_pages;
int compress_type;
struct list_head list;
+ struct btrfs_dedup_hash *hash; /* dedup hash of sha256 */
};
struct async_cow {
@@ -313,22 +326,41 @@ static noinline int add_async_extent(struct async_cow *cow,
u64 compressed_size,
struct page **pages,
unsigned long nr_pages,
- int compress_type)
+ int compress_type,
+ struct btrfs_dedup_hash *h)
{
struct async_extent *async_extent;
async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS);
- BUG_ON(!async_extent); /* -ENOMEM */
+ if (!async_extent)
+ return -ENOMEM;
async_extent->start = start;
async_extent->ram_size = ram_size;
async_extent->compressed_size = compressed_size;
async_extent->pages = pages;
async_extent->nr_pages = nr_pages;
async_extent->compress_type = compress_type;
+ async_extent->hash = NULL;
+ if (h) {
+ async_extent->hash = kmalloc(btrfs_dedup_hash_size(h->type),
+ GFP_NOFS);
+ if (!async_extent->hash) {
+ kfree(async_extent);
+ return -ENOMEM;
+ }
+ memcpy(async_extent->hash, h, btrfs_dedup_hash_size(h->type));
+ }
+
list_add_tail(&async_extent->list, &cow->extents);
return 0;
}
+static noinline void free_async_extent(struct async_extent *p)
+{
+ kfree(p->hash);
+ kfree(p);
+}
+
/*
* we create compressed extents in two phases. The first
* phase compresses a range of pages that have already been
@@ -350,7 +382,8 @@ static noinline int compress_file_range(struct inode *inode,
struct page *locked_page,
u64 start, u64 end,
struct async_cow *async_cow,
- int *num_added)
+ int *num_added,
+ struct btrfs_dedup_hash *dedup_hash)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
u64 num_bytes;
@@ -418,9 +451,7 @@ again:
* change at any time if we discover bad compression ratios.
*/
if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) &&
- (btrfs_test_opt(root, COMPRESS) ||
- (BTRFS_I(inode)->force_compress) ||
- (BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS))) {
+ btrfs_inode_test_compress(inode)) {
WARN_ON(pages);
pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
if (!pages) {
@@ -548,9 +579,11 @@ cont:
* allocation on disk for these compressed pages,
* and will submit them to the elevator.
*/
- add_async_extent(async_cow, start, num_bytes,
- total_compressed, pages, nr_pages_ret,
- compress_type);
+ ret = add_async_extent(async_cow, start, num_bytes,
+ total_compressed, pages, nr_pages_ret,
+ compress_type, dedup_hash);
+ if (ret)
+ goto free_pages_out;
if (start + num_bytes < end) {
start += num_bytes;
@@ -574,8 +607,11 @@ cleanup_and_bail_uncompressed:
}
if (redirty)
extent_range_redirty_for_io(inode, start, end);
- add_async_extent(async_cow, start, end - start + 1,
- 0, NULL, 0, BTRFS_COMPRESS_NONE);
+ ret = add_async_extent(async_cow, start, end - start + 1,
+ 0, NULL, 0, BTRFS_COMPRESS_NONE, dedup_hash);
+ if (ret)
+ goto free_pages_out;
+
*num_added += 1;
}
@@ -624,38 +660,15 @@ again:
retry:
/* did the compression code fall back to uncompressed IO? */
if (!async_extent->pages) {
- int page_started = 0;
- unsigned long nr_written = 0;
-
- lock_extent(io_tree, async_extent->start,
- async_extent->start +
- async_extent->ram_size - 1);
-
- /* allocate blocks */
- ret = cow_file_range(inode, async_cow->locked_page,
- async_extent->start,
- async_extent->start +
- async_extent->ram_size - 1,
- &page_started, &nr_written, 0);
-
- /* JDM XXX */
+ ret = run_locked_range(io_tree, inode,
+ async_cow->locked_page,
+ async_extent->start,
+ async_extent->start +
+ async_extent->ram_size - 1,
+ btrfs_get_extent, WB_SYNC_ALL,
+ async_extent->hash);
- /*
- * if page_started, cow_file_range inserted an
- * inline extent and took care of all the unlocking
- * and IO for us. Otherwise, we need to submit
- * all those pages down to the drive.
- */
- if (!page_started && !ret)
- extent_write_locked_range(io_tree,
- inode, async_extent->start,
- async_extent->start +
- async_extent->ram_size - 1,
- btrfs_get_extent,
- WB_SYNC_ALL);
- else if (ret)
- unlock_page(async_cow->locked_page);
- kfree(async_extent);
+ free_async_extent(async_extent);
cond_resched();
continue;
}
@@ -738,7 +751,8 @@ retry:
async_extent->ram_size,
ins.offset,
BTRFS_ORDERED_COMPRESSED,
- async_extent->compress_type);
+ async_extent->compress_type,
+ async_extent->hash);
if (ret)
goto out_free_reserve;
@@ -758,7 +772,7 @@ retry:
ins.offset, async_extent->pages,
async_extent->nr_pages);
alloc_hint = ins.objectid + ins.offset;
- kfree(async_extent);
+ free_async_extent(async_extent);
if (ret)
goto out;
cond_resched();
@@ -776,10 +790,366 @@ out_free:
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK);
- kfree(async_extent);
+ free_async_extent(async_extent);
goto again;
}
+static void btrfs_dedup_hash_final(struct btrfs_dedup_hash *hash);
+
+static int btrfs_dedup_hash_digest(struct btrfs_root *root, const char *data,
+ u64 length, struct btrfs_dedup_hash *hash)
+{
+ struct crypto_shash *tfm = root->fs_info->dedup_driver;
+ struct {
+ struct shash_desc desc;
+ char ctx[crypto_shash_descsize(tfm)];
+ } sdesc;
+ int ret;
+
+ sdesc.desc.tfm = tfm;
+ sdesc.desc.flags = 0;
+
+ ret = crypto_shash_digest(&sdesc.desc, data, length,
+ (char *)(hash->hash));
+ if (!ret)
+ btrfs_dedup_hash_final(hash);
+ return ret;
+}
+
+static void btrfs_dedup_hash_final(struct btrfs_dedup_hash *hash)
+{
+ int num, i;
+
+ num = btrfs_dedup_lens[hash->type] - 1;
+ for (i = 0; i < num; i++)
+ put_unaligned_le64(hash->hash[i], (char *)(hash->hash + i));
+}
+
+static int btrfs_calc_dedup_hash(struct btrfs_root *root, struct inode *inode,
+ u64 start, struct btrfs_dedup_hash *hash)
+{
+ struct page *p;
+ char *data;
+ u64 length = root->fs_info->dedup_bs;
+ u64 blocksize = root->sectorsize;
+ int err;
+
+ if (length == blocksize) {
+ p = find_get_page(inode->i_mapping,
+ (start >> PAGE_CACHE_SHIFT));
+ WARN_ON(!p); /* page should be here */
+ data = kmap_atomic(p);
+ err = btrfs_dedup_hash_digest(root, data, length, hash);
+ kunmap_atomic(data);
+ page_cache_release(p);
+ } else {
+ char *d;
+ int i = 0;
+
+ data = kmalloc(length, GFP_NOFS);
+ if (!data)
+ return -ENOMEM;
+
+ while (blocksize * i < length) {
+ p = find_get_page(inode->i_mapping,
+ (start >> PAGE_CACHE_SHIFT) + i);
+ WARN_ON(!p); /* page should be here */
+ d = kmap_atomic(p);
+ memcpy((data + blocksize * i), d, blocksize);
+ kunmap_atomic(d);
+ page_cache_release(p);
+ i++;
+ }
+
+ err = btrfs_dedup_hash_digest(root, data, length, hash);
+ kfree(data);
+ }
+ return err;
+}
+
+static noinline int
+run_delalloc_dedup(struct inode *inode, struct page *locked_page, u64 start,
+ u64 end, struct async_cow *async_cow)
+{
+ struct btrfs_root *root = BTRFS_I(inode)->root;
+ struct bio *bio = NULL;
+ struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
+ struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
+ struct extent_map *em;
+ struct page *page = NULL;
+ struct block_device *bdev;
+ struct btrfs_key ins;
+ u64 blocksize = root->sectorsize;
+ u64 num_bytes;
+ u64 cur_alloc_size;
+ u64 cur_end;
+ u64 alloc_hint = 0;
+ u64 iosize;
+ u64 dedup_bs = root->fs_info->dedup_bs;
+ int compr;
+ int found;
+ int type = 0;
+ sector_t sector;
+ int ret = 0;
+ struct extent_state *cached_state = NULL;
+ struct btrfs_dedup_hash *hash;
+ int dedup_type = root->fs_info->dedup_type;
+
+ WARN_ON(btrfs_is_free_space_inode(inode));
+
+ num_bytes = ALIGN(end - start + 1, blocksize);
+ num_bytes = max(blocksize, num_bytes);
+
+ hash = kzalloc(btrfs_dedup_hash_size(dedup_type), GFP_NOFS);
+ if (!hash) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0);
+
+ while (num_bytes > 0) {
+ unsigned long op = 0;
+
+ /* page has been locked by caller */
+ page = find_get_page(inode->i_mapping,
+ start >> PAGE_CACHE_SHIFT);
+ WARN_ON(!page); /* page should be here */
+
+ /* already ordered? */
+ if (PagePrivate2(page))
+ goto submit;
+
+ /* too small data, go for normal path */
+ if (num_bytes < dedup_bs) {
+ cur_end = start + num_bytes - 1;
+
+ if (btrfs_inode_test_compress(inode)) {
+ int num_added = 0;
+ compress_file_range(inode, page, start, cur_end,
+ async_cow, &num_added,
+ NULL);
+ } else {
+ /* Now locked_page is not dirty. */
+ if (page_offset(locked_page) >= start &&
+ page_offset(locked_page) <= cur_end) {
+ __set_page_dirty_nobuffers(locked_page);
+ }
+
+ ret = run_locked_range(tree, inode, page, start,
+ cur_end,
+ btrfs_get_extent,
+ WB_SYNC_ALL, NULL);
+ if (ret)
+ SetPageError(page);
+ }
+
+ page_cache_release(page);
+ page = NULL;
+
+ num_bytes -= num_bytes;
+ start += num_bytes;
+ cond_resched();
+ continue;
+ }
+
+ cur_alloc_size = min_t(u64, num_bytes, dedup_bs);
+ WARN_ON(cur_alloc_size < dedup_bs); /* shouldn't happen */
+ cur_end = start + cur_alloc_size - 1;
+
+ /* see comments in compress_file_range */
+ extent_range_clear_dirty_for_io(inode, start, cur_end);
+
+ memset(hash, 0, btrfs_dedup_hash_size(dedup_type));
+ hash->type = dedup_type;
+
+ ret = btrfs_calc_dedup_hash(root, inode, start, hash);
+
+ if (ret) {
+ found = 0;
+ compr = BTRFS_COMPRESS_NONE;
+ } else {
+ found = btrfs_find_dedup_extent(root, hash);
+ compr = hash->compression;
+ }
+
+ if (found == 0) {
+ /*
+ * compress fastpath.
+ * so we take the original data as dedup string instead
+ * of compressed data since compression methods and data
+ * from them vary a lot.
+ */
+ if (btrfs_inode_test_compress(inode)) {
+ int num_added = 0;
+
+ extent_range_redirty_for_io(inode, start,
+ cur_end);
+
+ compress_file_range(inode, page, start, cur_end,
+ async_cow, &num_added,
+ hash);
+
+ page_cache_release(page);
+ page = NULL;
+
+ num_bytes -= cur_alloc_size;
+ start += cur_alloc_size;
+ cond_resched();
+ continue;
+ }
+
+ /* no compress */
+ ret = btrfs_reserve_extent(root, cur_alloc_size,
+ cur_alloc_size, 0, alloc_hint,
+ &ins, 1);
+ if (ret < 0)
+ goto out_unlock;
+ } else { /* found same hash */
+ ins.objectid = hash->bytenr;
+ ins.offset = hash->num_bytes;
+
+ set_extent_dedup(tree, start, cur_end, &cached_state,
+ GFP_NOFS);
+ }
+
+ lock_extent(tree, start, cur_end);
+
+ em = alloc_extent_map();
+ if (!em) {
+ ret = -ENOMEM;
+ goto out_reserve;
+ }
+ em->start = start;
+ em->orig_start = em->start;
+ em->len = cur_alloc_size;
+ em->mod_start = em->start;
+ em->mod_len = em->len;
+
+ em->block_start = ins.objectid;
+ em->block_len = ins.offset;
+ em->orig_block_len = ins.offset;
+ em->bdev = root->fs_info->fs_devices->latest_bdev;
+ set_bit(EXTENT_FLAG_PINNED, &em->flags);
+ em->generation = -1;
+ if (compr > BTRFS_COMPRESS_NONE) {
+ em->compress_type = compr;
+ set_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
+ type = BTRFS_ORDERED_COMPRESSED;
+ }
+
+ while (1) {
+ write_lock(&em_tree->lock);
+ ret = add_extent_mapping(em_tree, em, 1);
+ write_unlock(&em_tree->lock);
+ if (ret != -EEXIST) {
+ free_extent_map(em);
+ break;
+ }
+ btrfs_drop_extent_cache(inode, start, cur_end, 0);
+ }
+ if (ret)
+ goto out_reserve;
+
+ ret = btrfs_add_ordered_extent_dedup(inode, start, ins.objectid,
+ cur_alloc_size, ins.offset,
+ type, found, hash, compr);
+ if (ret)
+ goto out_reserve;
+
+ /*
+ * Do set the Private2 bit so we know this page was properly
+ * setup for writepage
+ */
+ op |= PAGE_SET_PRIVATE2 | PAGE_SET_WRITEBACK | PAGE_CLEAR_DIRTY;
+ extent_clear_unlock_delalloc(inode, start, cur_end,
+ NULL,
+ EXTENT_LOCKED | EXTENT_DELALLOC,
+ op);
+
+submit:
+ iosize = blocksize;
+
+ found = test_range_bit(tree, start, start + iosize - 1,
+ EXTENT_DEDUP, 0, cached_state);
+ if (found == 0) {
+ em = btrfs_get_extent(inode, page, 0, start, blocksize,
+ 1);
+ if (IS_ERR(em)) {
+ /* btrfs_get_extent will not return NULL */
+ ret = PTR_ERR(em);
+ goto out_reserve;
+ }
+
+ sector = (em->block_start + start - em->start) >> 9;
+ bdev = em->bdev;
+ free_extent_map(em);
+ em = NULL;
+
+ /* TODO: rw can be WRTIE_SYNC */
+ ret = submit_extent_page(WRITE, tree, page, sector,
+ iosize, 0, bdev, &bio,
+ 0, /* max_nr is no used */
+ end_bio_extent_writepage,
+ 0, 0, 0);
+ if (ret)
+ break;
+ } else {
+ clear_extent_dedup(tree, start, start + iosize - 1,
+ &cached_state, GFP_NOFS);
+
+ end_extent_writepage(page, 0, start,
+ start + iosize - 1);
+ /* we need to do this ourselves because we skip IO */
+ end_page_writeback(page);
+ }
+
+ unlock_page(page);
+ page_cache_release(page);
+ page = NULL;
+
+ num_bytes -= blocksize;
+ alloc_hint = ins.objectid + blocksize;
+ start += blocksize;
+ cond_resched();
+ }
+
+out_unlock:
+ if (bio) {
+ if (ret)
+ bio_put(bio);
+ else
+ ret = submit_one_bio(WRITE, bio, 0, 0);
+ bio = NULL;
+ }
+
+ if (ret && page)
+ SetPageError(page);
+ if (page) {
+ unlock_page(page);
+ page_cache_release(page);
+ }
+
+out:
+ if (ret && num_bytes > 0)
+ extent_clear_unlock_delalloc(inode,
+ start, start + num_bytes - 1,
+ NULL,
+ EXTENT_DELALLOC | EXTENT_LOCKED |
+ EXTENT_DEDUP | EXTENT_DEFRAG,
+ PAGE_UNLOCK | PAGE_SET_WRITEBACK |
+ PAGE_END_WRITEBACK | PAGE_CLEAR_DIRTY);
+
+ kfree(hash);
+ free_extent_state(cached_state);
+ return ret;
+
+out_reserve:
+ if (found == 0)
+ btrfs_free_reserved_extent(root, ins.objectid, ins.offset);
+ goto out_unlock;
+}
+
static u64 get_extent_allocation_hint(struct inode *inode, u64 start,
u64 num_bytes)
{
@@ -825,11 +1195,11 @@ static u64 get_extent_allocation_hint(struct inode *inode, u64 start,
* required to start IO on it. It may be clean and already done with
* IO when we return.
*/
-static noinline int cow_file_range(struct inode *inode,
+static noinline int __cow_file_range(struct inode *inode,
struct page *locked_page,
u64 start, u64 end, int *page_started,
unsigned long *nr_written,
- int unlock)
+ int unlock, struct btrfs_dedup_hash *hash)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
u64 alloc_hint = 0;
@@ -928,8 +1298,16 @@ static noinline int cow_file_range(struct inode *inode,
goto out_reserve;
cur_alloc_size = ins.offset;
- ret = btrfs_add_ordered_extent(inode, start, ins.objectid,
- ram_size, cur_alloc_size, 0);
+ if (!hash)
+ ret = btrfs_add_ordered_extent(inode, start,
+ ins.objectid, ram_size,
+ cur_alloc_size, 0);
+ else
+ ret = btrfs_add_ordered_extent_dedup(inode, start,
+ ins.objectid, ram_size,
+ cur_alloc_size, 0, 0,
+ hash,
+ BTRFS_COMPRESS_NONE);
if (ret)
goto out_reserve;
@@ -977,21 +1355,76 @@ out_unlock:
goto out;
}
+static noinline int cow_file_range(struct inode *inode,
+ struct page *locked_page,
+ u64 start, u64 end, int *page_started,
+ unsigned long *nr_written,
+ int unlock)
+{
+ return __cow_file_range(inode, locked_page, start, end, page_started,
+ nr_written, unlock, NULL);
+}
+
+static noinline int cow_file_range_dedup(struct inode *inode,
+ struct page *locked_page,
+ u64 start, u64 end, int *page_started,
+ unsigned long *nr_written,
+ int unlock, struct btrfs_dedup_hash *hash)
+{
+ return __cow_file_range(inode, locked_page, start, end, page_started,
+ nr_written, unlock, hash);
+}
+
+static int run_locked_range(struct extent_io_tree *tree, struct inode *inode,
+ struct page *locked_page, u64 start, u64 end,
+ get_extent_t *get_extent, int mode,
+ struct btrfs_dedup_hash *hash)
+{
+ int page_started = 0;
+ unsigned long nr_written = 0;
+ int ret;
+
+ lock_extent(tree, start, end);
+
+ /* allocate blocks */
+ ret = cow_file_range_dedup(inode, locked_page, start, end,
+ &page_started, &nr_written, 0, hash);
+
+ /*
+ * if page_started, cow_file_range inserted an
+ * inline extent and took care of all the unlocking
+ * and IO for us. Otherwise, we need to submit
+ * all those pages down to the drive.
+ */
+ if (!page_started && !ret)
+ extent_write_locked_range(tree, inode, start, end, get_extent,
+ mode);
+ else if (ret)
+ unlock_page(locked_page);
+
+ return ret;
+}
+
/*
* work queue call back to started compression on a file and pages
*/
static noinline void async_cow_start(struct btrfs_work *work)
{
struct async_cow *async_cow;
- int num_added = 0;
async_cow = container_of(work, struct async_cow, work);
- compress_file_range(async_cow->inode, async_cow->locked_page,
- async_cow->start, async_cow->end, async_cow,
- &num_added);
- if (num_added == 0) {
- btrfs_add_delayed_iput(async_cow->inode);
- async_cow->inode = NULL;
+ if (async_cow->root->fs_info->dedup_bs != 0) {
+ run_delalloc_dedup(async_cow->inode, async_cow->locked_page,
+ async_cow->start, async_cow->end, async_cow);
+ } else {
+ int num_added = 0;
+ compress_file_range(async_cow->inode, async_cow->locked_page,
+ async_cow->start, async_cow->end, async_cow,
+ &num_added, NULL);
+ if (num_added == 0) {
+ btrfs_add_delayed_iput(async_cow->inode);
+ async_cow->inode = NULL;
+ }
}
}
@@ -1379,6 +1812,19 @@ error:
return ret;
}
+static int btrfs_inode_test_compress(struct inode *inode)
+{
+ struct btrfs_inode *bi = BTRFS_I(inode);
+ struct btrfs_root *root = BTRFS_I(inode)->root;
+
+ if (btrfs_test_opt(root, COMPRESS) ||
+ bi->force_compress ||
+ bi->flags & BTRFS_INODE_COMPRESS)
+ return 1;
+
+ return 0;
+}
+
/*
* extent_io.c call back to do delayed allocation processing
*/
@@ -1388,21 +1834,21 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
{
int ret;
struct btrfs_root *root = BTRFS_I(inode)->root;
+ struct btrfs_inode *bi = BTRFS_I(inode);
- if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) {
+ if (bi->flags & BTRFS_INODE_NODATACOW) {
ret = run_delalloc_nocow(inode, locked_page, start, end,
page_started, 1, nr_written);
- } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) {
+ } else if (bi->flags & BTRFS_INODE_PREALLOC) {
ret = run_delalloc_nocow(inode, locked_page, start, end,
page_started, 0, nr_written);
- } else if (!btrfs_test_opt(root, COMPRESS) &&
- !(BTRFS_I(inode)->force_compress) &&
- !(BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS)) {
+ } else if (!btrfs_inode_test_compress(inode) &&
+ root->fs_info->dedup_bs == 0) {
ret = cow_file_range(inode, locked_page, start, end,
page_started, nr_written, 1);
} else {
set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
- &BTRFS_I(inode)->runtime_flags);
+ &bi->runtime_flags);
ret = cow_file_range_async(inode, locked_page, start, end,
page_started, nr_written);
}
@@ -1829,12 +2275,14 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end)
return -EBUSY;
}
-static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
- struct inode *inode, u64 file_pos,
- u64 disk_bytenr, u64 disk_num_bytes,
- u64 num_bytes, u64 ram_bytes,
- u8 compression, u8 encryption,
- u16 other_encoding, int extent_type)
+static int __insert_reserved_file_extent(struct btrfs_trans_handle *trans,
+ struct inode *inode, u64 file_pos,
+ u64 disk_bytenr, u64 disk_num_bytes,
+ u64 num_bytes, u64 ram_bytes,
+ u8 compression, u8 encryption,
+ u16 other_encoding, int extent_type,
+ int dedup,
+ struct btrfs_dedup_hash *hash)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_file_extent_item *fi;
@@ -1891,15 +2339,59 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
ins.objectid = disk_bytenr;
ins.offset = disk_num_bytes;
ins.type = BTRFS_EXTENT_ITEM_KEY;
- ret = btrfs_alloc_reserved_file_extent(trans, root,
- root->root_key.objectid,
- btrfs_ino(inode), file_pos, &ins);
+
+ if (!dedup) {
+ ret = btrfs_alloc_reserved_file_extent(trans, root,
+ root->root_key.objectid,
+ btrfs_ino(inode),
+ file_pos, &ins);
+ if (ret)
+ goto out;
+
+ if (hash) {
+ int index = btrfs_dedup_lens[hash->type] - 1;
+
+ hash->bytenr = ins.objectid;
+ hash->num_bytes = ins.offset;
+ hash->compression = compression;
+ ret = btrfs_insert_dedup_extent(trans, root, hash);
+ if (ret)
+ goto out;
+
+ ret = btrfs_inc_extent_ref(trans, root, ins.objectid,
+ ins.offset, 0,
+ BTRFS_DEDUP_TREE_OBJECTID,
+ btrfs_ino(inode),
+ hash->hash[index], 0);
+ }
+ } else {
+ ret = btrfs_inc_extent_ref(trans, root, ins.objectid,
+ ins.offset, 0,
+ root->root_key.objectid,
+ btrfs_ino(inode),
+ file_pos, /* file_pos - 0 */
+ 0);
+ }
out:
btrfs_free_path(path);
return ret;
}
+static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
+ struct inode *inode, u64 file_pos,
+ u64 disk_bytenr, u64 disk_num_bytes,
+ u64 num_bytes, u64 ram_bytes,
+ u8 compression, u8 encryption,
+ u16 other_encoding, int extent_type)
+{
+ return __insert_reserved_file_extent(trans, inode, file_pos,
+ disk_bytenr, disk_num_bytes,
+ num_bytes, ram_bytes, compression,
+ encryption, other_encoding,
+ extent_type, 0, NULL);
+}
+
/* snapshot-aware defrag */
struct sa_defrag_extent_backref {
struct rb_node node;
@@ -2640,13 +3132,15 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
logical_len);
} else {
BUG_ON(root == root->fs_info->tree_root);
- ret = insert_reserved_file_extent(trans, inode,
+ ret = __insert_reserved_file_extent(trans, inode,
ordered_extent->file_offset,
ordered_extent->start,
ordered_extent->disk_len,
logical_len, logical_len,
compress_type, 0, 0,
- BTRFS_FILE_EXTENT_REG);
+ BTRFS_FILE_EXTENT_REG,
+ ordered_extent->dedup,
+ ordered_extent->hash);
}
unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
ordered_extent->file_offset, ordered_extent->len,
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 10/14] Btrfs: skip dedup reference during backref walking
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (8 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 09/14] Btrfs: online(inband) data dedup Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 11/14] Btrfs: don't return space for dedup extent Liu Bo
` (6 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
The dedup ref is quite a special one, it is just used to store the hash value
of the extent and cannot be used to find data, so we skip it during backref
walking.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/backref.c | 9 +++++++++
fs/btrfs/relocation.c | 3 +++
2 files changed, 12 insertions(+)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 3775947..1ec0046 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -590,6 +590,9 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
key.objectid = ref->objectid;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = ref->offset;
+ if (ref->root == BTRFS_DEDUP_TREE_OBJECTID)
+ break;
+
ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0,
node->bytenr,
node->ref_mod * sgn, GFP_ATOMIC);
@@ -708,6 +711,9 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = btrfs_extent_data_ref_offset(leaf, dref);
root = btrfs_extent_data_ref_root(leaf, dref);
+ if (root == BTRFS_DEDUP_TREE_OBJECTID)
+ break;
+
ret = __add_prelim_ref(prefs, root, &key, 0, 0,
bytenr, count, GFP_NOFS);
break;
@@ -791,6 +797,9 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = btrfs_extent_data_ref_offset(leaf, dref);
root = btrfs_extent_data_ref_root(leaf, dref);
+ if (root == BTRFS_DEDUP_TREE_OBJECTID)
+ break;
+
ret = __add_prelim_ref(prefs, root, &key, 0, 0,
bytenr, count, GFP_NOFS);
break;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 429c73c..a06e448 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3509,6 +3509,9 @@ static int find_data_references(struct reloc_control *rc,
ref_offset = btrfs_extent_data_ref_offset(leaf, ref);
ref_count = btrfs_extent_data_ref_count(leaf, ref);
+ if (ref_root == BTRFS_DEDUP_TREE_OBJECTID)
+ return 0;
+
/*
* This is an extent belonging to the free space cache, lets just delete
* it and redo the search.
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 11/14] Btrfs: don't return space for dedup extent
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (9 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 10/14] Btrfs: skip dedup reference during backref walking Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 12/14] Btrfs: add ioctl of dedup control Liu Bo
` (5 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
If the ordered extent had an IOERR or something else went wrong we need to
return the space for this ordered extent back to the allocator, but if the
extent is marked as a dedup one, we don't free the space because we just
use the existing space instead of allocating new space.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/inode.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3a221bb..4363e1e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3190,6 +3190,7 @@ out:
* truncated case if we didn't write out the extent at all.
*/
if ((ret || !logical_len) &&
+ !ordered_extent->dedup &&
!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
!test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags))
btrfs_free_reserved_extent(root, ordered_extent->start,
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 12/14] Btrfs: add ioctl of dedup control
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (10 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 11/14] Btrfs: don't return space for dedup extent Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 13/14] Btrfs: fix dedupe 'ENOSPC' problem Liu Bo
` (4 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
So far we have 4 commands to control dedup behaviour,
- btrfs dedup enable
Create the dedup tree, and it's the very first step when you're going to use
the dedup feature.
- btrfs dedup disable
Delete the dedup tree, after this we're not able to use dedup any more unless
you enable it again.
- btrfs dedup on [-b]
Switch on the dedup feature temporarily, and it's the second step of applying
dedup with writes. Option '-b' is used to set dedup blocksize.
The default blocksize is 8192(no special reason, you may argue), and the current
limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the
upper limit of btrfs's compression.
- btrfs dedup off
Switch off the dedup feature temporarily, but the dedup tree remains.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.h | 3 +
fs/btrfs/disk-io.c | 1 +
fs/btrfs/ioctl.c | 167 +++++++++++++++++++++++++++++++++++++++++++++
include/uapi/linux/btrfs.h | 11 +++
4 files changed, 182 insertions(+)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 52b2843..1b89d6c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1715,6 +1715,9 @@ struct btrfs_fs_info {
u64 dedup_bs;
int dedup_type;
+
+ /* protect user change for dedup operations */
+ struct mutex dedup_ioctl_mutex;
};
/*
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2c83de7..9c9667d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2314,6 +2314,7 @@ int open_ctree(struct super_block *sb,
mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
mutex_init(&fs_info->dev_replace.lock_management_lock);
mutex_init(&fs_info->dev_replace.lock);
+ mutex_init(&fs_info->dedup_ioctl_mutex);
spin_lock_init(&fs_info->qgroup_lock);
mutex_init(&fs_info->qgroup_ioctl_lock);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 347bf61..75fb3de 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4481,6 +4481,171 @@ out_unlock:
return ret;
}
+static long btrfs_enable_dedup(struct btrfs_root *root)
+{
+ struct btrfs_fs_info *fs_info = root->fs_info;
+ struct btrfs_trans_handle *trans = NULL;
+ struct btrfs_root *dedup_root;
+ int ret = 0;
+
+ mutex_lock(&fs_info->dedup_ioctl_mutex);
+ if (fs_info->dedup_root) {
+ pr_info("btrfs: dedup has already been enabled\n");
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ return 0;
+ }
+
+ trans = btrfs_start_transaction(root, 2);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ return ret;
+ }
+
+ dedup_root = btrfs_create_tree(trans, fs_info,
+ BTRFS_DEDUP_TREE_OBJECTID);
+ if (IS_ERR(dedup_root))
+ ret = PTR_ERR(dedup_root);
+
+ if (ret)
+ btrfs_end_transaction(trans, root);
+ else
+ ret = btrfs_commit_transaction(trans, root);
+
+ if (!ret) {
+ pr_info("btrfs: dedup enabled\n");
+ fs_info->dedup_root = dedup_root;
+ fs_info->dedup_root->block_rsv = &fs_info->global_block_rsv;
+ btrfs_set_fs_incompat(fs_info, DEDUP);
+ }
+
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ return ret;
+}
+
+static long btrfs_disable_dedup(struct btrfs_root *root)
+{
+ struct btrfs_fs_info *fs_info = root->fs_info;
+ struct btrfs_root *dedup_root;
+ int ret;
+
+ mutex_lock(&fs_info->dedup_ioctl_mutex);
+ if (!fs_info->dedup_root) {
+ pr_info("btrfs: dedup has been disabled\n");
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ return 0;
+ }
+
+ if (fs_info->dedup_bs != 0) {
+ pr_info("btrfs: cannot disable dedup until switching off dedup!\n");
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ return -EBUSY;
+ }
+
+ dedup_root = fs_info->dedup_root;
+
+ ret = btrfs_drop_snapshot(dedup_root, NULL, 1, 0);
+
+ if (!ret) {
+ fs_info->dedup_root = NULL;
+ pr_info("btrfs: dedup disabled\n");
+ }
+
+ mutex_unlock(&fs_info->dedup_ioctl_mutex);
+ WARN_ON(ret < 0 && ret != -EAGAIN && ret != -EROFS);
+ return ret;
+}
+
+static long btrfs_set_dedup_bs(struct btrfs_root *root, u64 bs)
+{
+ struct btrfs_fs_info *info = root->fs_info;
+ int ret = 0;
+
+ mutex_lock(&info->dedup_ioctl_mutex);
+ if (!info->dedup_root) {
+ pr_info("btrfs: dedup is disabled, we cannot switch on/off dedup\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ bs = ALIGN(bs, root->sectorsize);
+ bs = min_t(u64, bs, (128 * 1024ULL));
+
+ if (bs == info->dedup_bs) {
+ if (info->dedup_bs == 0)
+ pr_info("btrfs: switch OFF dedup(it's already off)\n");
+ else
+ pr_info("btrfs: switch ON dedup(its bs is already %llu)\n",
+ bs);
+ goto out;
+ }
+
+ /*
+ * The dedup works similar to compression, both use async workqueue to
+ * reach better performance. We drain the on-going async works here
+ * so that new dedup writes will apply with the new dedup blocksize.
+ */
+ atomic_inc(&info->async_submit_draining);
+ while (atomic_read(&info->nr_async_submits) ||
+ atomic_read(&info->async_delalloc_pages)) {
+ wait_event(info->async_submit_wait,
+ (atomic_read(&info->nr_async_submits) == 0 &&
+ atomic_read(&info->async_delalloc_pages) == 0));
+ }
+
+ /*
+ * dedup_bs = 0: dedup off;
+ * dedup_bs > 0: dedup on;
+ */
+ info->dedup_bs = bs;
+ if (info->dedup_bs == 0) {
+ pr_info("btrfs: switch OFF dedup\n");
+ } else {
+ info->dedup_bs = bs;
+ pr_info("btrfs: switch ON dedup(dedup blocksize %llu)\n",
+ info->dedup_bs);
+ }
+ atomic_dec(&info->async_submit_draining);
+
+out:
+ mutex_unlock(&info->dedup_ioctl_mutex);
+ return ret;
+}
+
+static long btrfs_ioctl_dedup_ctl(struct btrfs_root *root, void __user *args)
+{
+ struct btrfs_ioctl_dedup_args *dargs;
+ int ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ dargs = memdup_user(args, sizeof(*dargs));
+ if (IS_ERR(dargs)) {
+ ret = PTR_ERR(dargs);
+ goto out;
+ }
+
+ switch (dargs->cmd) {
+ case BTRFS_DEDUP_CTL_ENABLE:
+ ret = btrfs_enable_dedup(root);
+ break;
+ case BTRFS_DEDUP_CTL_DISABLE:
+ ret = btrfs_disable_dedup(root);
+ break;
+ case BTRFS_DEDUP_CTL_SET_BS:
+ /* dedup on/off */
+ ret = btrfs_set_dedup_bs(root, dargs->bs);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ kfree(dargs);
+out:
+ return ret;
+}
+
long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
{
@@ -4599,6 +4764,8 @@ long btrfs_ioctl(struct file *file, unsigned int
return btrfs_ioctl_set_fslabel(file, argp);
case BTRFS_IOC_FILE_EXTENT_SAME:
return btrfs_ioctl_file_extent_same(file, argp);
+ case BTRFS_IOC_DEDUP_CTL:
+ return btrfs_ioctl_dedup_ctl(root, argp);
}
return -ENOTTY;
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 45e6189..eda8b92 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -399,6 +399,15 @@ struct btrfs_ioctl_get_dev_stats {
__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
};
+/* deduplication control ioctl modes */
+#define BTRFS_DEDUP_CTL_ENABLE 1
+#define BTRFS_DEDUP_CTL_DISABLE 2
+#define BTRFS_DEDUP_CTL_SET_BS 3
+struct btrfs_ioctl_dedup_args {
+ __u64 cmd;
+ __u64 bs;
+};
+
#define BTRFS_QUOTA_CTL_ENABLE 1
#define BTRFS_QUOTA_CTL_DISABLE 2
#define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
@@ -606,5 +615,7 @@ 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_DEDUP_CTL _IOWR(BTRFS_IOCTL_MAGIC, 55, \
+ struct btrfs_ioctl_dedup_args)
#endif /* _UAPI_LINUX_BTRFS_H */
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 13/14] Btrfs: fix dedupe 'ENOSPC' problem
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (11 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 12/14] Btrfs: add ioctl of dedup control Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH v8 14/14] Btrfs: fix a crash of dedup ref Liu Bo
` (3 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
With dedupe, writes are likely to produce metadata but no data, which means
producing more delayed_refs, and this can ends up aborting a transaction
because it needs to allocate enough free space from global_rsv to turn
delayed_refs into real extent tree's nodes/leaves and global_rsv is used up.
So we must take the worst case for throttling delayed refs in this dedup case,
ie, allocating one leaf on each delayed ref head update.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/extent-tree.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f14db92..df3a645 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2661,6 +2661,19 @@ static inline u64 heads_to_leaves(struct btrfs_root *root, u64 heads)
{
u64 num_bytes;
+ /*
+ * For deduplication it's a special case where we must be very careful
+ * on throttling the number of delayed_refs, just because with dedupe,
+ * we're likely to produce _only_ metadata but no data, which results in
+ * quite a lot of delayed_refs, and consequently global_rsv may be used
+ * up and we get a RO btrfs.
+ *
+ * So we have to take the worst case -- one leaf for updating a ref head
+ * and its related refs.
+ */
+ if (root->fs_info->dedup_bs != 0)
+ return heads;
+
num_bytes = heads * (sizeof(struct btrfs_extent_item) +
sizeof(struct btrfs_extent_inline_ref));
if (!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v8 14/14] Btrfs: fix a crash of dedup ref
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (12 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 13/14] Btrfs: fix dedupe 'ENOSPC' problem Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 8:12 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
` (2 subsequent siblings)
16 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
The dedup reference is a special kind of delayed refs, and the delayed refs
are batched to be processed later.
If we find a matched dedup extent, then we queue an ADD delayed ref on it within
endio work, but there is already a DROP delayed ref queued,
t1 t2 t3
->writepage commit transaction
->run_delalloc_dedup
find_dedup
------------------------------------------------------------------------------
process_delayed refs
(it deletes the dedup extent)
add ordered extent |
submit pages |
finish ordered io |
insert file extents |
queue delayed refs |
queue dedup ref |
"process delayed refs" continues
(insert a ref on an extent
deleted by the above)
This senario ends up with a crash because we're going to insert a ref on
a deleted extent.
To avoid the race, we need to check if there is a ADD delayed ref on deleting
the extent and protect this job with lock.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.h | 3 ++-
fs/btrfs/extent-tree.c | 35 +++++++++++++++++++----------------
fs/btrfs/file-item.c | 36 +++++++++++++++++++++++++++++++++++-
fs/btrfs/inode.c | 10 ++--------
4 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 1b89d6c..8a35cdf 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3692,7 +3692,8 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
struct list_head *list, int search_commit);
int noinline_for_stack
-btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash);
+btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash,
+ struct inode *inode, u64 file_pos);
int noinline_for_stack
btrfs_insert_dedup_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index df3a645..a140ea9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5996,9 +5996,23 @@ again:
goto again;
}
} else {
- if (!dedup_hash && is_data &&
- root_objectid == BTRFS_DEDUP_TREE_OBJECTID)
- dedup_hash = extent_data_ref_offset(root, path, iref);
+ if (is_data && root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
+ if (!dedup_hash)
+ dedup_hash = extent_data_ref_offset(root,
+ path, iref);
+
+ ret = btrfs_free_dedup_extent(trans, root,
+ dedup_hash, bytenr);
+ if (ret) {
+ if (ret == -EAGAIN)
+ ret = 0;
+ else
+ btrfs_abort_transaction(trans,
+ extent_root,
+ ret);
+ goto out;
+ }
+ }
if (found_extent) {
BUG_ON(is_data && refs_to_drop !=
@@ -6023,21 +6037,10 @@ again:
if (is_data) {
ret = btrfs_del_csums(trans, root, bytenr, num_bytes);
if (ret) {
- btrfs_abort_transaction(trans, extent_root, ret);
+ btrfs_abort_transaction(trans,
+ extent_root, ret);
goto out;
}
-
- if (root_objectid == BTRFS_DEDUP_TREE_OBJECTID) {
- ret = btrfs_free_dedup_extent(trans, root,
- dedup_hash,
- bytenr);
- if (ret) {
- btrfs_abort_transaction(trans,
- extent_root,
- ret);
- goto out;
- }
- }
}
ret = update_block_group(root, bytenr, num_bytes, 0);
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index fd95692..a804071 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -887,13 +887,15 @@ fail_unlock:
/* 1 means we find one, 0 means we dont. */
int noinline_for_stack
-btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash)
+btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash,
+ struct inode *inode, u64 file_pos)
{
struct btrfs_key key;
struct btrfs_path *path;
struct extent_buffer *leaf;
struct btrfs_root *dedup_root;
struct btrfs_dedup_item *item;
+ struct btrfs_trans_handle *trans;
u64 hash_value;
u64 length;
u64 dedup_size;
@@ -916,6 +918,12 @@ btrfs_find_dedup_extent(struct btrfs_root *root, struct btrfs_dedup_hash *hash)
if (!path)
return 0;
+ trans = btrfs_join_transaction(root);
+ if (IS_ERR(trans)) {
+ trans = NULL;
+ goto out;
+ }
+
/*
* For SHA256 dedup algorithm, we store the last 64bit as the
* key.objectid, and the rest in the tree item.
@@ -972,7 +980,15 @@ prev_slot:
hash->num_bytes = length;
hash->compression = compression;
found = 1;
+
+ ret = btrfs_inc_extent_ref(trans, root, key.offset, length, 0,
+ BTRFS_I(inode)->root->root_key.objectid,
+ btrfs_ino(inode),
+ file_pos, /* file_pos - 0 */
+ 0);
out:
+ if (trans)
+ btrfs_end_transaction(trans, root);
btrfs_free_path(path);
return found;
}
@@ -1055,6 +1071,8 @@ btrfs_free_dedup_extent(struct btrfs_trans_handle *trans,
struct btrfs_path *path;
struct extent_buffer *leaf;
struct btrfs_root *dedup_root;
+ struct btrfs_delayed_ref_root *delayed_refs;
+ struct btrfs_delayed_ref_head *head;
int ret = 0;
if (!root->fs_info->dedup_root)
@@ -1088,6 +1106,22 @@ btrfs_free_dedup_extent(struct btrfs_trans_handle *trans,
if (key.objectid != hash || key.offset != bytenr)
goto out;
+ ret = 0;
+
+ /* check if ADD_DELAYED delayed refs exist */
+ delayed_refs = &trans->transaction->delayed_refs;
+
+ spin_lock(&delayed_refs->lock);
+ head = btrfs_find_delayed_ref_head(trans, bytenr);
+
+ /* the mutex has been acquired by the caller */
+ if (head && head->add_cnt) {
+ spin_unlock(&delayed_refs->lock);
+ ret = -EAGAIN;
+ goto out;
+ }
+ spin_unlock(&delayed_refs->lock);
+
ret = btrfs_del_item(trans, dedup_root, path);
WARN_ON(ret);
out:
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4363e1e..b40ec29 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -969,7 +969,8 @@ run_delalloc_dedup(struct inode *inode, struct page *locked_page, u64 start,
found = 0;
compr = BTRFS_COMPRESS_NONE;
} else {
- found = btrfs_find_dedup_extent(root, hash);
+ found = btrfs_find_dedup_extent(root, hash,
+ inode, start);
compr = hash->compression;
}
@@ -2364,13 +2365,6 @@ static int __insert_reserved_file_extent(struct btrfs_trans_handle *trans,
btrfs_ino(inode),
hash->hash[index], 0);
}
- } else {
- ret = btrfs_inc_extent_ref(trans, root, ins.objectid,
- ins.offset, 0,
- root->root_key.objectid,
- btrfs_ino(inode),
- file_pos, /* file_pos - 0 */
- 0);
}
out:
btrfs_free_path(path);
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH] Btrfs-progs: add dedup subcommand
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (13 preceding siblings ...)
2013-12-30 8:12 ` [PATCH v8 14/14] Btrfs: fix a crash of dedup ref Liu Bo
@ 2013-12-30 8:12 ` Liu Bo
2013-12-30 11:34 ` Martin Steigerwald
2014-01-14 17:34 ` David Sterba
2014-01-02 14:32 ` [RFC PATCH v8 00/14] Online(inband) data deduplication Konstantinos Skarlatos
2014-02-25 19:22 ` Jannis Achstetter
16 siblings, 2 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-30 8:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
This adds deduplication subcommands, 'btrfs dedup command <path>',
including enable/disable/on/off.
- btrfs dedup enable
Create the dedup tree, and it's the very first step when you're going to use
the dedup feature.
- btrfs dedup disable
Delete the dedup tree, after this we're not able to use dedup any more unless
you enable it again.
- btrfs dedup on [-b]
Switch on the dedup feature temporarily, and it's the second step of applying
dedup with writes. Option '-b' is used to set dedup blocksize.
The default blocksize is 8192(no special reason, you may argue), and the current
limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the
upper limit of btrfs's compression.
- btrfs dedup off
Switch off the dedup feature temporarily, but the dedup tree remains.
---------------------------------------------------------
Usage:
Step 1: btrfs dedup enable /btrfs
Step 2: btrfs dedup on /btrfs or btrfs dedup on -b 4K /btrfs
Step 3: now we have dedup, run your test.
Step 4: btrfs dedup off /btrfs
Step 5: btrfs dedup disable /btrfs
---------------------------------------------------------
v3: add commands 'btrfs dedup on/off'
v2: add manpage
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
Makefile | 3 +-
btrfs.c | 1 +
cmds-dedup.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
commands.h | 2 +
ctree.h | 2 +
ioctl.h | 12 ++++
man/btrfs.8.in | 31 +++++++++-
7 files changed, 225 insertions(+), 4 deletions(-)
create mode 100644 cmds-dedup.c
diff --git a/Makefile b/Makefile
index 0874a41..092f2db 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,8 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.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-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
+ cmds-dedup.o
libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
uuid-tree.o
libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
diff --git a/btrfs.c b/btrfs.c
index d5fc738..dfae35f 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -255,6 +255,7 @@ static const struct cmd_group btrfs_cmd_group = {
{ "quota", cmd_quota, NULL, "a_cmd_group, 0 },
{ "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 },
{ "replace", cmd_replace, NULL, &replace_cmd_group, 0 },
+ { "dedup", cmd_dedup, NULL, &dedup_cmd_group, 0 },
{ "help", cmd_help, cmd_help_usage, NULL, 0 },
{ "version", cmd_version, cmd_version_usage, NULL, 0 },
NULL_CMD_STRUCT
diff --git a/cmds-dedup.c b/cmds-dedup.c
new file mode 100644
index 0000000..b959349
--- /dev/null
+++ b/cmds-dedup.c
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2013 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "ctree.h"
+#include "ioctl.h"
+
+#include "commands.h"
+#include "utils.h"
+
+static const char * const dedup_cmd_group_usage[] = {
+ "btrfs dedup <command> [options] <path>",
+ NULL
+};
+
+int dedup_ctl(char *path, struct btrfs_ioctl_dedup_args *args)
+{
+ int ret = 0;
+ int fd;
+ int e;
+ DIR *dirstream = NULL;
+
+ fd = open_file_or_dir(path, &dirstream);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return -EACCES;
+ }
+
+ ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, args);
+ e = errno;
+ close_file_or_dir(fd, dirstream);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: dedup command failed: %s\n",
+ strerror(e));
+ if (args->cmd == BTRFS_DEDUP_CTL_DISABLE ||
+ args->cmd == BTRFS_DEDUP_CTL_SET_BS)
+ fprintf(stderr, "please refer to 'dmesg | tail' for more info\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static const char * const cmd_dedup_enable_usage[] = {
+ "btrfs dedup enable <path>",
+ "Enable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_enable(int argc, char **argv)
+{
+ struct btrfs_ioctl_dedup_args dargs;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_dedup_enable_usage);
+
+ dargs.cmd = BTRFS_DEDUP_CTL_ENABLE;
+
+ return dedup_ctl(argv[1], &dargs);
+}
+
+static const char * const cmd_dedup_disable_usage[] = {
+ "btrfs dedup disable <path>",
+ "Disable data deduplication support for a filesystem.",
+ NULL
+};
+
+static int cmd_dedup_disable(int argc, char **argv)
+{
+ struct btrfs_ioctl_dedup_args dargs;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_dedup_disable_usage);
+
+ dargs.cmd = BTRFS_DEDUP_CTL_DISABLE;
+
+ return dedup_ctl(argv[1], &dargs);
+}
+
+static int dedup_set_bs(char *path, struct btrfs_ioctl_dedup_args *dargs)
+{
+ return dedup_ctl(path, dargs);
+}
+
+static const char * const cmd_dedup_on_usage[] = {
+ "btrfs dedup on [-b|--bs size] <path>",
+ "Switch on data deduplication or change the dedup blocksize.",
+ "",
+ "-b|--bs <size> set dedup blocksize",
+ NULL
+};
+
+static struct option longopts[] = {
+ {"bs", required_argument, NULL, 'b'},
+ {0, 0, 0, 0}
+};
+
+static int cmd_dedup_on(int argc, char **argv)
+{
+ struct btrfs_ioctl_dedup_args dargs;
+ u64 bs = 8192;
+
+ optind = 1;
+ while (1) {
+ int longindex;
+
+ int c = getopt_long(argc, argv, "b:", longopts, &longindex);
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case 'b':
+ bs = parse_size(optarg);
+ break;
+ default:
+ usage(cmd_dedup_on_usage);
+ }
+ }
+
+ if (check_argc_exact(argc - optind, 1))
+ usage(cmd_dedup_on_usage);
+
+ dargs.cmd = BTRFS_DEDUP_CTL_SET_BS;
+ dargs.bs = bs;
+
+ return dedup_set_bs(argv[optind], &dargs);
+}
+
+static const char * const cmd_dedup_off_usage[] = {
+ "btrfs dedup off <path>",
+ "Switch off data deduplication.",
+ NULL
+};
+
+static int cmd_dedup_off(int argc, char **argv)
+{
+ struct btrfs_ioctl_dedup_args dargs;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_dedup_off_usage);
+
+ dargs.cmd = BTRFS_DEDUP_CTL_SET_BS;
+ dargs.bs = 0;
+
+ return dedup_set_bs(argv[1], &dargs);
+}
+
+const struct cmd_group dedup_cmd_group = {
+ dedup_cmd_group_usage, NULL, {
+ { "enable", cmd_dedup_enable, cmd_dedup_enable_usage, NULL, 0 },
+ { "disable", cmd_dedup_disable, cmd_dedup_disable_usage, 0, 0 },
+ { "on", cmd_dedup_on, cmd_dedup_on_usage, NULL, 0},
+ { "off", cmd_dedup_off, cmd_dedup_off_usage, NULL, 0},
+ { 0, 0, 0, 0, 0 }
+ }
+};
+
+int cmd_dedup(int argc, char **argv)
+{
+ return handle_command_group(&dedup_cmd_group, argc, argv);
+}
diff --git a/commands.h b/commands.h
index b791d68..6fccc15 100644
--- a/commands.h
+++ b/commands.h
@@ -91,6 +91,7 @@ extern const struct cmd_group quota_cmd_group;
extern const struct cmd_group qgroup_cmd_group;
extern const struct cmd_group replace_cmd_group;
extern const struct cmd_group rescue_cmd_group;
+extern const struct cmd_group dedup_cmd_group;
extern const char * const cmd_send_usage[];
extern const char * const cmd_receive_usage[];
@@ -119,6 +120,7 @@ int cmd_select_super(int argc, char **argv);
int cmd_dump_super(int argc, char **argv);
int cmd_debug_tree(int argc, char **argv);
int cmd_rescue(int argc, char **argv);
+int cmd_dedup(int argc, char **argv);
/* subvolume exported functions */
int test_issubvolume(char *path);
diff --git a/ctree.h b/ctree.h
index 2117374..27c5897 100644
--- a/ctree.h
+++ b/ctree.h
@@ -470,6 +470,7 @@ struct btrfs_super_block {
#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
+#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
@@ -482,6 +483,7 @@ struct btrfs_super_block {
BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
BTRFS_FEATURE_INCOMPAT_RAID56 | \
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
+ BTRFS_FEATURE_INCOMPAT_DEDUP | \
BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
/*
diff --git a/ioctl.h b/ioctl.h
index a589cd7..d4c6423 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -430,6 +430,15 @@ struct btrfs_ioctl_get_dev_stats {
__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
};
+/* deduplication control ioctl modes */
+#define BTRFS_DEDUP_CTL_ENABLE 1
+#define BTRFS_DEDUP_CTL_DISABLE 2
+#define BTRFS_DEDUP_CTL_SET_BS 3
+struct btrfs_ioctl_dedup_args {
+ __u64 cmd;
+ __u64 bs;
+};
+
/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
#define BTRFS_QUOTA_CTL_ENABLE 1
#define BTRFS_QUOTA_CTL_DISABLE 2
@@ -593,6 +602,9 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_get_dev_stats)
#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
struct btrfs_ioctl_dev_replace_args)
+#define BTRFS_IOC_DEDUP_CTL _IOWR(BTRFS_IOCTL_MAGIC, 55, \
+ struct btrfs_ioctl_dedup_args)
+
#ifdef __cplusplus
}
#endif
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index b620348..56cdf1b 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -109,13 +109,22 @@ btrfs \- control a btrfs filesystem
.PP
\fBbtrfs\fP \fBqgroup limit\fP [\fIoptions\fP] \fI<size>\fP|\fBnone\fP [\fI<qgroupid>\fP] \fI<path>\fP
.PP
-.PP
\fBbtrfs\fP \fBreplace start\fP [-Bfr] \fI<srcdev>\fP|\fI<devid> <targetdev> <mount_point>\fP
.PP
\fBbtrfs\fP \fBreplace status\fP [-1] \fI<mount_point>\fP
.PP
\fBbtrfs\fP \fBreplace cancel\fP \fI<mount_point>\fP
.PP
+\fBbtrfs\fP \fBdedup enable\fP \fI<path>\fP
+.PP
+\fBbtrfs\fP \fBdedup disable\fP \fI<path>\fP
+.PP
+\fBbtrfs\fP \fBdedup on\fP [-b|--bs \fIsize\fP] \fI<path>\fP
+.PP
+\fBbtrfs\fP \fBdedup off\fP \fI<path>\fP
+.PP
+.PP
+
\fBbtrfs\fP \fBhelp|\-\-help \fP
.PP
\fBbtrfs\fP \fB<command> \-\-help \fP
@@ -739,12 +748,28 @@ Print status and progress information of a running device replace operation.
.IP "\fB-1\fP" 5
print once instead of print continuously until the replace
operation finishes (or is canceled)
-.RE
-.TP
\fBreplace cancel\fR \fI<mount_point>\fR
Cancel a running device replace operation.
.RE
+.TP
+
+\fBdedup enable\fP \fI<path>\fP
+Enable data deduplication support for a filesystem.
+.TP
+
+\fBdedup disable\fP \fI<path>\fP
+Disable data deduplication support for a filesystem.
+.TP
+
+\fBdedup on\fP [-b|--bs \fIsize\fP] \fI<path>\fP
+Switch on data deduplication or change the dedup blocksize.
+.TP
+
+\fBdedup off\fP \fI<path>\fP
+Switch off data deduplication.
+.RE
+.TP
.SH EXIT STATUS
\fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in
--
1.8.2.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-12-30 8:12 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
@ 2013-12-30 11:34 ` Martin Steigerwald
2013-12-31 3:18 ` Liu Bo
2013-12-31 3:24 ` Kai Krakow
2014-01-14 17:34 ` David Sterba
1 sibling, 2 replies; 34+ messages in thread
From: Martin Steigerwald @ 2013-12-30 11:34 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs, Marcel Ritter, Christian Robert, alanqk@gmail.com
Am Montag, 30. Dezember 2013, 16:12:55 schrieben Sie:
> This adds deduplication subcommands, 'btrfs dedup command <path>',
> including enable/disable/on/off.
Nice. Looking forward to test it.
> - btrfs dedup enable
> Create the dedup tree, and it's the very first step when you're going to use
> the dedup feature.
>
> - btrfs dedup disable
> Delete the dedup tree, after this we're not able to use dedup any more
> unless you enable it again.
So if deduplication has been switched on for a while, btrfs dedup disable will
cause BTRFS to undo the deduplication (and thus require more space for the
same amount of data)?
Thanks and happy new year,
--
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de
GPG: 03B0 0D6C 0040 0710 4AFA B82F 991B EAAC A599 84C7
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-12-30 11:34 ` Martin Steigerwald
@ 2013-12-31 3:18 ` Liu Bo
2013-12-31 3:24 ` Kai Krakow
1 sibling, 0 replies; 34+ messages in thread
From: Liu Bo @ 2013-12-31 3:18 UTC (permalink / raw)
To: Martin Steigerwald
Cc: linux-btrfs, Marcel Ritter, Christian Robert, alanqk@gmail.com
On Mon, Dec 30, 2013 at 12:34:42PM +0100, Martin Steigerwald wrote:
> Am Montag, 30. Dezember 2013, 16:12:55 schrieben Sie:
> > This adds deduplication subcommands, 'btrfs dedup command <path>',
> > including enable/disable/on/off.
>
> Nice. Looking forward to test it.
Well, I just got a report from another user, Marcel, who still got ENOSPC errors with this
around of patch set, so it seems that I don't really fix that bug, I guess I
have to work harder on this :-(
>
> > - btrfs dedup enable
> > Create the dedup tree, and it's the very first step when you're going to use
> > the dedup feature.
> >
> > - btrfs dedup disable
> > Delete the dedup tree, after this we're not able to use dedup any more
> > unless you enable it again.
>
> So if deduplication has been switched on for a while, btrfs dedup disable will
> cause BTRFS to undo the deduplication (and thus require more space for the
> same amount of data)?
No, it remains unchanged, and the data is independent of dedupe, so you can read
them without any problems.
Happy new year.
Thanks,
-liubo
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-12-30 11:34 ` Martin Steigerwald
2013-12-31 3:18 ` Liu Bo
@ 2013-12-31 3:24 ` Kai Krakow
1 sibling, 0 replies; 34+ messages in thread
From: Kai Krakow @ 2013-12-31 3:24 UTC (permalink / raw)
To: linux-btrfs
Martin Steigerwald <Martin@lichtvoll.de> schrieb:
>> - btrfs dedup disable
>> Delete the dedup tree, after this we're not able to use dedup any more
>> unless you enable it again.
>
> So if deduplication has been switched on for a while, btrfs dedup disable
> will cause BTRFS to undo the deduplication (and thus require more space
> for the same amount of data)?
>From my intention I would guess it just looses track of what the content is
in "content based storage" - so when re-enabling it will have to "learn"
from beginning. It should not unshare data as sharing extents is a feature
of btrfs disting from the function of online dedup itself.
At least that would sound reasonable to me.
Regards,
Kai
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (14 preceding siblings ...)
2013-12-30 8:12 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
@ 2014-01-02 14:32 ` Konstantinos Skarlatos
2014-01-02 15:02 ` Konstantinos Skarlatos
2014-02-25 19:22 ` Jannis Achstetter
16 siblings, 1 reply; 34+ messages in thread
From: Konstantinos Skarlatos @ 2014-01-02 14:32 UTC (permalink / raw)
To: Liu Bo, linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
Hello, I am trying to test your patches and they do not apply to latest
3.12 source or 3.13 git. Am I doing something wrong?
---logs for 3.12---
Hunk #1 succeeded at 59 with fuzz 2 (offset 1 line).
patching file init/Kconfig
Hunk #1 succeeded at 1085 (offset 96 lines).
Hunk #2 succeeded at 1096 (offset 96 lines).
patching file fs/btrfs/ctree.h
Hunk #1 FAILED at 3692.
1 out of 1 hunk FAILED -- saving rejects to file fs/btrfs/ctree.h.rej
patching file fs/btrfs/extent-tree.c
Hunk #1 FAILED at 5996.
Hunk #2 FAILED at 6023.
2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/extent-tree.c.rej
patching file fs/btrfs/file-item.c
Hunk #1 FAILED at 887.
Hunk #2 succeeded at 765 with fuzz 2 (offset -151 lines).
Hunk #3 FAILED at 978.
Hunk #4 FAILED at 1061.
Hunk #5 FAILED at 1094.
4 out of 5 hunks FAILED -- saving rejects to file fs/btrfs/file-item.c.rej
patching file fs/btrfs/inode.c
Hunk #1 FAILED at 969.
Hunk #2 FAILED at 2364.
2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/inode.c.rej
---logs for 3.13---
Hunk #1 succeeded at 59 with fuzz 2 (offset 1 line).
patching file init/Kconfig
Hunk #1 succeeded at 1078 (offset 89 lines).
Hunk #2 succeeded at 1089 (offset 89 lines).
patching file fs/btrfs/ctree.h
Hunk #1 FAILED at 3692.
1 out of 1 hunk FAILED -- saving rejects to file fs/btrfs/ctree.h.rej
patching file fs/btrfs/extent-tree.c
Hunk #1 FAILED at 5996.
Hunk #2 FAILED at 6023.
2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/extent-tree.c.rej
patching file fs/btrfs/file-item.c
Hunk #1 FAILED at 887.
Hunk #2 succeeded at 768 with fuzz 2 (offset -148 lines).
Hunk #3 FAILED at 978.
Hunk #4 FAILED at 1061.
Hunk #5 FAILED at 1094.
4 out of 5 hunks FAILED -- saving rejects to file fs/btrfs/file-item.c.rej
patching file fs/btrfs/inode.c
Hunk #1 FAILED at 969.
Hunk #2 FAILED at 2364.
2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/inode.c.rej
On 30/12/2013 10:12 πμ, Liu Bo wrote:
> Hello,
>
> Here is the New Year patch bomb :-)
>
> Data deduplication is a specialized data compression technique for eliminating
> duplicate copies of repeating data.[1]
>
> This patch set is also related to "Content based storage" in project ideas[2],
> it introduces inband data deduplication for btrfs and dedup/dedupe is for short.
>
> PATCH 1 is a hang fix with deduplication on, but it's also useful without
> dedup in practice use.
>
> PATCH 2 and 3 are targetting delayed refs' scalability problems, which are
> uncovered by the dedup feature.
>
> PATCH 4 is a speed-up improvement, which is about dedup and quota.
>
> PATCH 5-8 is the preparation work for dedup implementation.
>
> PATCH 9 shows how we implement dedup feature.
>
> PATCH 10 fixes a backref walking bug with dedup.
>
> PATCH 11 fixes a free space bug of dedup extents on error handling.
>
> PATCH 12 adds the ioctl to control dedup feature.
>
> PATCH 13 fixes the metadata ENOSPC problem with dedup which has been there
> WAY TOO LONG.
>
> PATCH 14 fixes a race bug on dedup writes.
>
> And there is also a btrfs-progs patch(PATCH 15) which offers all details about
> how to control the dedup feature.
>
> I've tested this with xfstests by adding a inline dedup 'enable & on' in xfstests'
> mount and scratch_mount.
>
> TODO:
> * a bit-to-bit comparison callback.
>
> All comments are welcome!
>
>
> [1]: http://en.wikipedia.org/wiki/Data_deduplication
> [2]: https://btrfs.wiki.kernel.org/index.php/Project_ideas#Content_based_storage
>
> v8:
> - fix the race crash of dedup ref again.
> - fix the metadata ENOSPC problem with dedup.
>
> v7:
> - rebase onto the lastest btrfs
> - break a big patch into smaller ones to make reviewers happy.
> - kill mount options of dedup and use ioctl method instead.
> - fix two crash due to the special dedup ref
>
> For former patch sets:
> v6: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27512
> v5: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27257
> v4: http://thread.gmane.org/gmane.comp.file-systems.btrfs/25751
> v3: http://comments.gmane.org/gmane.comp.file-systems.btrfs/25433
> v2: http://comments.gmane.org/gmane.comp.file-systems.btrfs/24959
>
> Liu Bo (14):
> Btrfs: skip merge part for delayed data refs
> Btrfs: improve the delayed refs process in rm case
> Btrfs: introduce a head ref rbtree
> Btrfs: disable qgroups accounting when quata_enable is 0
> Btrfs: introduce dedup tree and relatives
> Btrfs: introduce dedup tree operations
> Btrfs: introduce dedup state
> Btrfs: make ordered extent aware of dedup
> Btrfs: online(inband) data dedup
> Btrfs: skip dedup reference during backref walking
> Btrfs: don't return space for dedup extent
> Btrfs: add ioctl of dedup control
> Btrfs: fix dedupe 'ENOSPC' problem
> Btrfs: fix a crash of dedup ref
>
> fs/btrfs/backref.c | 9 +
> fs/btrfs/ctree.c | 2 +-
> fs/btrfs/ctree.h | 86 ++++++
> fs/btrfs/delayed-ref.c | 161 +++++++----
> fs/btrfs/delayed-ref.h | 8 +
> fs/btrfs/disk-io.c | 40 +++
> fs/btrfs/extent-tree.c | 208 ++++++++++++--
> fs/btrfs/extent_io.c | 22 +-
> fs/btrfs/extent_io.h | 16 ++
> fs/btrfs/file-item.c | 244 +++++++++++++++++
> fs/btrfs/inode.c | 635 ++++++++++++++++++++++++++++++++++++++-----
> fs/btrfs/ioctl.c | 167 ++++++++++++
> fs/btrfs/ordered-data.c | 38 ++-
> fs/btrfs/ordered-data.h | 13 +-
> fs/btrfs/qgroup.c | 3 +
> fs/btrfs/relocation.c | 3 +
> fs/btrfs/transaction.c | 4 +-
> include/trace/events/btrfs.h | 3 +-
> include/uapi/linux/btrfs.h | 11 +
> 19 files changed, 1501 insertions(+), 172 deletions(-)
>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2014-01-02 14:32 ` [RFC PATCH v8 00/14] Online(inband) data deduplication Konstantinos Skarlatos
@ 2014-01-02 15:02 ` Konstantinos Skarlatos
0 siblings, 0 replies; 34+ messages in thread
From: Konstantinos Skarlatos @ 2014-01-02 15:02 UTC (permalink / raw)
To: Liu Bo, linux-btrfs; +Cc: Marcel Ritter, Christian Robert, alanqk@gmail.com
Sorry for the spam, i just mixed up the order of your patches. they now
apply cleanly to 3.13 git.
Thanks
On 2/1/2014 4:32 μμ, Konstantinos Skarlatos wrote:
> Hello, I am trying to test your patches and they do not apply to
> latest 3.12 source or 3.13 git. Am I doing something wrong?
>
> ---logs for 3.12---
>
> Hunk #1 succeeded at 59 with fuzz 2 (offset 1 line).
> patching file init/Kconfig
> Hunk #1 succeeded at 1085 (offset 96 lines).
> Hunk #2 succeeded at 1096 (offset 96 lines).
> patching file fs/btrfs/ctree.h
> Hunk #1 FAILED at 3692.
> 1 out of 1 hunk FAILED -- saving rejects to file fs/btrfs/ctree.h.rej
> patching file fs/btrfs/extent-tree.c
> Hunk #1 FAILED at 5996.
> Hunk #2 FAILED at 6023.
> 2 out of 2 hunks FAILED -- saving rejects to file
> fs/btrfs/extent-tree.c.rej
> patching file fs/btrfs/file-item.c
> Hunk #1 FAILED at 887.
> Hunk #2 succeeded at 765 with fuzz 2 (offset -151 lines).
> Hunk #3 FAILED at 978.
> Hunk #4 FAILED at 1061.
> Hunk #5 FAILED at 1094.
> 4 out of 5 hunks FAILED -- saving rejects to file
> fs/btrfs/file-item.c.rej
> patching file fs/btrfs/inode.c
> Hunk #1 FAILED at 969.
> Hunk #2 FAILED at 2364.
> 2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/inode.c.rej
>
> ---logs for 3.13---
> Hunk #1 succeeded at 59 with fuzz 2 (offset 1 line).
> patching file init/Kconfig
> Hunk #1 succeeded at 1078 (offset 89 lines).
> Hunk #2 succeeded at 1089 (offset 89 lines).
> patching file fs/btrfs/ctree.h
> Hunk #1 FAILED at 3692.
> 1 out of 1 hunk FAILED -- saving rejects to file fs/btrfs/ctree.h.rej
> patching file fs/btrfs/extent-tree.c
> Hunk #1 FAILED at 5996.
> Hunk #2 FAILED at 6023.
> 2 out of 2 hunks FAILED -- saving rejects to file
> fs/btrfs/extent-tree.c.rej
> patching file fs/btrfs/file-item.c
> Hunk #1 FAILED at 887.
> Hunk #2 succeeded at 768 with fuzz 2 (offset -148 lines).
> Hunk #3 FAILED at 978.
> Hunk #4 FAILED at 1061.
> Hunk #5 FAILED at 1094.
> 4 out of 5 hunks FAILED -- saving rejects to file
> fs/btrfs/file-item.c.rej
> patching file fs/btrfs/inode.c
> Hunk #1 FAILED at 969.
> Hunk #2 FAILED at 2364.
> 2 out of 2 hunks FAILED -- saving rejects to file fs/btrfs/inode.c.rej
>
>
> On 30/12/2013 10:12 πμ, Liu Bo wrote:
>> Hello,
>>
>> Here is the New Year patch bomb :-)
>>
>> Data deduplication is a specialized data compression technique for
>> eliminating
>> duplicate copies of repeating data.[1]
>>
>> This patch set is also related to "Content based storage" in project
>> ideas[2],
>> it introduces inband data deduplication for btrfs and dedup/dedupe is
>> for short.
>>
>> PATCH 1 is a hang fix with deduplication on, but it's also useful
>> without
>> dedup in practice use.
>>
>> PATCH 2 and 3 are targetting delayed refs' scalability problems,
>> which are
>> uncovered by the dedup feature.
>>
>> PATCH 4 is a speed-up improvement, which is about dedup and quota.
>>
>> PATCH 5-8 is the preparation work for dedup implementation.
>>
>> PATCH 9 shows how we implement dedup feature.
>>
>> PATCH 10 fixes a backref walking bug with dedup.
>>
>> PATCH 11 fixes a free space bug of dedup extents on error handling.
>>
>> PATCH 12 adds the ioctl to control dedup feature.
>>
>> PATCH 13 fixes the metadata ENOSPC problem with dedup which has been
>> there
>> WAY TOO LONG.
>>
>> PATCH 14 fixes a race bug on dedup writes.
>>
>> And there is also a btrfs-progs patch(PATCH 15) which offers all
>> details about
>> how to control the dedup feature.
>>
>> I've tested this with xfstests by adding a inline dedup 'enable & on'
>> in xfstests'
>> mount and scratch_mount.
>>
>> TODO:
>> * a bit-to-bit comparison callback.
>>
>> All comments are welcome!
>>
>>
>> [1]: http://en.wikipedia.org/wiki/Data_deduplication
>> [2]:
>> https://btrfs.wiki.kernel.org/index.php/Project_ideas#Content_based_storage
>>
>> v8:
>> - fix the race crash of dedup ref again.
>> - fix the metadata ENOSPC problem with dedup.
>>
>> v7:
>> - rebase onto the lastest btrfs
>> - break a big patch into smaller ones to make reviewers happy.
>> - kill mount options of dedup and use ioctl method instead.
>> - fix two crash due to the special dedup ref
>>
>> For former patch sets:
>> v6: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27512
>> v5: http://thread.gmane.org/gmane.comp.file-systems.btrfs/27257
>> v4: http://thread.gmane.org/gmane.comp.file-systems.btrfs/25751
>> v3: http://comments.gmane.org/gmane.comp.file-systems.btrfs/25433
>> v2: http://comments.gmane.org/gmane.comp.file-systems.btrfs/24959
>>
>> Liu Bo (14):
>> Btrfs: skip merge part for delayed data refs
>> Btrfs: improve the delayed refs process in rm case
>> Btrfs: introduce a head ref rbtree
>> Btrfs: disable qgroups accounting when quata_enable is 0
>> Btrfs: introduce dedup tree and relatives
>> Btrfs: introduce dedup tree operations
>> Btrfs: introduce dedup state
>> Btrfs: make ordered extent aware of dedup
>> Btrfs: online(inband) data dedup
>> Btrfs: skip dedup reference during backref walking
>> Btrfs: don't return space for dedup extent
>> Btrfs: add ioctl of dedup control
>> Btrfs: fix dedupe 'ENOSPC' problem
>> Btrfs: fix a crash of dedup ref
>>
>> fs/btrfs/backref.c | 9 +
>> fs/btrfs/ctree.c | 2 +-
>> fs/btrfs/ctree.h | 86 ++++++
>> fs/btrfs/delayed-ref.c | 161 +++++++----
>> fs/btrfs/delayed-ref.h | 8 +
>> fs/btrfs/disk-io.c | 40 +++
>> fs/btrfs/extent-tree.c | 208 ++++++++++++--
>> fs/btrfs/extent_io.c | 22 +-
>> fs/btrfs/extent_io.h | 16 ++
>> fs/btrfs/file-item.c | 244 +++++++++++++++++
>> fs/btrfs/inode.c | 635
>> ++++++++++++++++++++++++++++++++++++++-----
>> fs/btrfs/ioctl.c | 167 ++++++++++++
>> fs/btrfs/ordered-data.c | 38 ++-
>> fs/btrfs/ordered-data.h | 13 +-
>> fs/btrfs/qgroup.c | 3 +
>> fs/btrfs/relocation.c | 3 +
>> fs/btrfs/transaction.c | 4 +-
>> include/trace/events/btrfs.h | 3 +-
>> include/uapi/linux/btrfs.h | 11 +
>> 19 files changed, 1501 insertions(+), 172 deletions(-)
>>
>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2013-12-30 8:12 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
2013-12-30 11:34 ` Martin Steigerwald
@ 2014-01-14 17:34 ` David Sterba
2014-01-15 1:35 ` Liu Bo
1 sibling, 1 reply; 34+ messages in thread
From: David Sterba @ 2014-01-14 17:34 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs, Marcel Ritter, Christian Robert, alanqk@gmail.com
On Mon, Dec 30, 2013 at 04:12:55PM +0800, Liu Bo wrote:
> --- a/ctree.h
> +++ b/ctree.h
> @@ -470,6 +470,7 @@ struct btrfs_super_block {
> #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
> #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
> #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
> +#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
FYI, this incompat bit is taken by Josef's NO_HOLE feature, now heading
to next merge window, so I've used 10 for dedup in integration branch.
> --- a/ioctl.h
> +++ b/ioctl.h
> @@ -430,6 +430,15 @@ struct btrfs_ioctl_get_dev_stats {
> __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> };
>
> +/* deduplication control ioctl modes */
> +#define BTRFS_DEDUP_CTL_ENABLE 1
> +#define BTRFS_DEDUP_CTL_DISABLE 2
> +#define BTRFS_DEDUP_CTL_SET_BS 3
> +struct btrfs_ioctl_dedup_args {
> + __u64 cmd;
> + __u64 bs;
I've spotted that you did not reserve any space for future extensions of
the ioctl, especially the in-band dedup can be quite heavy, I think
we'll want some tunables in the future.
> +};
> +
> /* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
> #define BTRFS_QUOTA_CTL_ENABLE 1
> #define BTRFS_QUOTA_CTL_DISABLE 2
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2014-01-14 17:34 ` David Sterba
@ 2014-01-15 1:35 ` Liu Bo
2014-01-17 16:14 ` David Sterba
0 siblings, 1 reply; 34+ messages in thread
From: Liu Bo @ 2014-01-15 1:35 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs
On Tue, Jan 14, 2014 at 06:34:19PM +0100, David Sterba wrote:
> On Mon, Dec 30, 2013 at 04:12:55PM +0800, Liu Bo wrote:
> > --- a/ctree.h
> > +++ b/ctree.h
> > @@ -470,6 +470,7 @@ struct btrfs_super_block {
> > #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
> > #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
> > #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
> > +#define BTRFS_FEATURE_INCOMPAT_DEDUP (1ULL << 9)
>
> FYI, this incompat bit is taken by Josef's NO_HOLE feature, now heading
> to next merge window, so I've used 10 for dedup in integration branch.
Thanks for the notice, David, I'll update it in the next version.
>
> > --- a/ioctl.h
> > +++ b/ioctl.h
> > @@ -430,6 +430,15 @@ struct btrfs_ioctl_get_dev_stats {
> > __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> > };
> >
> > +/* deduplication control ioctl modes */
> > +#define BTRFS_DEDUP_CTL_ENABLE 1
> > +#define BTRFS_DEDUP_CTL_DISABLE 2
> > +#define BTRFS_DEDUP_CTL_SET_BS 3
> > +struct btrfs_ioctl_dedup_args {
> > + __u64 cmd;
> > + __u64 bs;
>
> I've spotted that you did not reserve any space for future extensions of
> the ioctl, especially the in-band dedup can be quite heavy, I think
> we'll want some tunables in the future.
>
Good point, I think 128 bytes can be enough for that, agree?
I didn't put much notice on that because I kept stuck in fixing more urgent ENOSPC
problem, it looks like I can hardly bypass this endless issue with dedup enabled,
I have to fix it thoroughly...
Thanks,
-liubo
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] Btrfs-progs: add dedup subcommand
2014-01-15 1:35 ` Liu Bo
@ 2014-01-17 16:14 ` David Sterba
0 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2014-01-17 16:14 UTC (permalink / raw)
To: Liu Bo; +Cc: dsterba, linux-btrfs
On Wed, Jan 15, 2014 at 09:35:17AM +0800, Liu Bo wrote:
> > > @@ -430,6 +430,15 @@ struct btrfs_ioctl_get_dev_stats {
> > > __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> > > };
> > >
> > > +/* deduplication control ioctl modes */
> > > +#define BTRFS_DEDUP_CTL_ENABLE 1
> > > +#define BTRFS_DEDUP_CTL_DISABLE 2
> > > +#define BTRFS_DEDUP_CTL_SET_BS 3
> > > +struct btrfs_ioctl_dedup_args {
> > > + __u64 cmd;
> > > + __u64 bs;
> >
> > I've spotted that you did not reserve any space for future extensions of
> > the ioctl, especially the in-band dedup can be quite heavy, I think
> > we'll want some tunables in the future.
> >
>
> Good point, I think 128 bytes can be enough for that, agree?
Yes, should be enough.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
` (15 preceding siblings ...)
2014-01-02 14:32 ` [RFC PATCH v8 00/14] Online(inband) data deduplication Konstantinos Skarlatos
@ 2014-02-25 19:22 ` Jannis Achstetter
2014-02-25 19:39 ` Jannis Achstetter
2014-02-26 20:20 ` Jannis Achstetter
16 siblings, 2 replies; 34+ messages in thread
From: Jannis Achstetter @ 2014-02-25 19:22 UTC (permalink / raw)
To: linux-btrfs
Hello Liu, hello list,
Liu Bo <bo.li.liu <at> oracle.com> writes:
> Here is the New Year patch bomb
I tried yout btrfs deduplication patches today (on top of 3.13.2-gentoo) and
it seems that the deduplication works great (when copying the same or
similar data to the file system, the used size reported by df -h grows less
than the data that is copied to it on the second time).
However, there are disturbing messages in the kernel log:
[46620.519741] btrfs-delalloc-: page allocation failure: order:5, mode:0x104050
[46620.519743] CPU: 1 PID: 25246 Comm: btrfs-delalloc- Tainted: G
O 3.13.2-gentoo #4
[46620.519744] Hardware name: MSI MS-7640/890FXA-GD70 (MS-7640) , BIOS
V1.12 10/06/2011
[46620.519745] ffff880098881b38 ffffffff81920b14 0000000000104050
ffffffff81145927
[46620.519747] 0000000000000000 ffff880237ffc800 0000000000000000
0000000000000005
[46620.519749] 0000000000000001 ffffffff8191ce20 ffff880237ffc808
0000000000000002
[46620.519750] Call Trace:
[46620.519752] [<ffffffff81920b14>] ? dump_stack+0x49/0x6a
[46620.519754] [<ffffffff81145927>] ? warn_alloc_failed+0xe7/0x140
[46620.519757] [<ffffffff8191ce20>] ? __alloc_pages_direct_compact+0xa2/0x1b0
[46620.519759] [<ffffffff81148fa4>] ? __alloc_pages_nodemask+0x7f4/0x970
[46620.519761] [<ffffffff8118376f>] ? alloc_pages_current+0xaf/0x180
[46620.519763] [<ffffffff81144cc5>] ? __get_free_pages+0x5/0x40
[46620.519765] [<ffffffff8115fb1b>] ? kmalloc_order_trace+0x3b/0xe0
[46620.519767] [<ffffffff813291f5>] ? run_delalloc_dedup+0x685/0xba0
[46620.519769] [<ffffffff813280ae>] ? run_locked_range.constprop.66+0xce/0xd0
[46620.519771] [<ffffffff8109fd90>] ? detach_if_pending+0x100/0x100
[46620.519773] [<ffffffff81329785>] ? async_cow_start+0x75/0xa0
[46620.519775] [<ffffffff8134da99>] ? worker_loop+0x149/0x550
[46620.519777] [<ffffffff8134d950>] ? btrfs_queue_worker+0x2f0/0x2f0
[46620.519779] [<ffffffff810b4481>] ? kthread+0xc1/0xe0
[46620.519781] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
[46620.519783] [<ffffffff819286bc>] ? ret_from_fork+0x7c/0xb0
[46620.519785] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
(many of them, as to be seen here: http://bpaste.net/show/182698/ )
I use btrfs with lzo compression:
/dev/sdc2 on /mnt/steamdir type btrfs (rw,compress=lzo)
Kernel config is here:
http://bpaste.net/show/182706/
If you need any more info, just let me know!
Thanks for your work and all the best,
Jannis Achstetter
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2014-02-25 19:22 ` Jannis Achstetter
@ 2014-02-25 19:39 ` Jannis Achstetter
2014-02-26 20:20 ` Jannis Achstetter
1 sibling, 0 replies; 34+ messages in thread
From: Jannis Achstetter @ 2014-02-25 19:39 UTC (permalink / raw)
To: linux-btrfs
Jannis Achstetter <jannis_achstetter <at> web.de> writes:
>
> Hello Liu, hello list,
>
> Liu Bo <bo.li.liu <at> oracle.com> writes:
> > Here is the New Year patch bomb
>
Some more info I forgot: I set the dedup block size to 128k but I forgot it
the first time:
> btrfs dedup enable /mnt/steamdir
> btrfs dedup on /mnt/steamdir
> btrfs dedup off /mnt/steamdir
> btrfs dedup on -b 128k /mnt/steamdir
The data written to the file system seems not to get corrupted. I copied a
>20GB file to the fs two times with different names and the sha1sum is
identical both time and matches the source file.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2014-02-25 19:22 ` Jannis Achstetter
2014-02-25 19:39 ` Jannis Achstetter
@ 2014-02-26 20:20 ` Jannis Achstetter
2014-02-27 2:39 ` Liu Bo
1 sibling, 1 reply; 34+ messages in thread
From: Jannis Achstetter @ 2014-02-26 20:20 UTC (permalink / raw)
To: linux-btrfs
Jannis Achstetter <jannis_achstetter <at> web.de> writes:
> I tried yout btrfs deduplication patches today (on top of 3.13.2-gentoo) and
> it seems that the deduplication works great (when copying the same or
> similar data to the file system, the used size reported by df -h grows less
> than the data that is copied to it on the second time).
> However, there are disturbing messages in the kernel log:
Me again :)
Today (PC rebooted), there are other messages in the log with traces like:
[ 253.971188] BUG: scheduling while atomic: btrfs-transacti/5985/0x00000003
[ 253.971194] Modules linked in: snd_aloop vboxnetflt(O) vboxnetadp(O)
vboxdrv(O) microcode
[ 253.971208] CPU: 2 PID: 5985 Comm: btrfs-transacti Tainted: G W O
3.13.2-gentoo #4
[ 253.971212] Hardware name: MSI MS-7640/890FXA-GD70 (MS-7640) , BIOS
V1.12 10/06/2011
[ 253.971215] ffff88022cf3b8a8 ffffffff81920b14 ffff880237c92b40
ffffffff8191c304
[ 253.971221] ffffffff81924bd5 ffff88022df7d750 ffff88022cf3bfd8
0000000000012b40
[ 253.971227] 0000000000012b40 ffff88022df7d750 ffff8800c2ff7aa8
0000000000000020
[ 253.971233] Call Trace:
[ 253.971243] [<ffffffff81920b14>] ? dump_stack+0x49/0x6a
[ 253.971251] [<ffffffff8191c304>] ? __schedule_bug+0x3e/0x4b
[ 253.971258] [<ffffffff81924bd5>] ? __schedule+0x7f5/0x8e0
[ 253.971266] [<ffffffff813d16c0>] ? submit_bio+0x60/0x130
[ 253.971273] [<ffffffff813497d3>] ? btrfs_map_bio+0x2d3/0x540
[ 253.971280] [<ffffffff810e6c8d>] ? ktime_get_ts+0x3d/0xd0
[ 253.971287] [<ffffffff81116c14>] ? delayacct_end+0x84/0xa0
[ 253.971293] [<ffffffff81140700>] ? filemap_fdatawait+0x20/0x20
[ 253.971299] [<ffffffff81924f43>] ? io_schedule+0x83/0xd0
[ 253.971305] [<ffffffff81140705>] ? sleep_on_page+0x5/0x10
[ 253.971312] [<ffffffff819252d4>] ? __wait_on_bit+0x54/0x80
[ 253.971319] [<ffffffff8114051f>] ? wait_on_page_bit+0x7f/0x90
[ 253.971321] [<ffffffff810d01b0>] ? autoremove_wake_function+0x30/0x30
[ 253.971323] [<ffffffff81341172>] ? read_extent_buffer_pages+0x2a2/0x2d0
[ 253.971325] [<ffffffff813172a0>] ? free_root_pointers+0x60/0x60
[ 253.971327] [<ffffffff81318e29>] ?
btree_read_extent_buffer_pages.constprop.53+0xa9/0x110
[ 253.971330] [<ffffffff813193ca>] ? read_tree_block+0x4a/0x80
[ 253.971332] [<ffffffff812fa657>] ? read_block_for_search.isra.32+0x177/0x3a0
[ 253.971334] [<ffffffff812f527a>] ? unlock_up+0x13a/0x160
[ 253.971336] [<ffffffff812fc980>] ? btrfs_search_slot+0x400/0x970
[ 253.971338] [<ffffffff8131531a>] ? btrfs_free_dedup_extent+0x7a/0x1c0
[ 253.971340] [<ffffffff813035e9>] ? extent_data_ref_offset.isra.30+0x79/0x110
[ 253.971342] [<ffffffff813061fc>] ? __btrfs_free_extent+0xa1c/0xc70
[ 253.971344] [<ffffffff8130aa3c>] ? run_clustered_refs+0x47c/0x1110
[ 253.971347] [<ffffffff813645ed>] ? find_ref_head+0x5d/0x90
[ 253.971348] [<ffffffff8130f388>] ? btrfs_run_delayed_refs+0xc8/0x510
[ 253.971351] [<ffffffff8131fe15>] ? btrfs_commit_transaction+0x55/0x990
[ 253.971353] [<ffffffff813207da>] ? start_transaction+0x8a/0x560
[ 253.971355] [<ffffffff8131bead>] ? transaction_kthread+0x19d/0x230
[ 253.971357] [<ffffffff8131bd10>] ? btrfs_cleanup_transaction+0x540/0x540
[ 253.971360] [<ffffffff810b4481>] ? kthread+0xc1/0xe0
[ 253.971362] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
[ 253.971364] [<ffffffff819286bc>] ? ret_from_fork+0x7c/0xb0
[ 253.971366] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
(More of them at http://bpaste.net/show/183075/ )
One more question: Do I have to run "btrfs dedup on -b 128k /mnt/steamdir"
after every mount or is that info stored across mounts?
Best regards,
Jannis
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [RFC PATCH v8 00/14] Online(inband) data deduplication
2014-02-26 20:20 ` Jannis Achstetter
@ 2014-02-27 2:39 ` Liu Bo
0 siblings, 0 replies; 34+ messages in thread
From: Liu Bo @ 2014-02-27 2:39 UTC (permalink / raw)
To: Jannis Achstetter; +Cc: linux-btrfs
Hi Jannis,
On Wed, Feb 26, 2014 at 08:20:01PM +0000, Jannis Achstetter wrote:
> Jannis Achstetter <jannis_achstetter <at> web.de> writes:
> > I tried yout btrfs deduplication patches today (on top of 3.13.2-gentoo) and
> > it seems that the deduplication works great (when copying the same or
> > similar data to the file system, the used size reported by df -h grows less
> > than the data that is copied to it on the second time).
> > However, there are disturbing messages in the kernel log:
>
> Me again :)
>
> Today (PC rebooted), there are other messages in the log with traces like:
> [ 253.971188] BUG: scheduling while atomic: btrfs-transacti/5985/0x00000003
> [ 253.971194] Modules linked in: snd_aloop vboxnetflt(O) vboxnetadp(O)
> vboxdrv(O) microcode
> [ 253.971208] CPU: 2 PID: 5985 Comm: btrfs-transacti Tainted: G W O
> 3.13.2-gentoo #4
> [ 253.971212] Hardware name: MSI MS-7640/890FXA-GD70 (MS-7640) , BIOS
> V1.12 10/06/2011
> [ 253.971215] ffff88022cf3b8a8 ffffffff81920b14 ffff880237c92b40
> ffffffff8191c304
> [ 253.971221] ffffffff81924bd5 ffff88022df7d750 ffff88022cf3bfd8
> 0000000000012b40
> [ 253.971227] 0000000000012b40 ffff88022df7d750 ffff8800c2ff7aa8
> 0000000000000020
> [ 253.971233] Call Trace:
> [ 253.971243] [<ffffffff81920b14>] ? dump_stack+0x49/0x6a
> [ 253.971251] [<ffffffff8191c304>] ? __schedule_bug+0x3e/0x4b
> [ 253.971258] [<ffffffff81924bd5>] ? __schedule+0x7f5/0x8e0
> [ 253.971266] [<ffffffff813d16c0>] ? submit_bio+0x60/0x130
> [ 253.971273] [<ffffffff813497d3>] ? btrfs_map_bio+0x2d3/0x540
> [ 253.971280] [<ffffffff810e6c8d>] ? ktime_get_ts+0x3d/0xd0
> [ 253.971287] [<ffffffff81116c14>] ? delayacct_end+0x84/0xa0
> [ 253.971293] [<ffffffff81140700>] ? filemap_fdatawait+0x20/0x20
> [ 253.971299] [<ffffffff81924f43>] ? io_schedule+0x83/0xd0
> [ 253.971305] [<ffffffff81140705>] ? sleep_on_page+0x5/0x10
> [ 253.971312] [<ffffffff819252d4>] ? __wait_on_bit+0x54/0x80
> [ 253.971319] [<ffffffff8114051f>] ? wait_on_page_bit+0x7f/0x90
> [ 253.971321] [<ffffffff810d01b0>] ? autoremove_wake_function+0x30/0x30
> [ 253.971323] [<ffffffff81341172>] ? read_extent_buffer_pages+0x2a2/0x2d0
> [ 253.971325] [<ffffffff813172a0>] ? free_root_pointers+0x60/0x60
> [ 253.971327] [<ffffffff81318e29>] ?
> btree_read_extent_buffer_pages.constprop.53+0xa9/0x110
> [ 253.971330] [<ffffffff813193ca>] ? read_tree_block+0x4a/0x80
> [ 253.971332] [<ffffffff812fa657>] ? read_block_for_search.isra.32+0x177/0x3a0
> [ 253.971334] [<ffffffff812f527a>] ? unlock_up+0x13a/0x160
> [ 253.971336] [<ffffffff812fc980>] ? btrfs_search_slot+0x400/0x970
> [ 253.971338] [<ffffffff8131531a>] ? btrfs_free_dedup_extent+0x7a/0x1c0
> [ 253.971340] [<ffffffff813035e9>] ? extent_data_ref_offset.isra.30+0x79/0x110
> [ 253.971342] [<ffffffff813061fc>] ? __btrfs_free_extent+0xa1c/0xc70
> [ 253.971344] [<ffffffff8130aa3c>] ? run_clustered_refs+0x47c/0x1110
> [ 253.971347] [<ffffffff813645ed>] ? find_ref_head+0x5d/0x90
> [ 253.971348] [<ffffffff8130f388>] ? btrfs_run_delayed_refs+0xc8/0x510
> [ 253.971351] [<ffffffff8131fe15>] ? btrfs_commit_transaction+0x55/0x990
> [ 253.971353] [<ffffffff813207da>] ? start_transaction+0x8a/0x560
> [ 253.971355] [<ffffffff8131bead>] ? transaction_kthread+0x19d/0x230
> [ 253.971357] [<ffffffff8131bd10>] ? btrfs_cleanup_transaction+0x540/0x540
> [ 253.971360] [<ffffffff810b4481>] ? kthread+0xc1/0xe0
> [ 253.971362] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
> [ 253.971364] [<ffffffff819286bc>] ? ret_from_fork+0x7c/0xb0
> [ 253.971366] [<ffffffff810b43c0>] ? kthread_create_on_node+0x190/0x190
>
> (More of them at http://bpaste.net/show/183075/ )
Yeah, I've also found this and fixed it locally :)
>
> One more question: Do I have to run "btrfs dedup on -b 128k /mnt/steamdir"
> after every mount or is that info stored across mounts?
For now, yes, the default value is 8K, ie, we reset it on every mount.
Thanks for the report!
-liubo
^ permalink raw reply [flat|nested] 34+ messages in thread
end of thread, other threads:[~2014-02-27 2:39 UTC | newest]
Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-30 8:12 [RFC PATCH v8 00/14] Online(inband) data deduplication Liu Bo
2013-12-30 8:12 ` [PATCH v8 01/14] Btrfs: skip merge part for delayed data refs Liu Bo
2013-12-30 8:12 ` [PATCH v8 02/14] Btrfs: improve the delayed refs process in rm case Liu Bo
2013-12-30 8:12 ` [PATCH v8 03/14] Btrfs: introduce a head ref rbtree Liu Bo
2013-12-30 8:12 ` [PATCH v8 04/14] Btrfs: disable qgroups accounting when quata_enable is 0 Liu Bo
2013-12-30 8:12 ` [PATCH v8 05/14] Btrfs: introduce dedup tree and relatives Liu Bo
2013-12-30 8:12 ` [PATCH v8 06/14] Btrfs: introduce dedup tree operations Liu Bo
2013-12-30 8:12 ` [PATCH v8 07/14] Btrfs: introduce dedup state Liu Bo
2013-12-30 8:12 ` [PATCH v8 08/14] Btrfs: make ordered extent aware of dedup Liu Bo
2013-12-30 8:12 ` [PATCH v8 09/14] Btrfs: online(inband) data dedup Liu Bo
2013-12-30 8:12 ` [PATCH v8 10/14] Btrfs: skip dedup reference during backref walking Liu Bo
2013-12-30 8:12 ` [PATCH v8 11/14] Btrfs: don't return space for dedup extent Liu Bo
2013-12-30 8:12 ` [PATCH v8 12/14] Btrfs: add ioctl of dedup control Liu Bo
2013-12-30 8:12 ` [PATCH v8 13/14] Btrfs: fix dedupe 'ENOSPC' problem Liu Bo
2013-12-30 8:12 ` [PATCH v8 14/14] Btrfs: fix a crash of dedup ref Liu Bo
2013-12-30 8:12 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
2013-12-30 11:34 ` Martin Steigerwald
2013-12-31 3:18 ` Liu Bo
2013-12-31 3:24 ` Kai Krakow
2014-01-14 17:34 ` David Sterba
2014-01-15 1:35 ` Liu Bo
2014-01-17 16:14 ` David Sterba
2014-01-02 14:32 ` [RFC PATCH v8 00/14] Online(inband) data deduplication Konstantinos Skarlatos
2014-01-02 15:02 ` Konstantinos Skarlatos
2014-02-25 19:22 ` Jannis Achstetter
2014-02-25 19:39 ` Jannis Achstetter
2014-02-26 20:20 ` Jannis Achstetter
2014-02-27 2:39 ` Liu Bo
-- strict thread matches above, loose matches on Subject: below --
2013-07-31 15:37 [RFC PATCH v5 0/5] Online " Liu Bo
2013-07-31 15:37 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
2013-07-31 16:30 ` Stefan Behrens
2013-08-01 10:17 ` Liu Bo
2013-08-01 22:01 ` Mark Fasheh
2013-08-02 2:29 ` Liu Bo
2013-05-14 12:08 [RFC PATCH V4 0/2] Online data deduplication Liu Bo
2013-05-14 12:08 ` [PATCH] Btrfs-progs: add dedup subcommand Liu Bo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).