Ext4 snapshots
cover Ext4 snapshots
Hi All,
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.
Thanks,
Amir.
[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental)
[PATCH v1 02/36] ext4: snapshot debugging support
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks
[PATCH v1 04/36] ext4: snapshot hooks - block bitmap access
[PATCH v1 05/36] ext4: snapshot hooks - delete blocks
[PATCH v1 06/36] ext4: snapshot hooks - move data blocks
[PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocks [PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TB [PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshot [PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot
[PATCH v1 20/36] ext4: snapshot control - fix new snapshot
[PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshot [PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implement journal_release_buffer() [PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid in journal_head [PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits [PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshot [PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads [PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshots [PATCH v1 36/36] ext4: snapshot rocompat - enable rw mount
fs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++ fs/ext4/ext4.h | 188 ++++- fs/ext4/ext4_jbd2.c | 162 ++++- fs/ext4/ext4_jbd2.h | 266 ++++++- fs/ext4/extents.c | 157 ++++- fs/ext4/file.c | 11 +- fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++ fs/ext4/mballoc.c | 161 ++++- fs/ext4/move_extent.c | 3 +- fs/ext4/namei.c | 9 + fs/ext4/resize.c | 19 +- fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++ fs/ext4/snapshot.h | 690 ++++++++++++++++ fs/ext4/snapshot_buffer.c | 393 +++++++++ fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)
PATCH 1/36 ext4: EXT4 snapshots (Experimental)
From: Amir Goldstein <[email protected]>
Built-in snapshots support for ext4.
Requires that the filesystem has the has_snapshot and exclude_bitmap features and that block size is equal to system page size. Snapshots are not supported with 64bit and meta_bg features and the filesystem must be mounted with ordered data mode.
--- fs/ext4/Kconfig | 11 ++ fs/ext4/Makefile | 2 + fs/ext4/balloc.c | 2 +- fs/ext4/ext4.h | 15 +++ fs/ext4/ext4_jbd2.c | 3 + fs/ext4/ext4_jbd2.h | 25 +++++ fs/ext4/extents.c | 3 + fs/ext4/file.c | 1 + fs/ext4/ialloc.c | 1 + fs/ext4/inode.c | 3 + fs/ext4/ioctl.c | 3 + fs/ext4/mballoc.c | 5 + fs/ext4/namei.c | 1 + fs/ext4/resize.c | 1 + fs/ext4/snapshot.c | 18 ++++ fs/ext4/snapshot.h | 193 ++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_buffer.c | 238 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_ctl.c | 22 ++++ fs/ext4/snapshot_inode.c | 42 ++++++++ fs/ext4/super.c | 43 ++++++++ 20 files changed, 631 insertions(+), 1 deletions(-) create mode 100644 fs/ext4/snapshot.c create mode 100644 fs/ext4/snapshot.h create mode 100644 fs/ext4/snapshot_buffer.c create mode 100644 fs/ext4/snapshot_ctl.c create mode 100644 fs/ext4/snapshot_debug.c create mode 100644 fs/ext4/snapshot_debug.h create mode 100644 fs/ext4/snapshot_inode.c
fs/ext4/Kconfig +11 -0
@@ -83,3 +83,14 @@ config EXT4_DEBUG If you select Y here, then you will be able to turn on debugging with a command such as "echo 1 > /sys/kernel/debug/ext4/mballoc-debug" + +config EXT4_FS_SNAPSHOT + bool "EXT4 snapshots (Experimental)" + depends on EXT4_FS && EXPERIMENTAL + default n + help + Built-in snapshots support for ext4. + Requires that the filesystem has the has_snapshot and exclude_bitmap + features and that block size is equal to system page size. + Snapshots are not supported with 64bit and meta_bg features and the + filesystem must be mounted with ordered data mode.
fs/ext4/Makefile +2 -0
@@ -11,3 +11,5 @@ ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o page-io.o \ ext4-$(CONFIG_EXT4_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o +ext4-$(CONFIG_EXT4_FS_SNAPSHOT) += snapshot.o snapshot_ctl.o +ext4-$(CONFIG_EXT4_FS_SNAPSHOT) += snapshot_inode.o snapshot_buffer.o
fs/ext4/balloc.c +1 -1
@@ -20,6 +20,7 @@#include "ext4.h" #include "ext4_jbd2.h" #include "mballoc.h" +#include "snapshot.h" #include <trace/events/ext4.h>
@@ -156,7 +157,6 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, tmp =ext4_block_bitmap (sb, gdp);if (!flex_bg ||ext4_block_in_group (sb, tmp, block_group))ext4_set_bit (tmp - start, bh->b_data); - tmp =ext4_inode_bitmap (sb, gdp);if (!flex_bg ||ext4_block_in_group (sb, tmp, block_group))ext4_set_bit (tmp - start, bh->b_data);
fs/ext4/ext4.h +15 -0
@@ -873,6 +873,20 @@ struct ext4_inode_info {#define EXT2_FLAGS_SIGNED_HASH 0x0001/* Signed dirhash in use */ #define EXT2_FLAGS_UNSIGNED_HASH 0x0002/* Unsigned dirhash in use */ #define EXT2_FLAGS_TEST_FILESYS 0x0004/* to test development code */ +#define EXT4_FLAGS_IS_SNAPSHOT 0x0010/* Is a snapshot image */ +#define EXT4_FLAGS_FIX_SNAPSHOT 0x0020/* Corrupted snapshot */ +#define EXT4_FLAGS_FIX_EXCLUDE 0x0040/* Bad exclude bitmap */ + +#define EXT4_SET_FLAGS (sb, mask) \ + do { \ + EXT4_SB(sb)->s_es->s_flags |= cpu_to_le32(mask); \ + } while (0) +#define EXT4_CLEAR_FLAGS (sb, mask) \ + do { \ + EXT4_SB(sb)->s_es->s_flags &= ~cpu_to_le32(mask);\ + } while (0) +#define EXT4_TEST_FLAGS (sb, mask) \ + (EXT4_SB(sb)->s_es->s_flags & cpu_to_le32(mask))/* * Mount flags
@@ -1338,6 +1352,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 +#define EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT 0x0080/* Ext4 has snapshots */ #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
fs/ext4/ext4_jbd2.c +3 -0
@@ -1,8 +1,11 @@/* * Interface between ext4 and JBD +* +* Snapshot metadata COW hooks, Amir Goldstein <[email protected]>, 2011 */ #include "ext4_jbd2.h" +#include "snapshot.h" #include <trace/events/ext4.h>
fs/ext4/ext4_jbd2.h +25 -0
@@ -10,6 +10,8 @@* option, any later version, incorporated herein by reference. * * Ext4-specific journaling extensions. +* +* Snapshot extra COW credits, Amir Goldstein <[email protected]>, 2011 */ #ifndef _EXT4_JBD2_H
@@ -18,6 +20,7 @@#include <linux/fs.h> #include <linux/jbd2.h> #include "ext4.h" +#include "snapshot.h" #define EXT4_JOURNAL (inode) (EXT4_SB((inode)->i_sb)->s_journal)
@@ -272,6 +275,11 @@ static inline int ext4_should_journal_data(struct inode *inode)return 0 ;if (!S_ISREG (inode->i_mode))return 1 ; +#ifdef CONFIG_EXT4_FS_SNAPSHOT +if (EXT4_SNAPSHOTS (inode->i_sb)) +/* snapshots enforce ordered data */ +return 0 ; +#endif if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA )return 1 ;if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))
@@ -285,6 +293,11 @@ static inline int ext4_should_order_data(struct inode *inode)return 0 ;if (!S_ISREG (inode->i_mode))return 0 ; +#ifdef CONFIG_EXT4_FS_SNAPSHOT +if (EXT4_SNAPSHOTS (inode->i_sb)) +/* snapshots enforce ordered data */ +return 1 ; +#endif if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))return 0 ;if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_ORDERED_DATA )
@@ -298,6 +311,11 @@ static inline int ext4_should_writeback_data(struct inode *inode)return 0 ;if (EXT4_JOURNAL (inode) ==NULL )return 1 ; +#ifdef CONFIG_EXT4_FS_SNAPSHOT +if (EXT4_SNAPSHOTS (inode->i_sb)) +/* snapshots enforce ordered data */ +return 0 ; +#endif if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))return 0 ;if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_WRITEBACK_DATA )
@@ -320,6 +338,11 @@ static inline int ext4_should_dioread_nolock(struct inode *inode)return 0 ;if (!S_ISREG (inode->i_mode))return 0 ; +#ifdef CONFIG_EXT4_FS_SNAPSHOT +if (EXT4_SNAPSHOTS (inode->i_sb)) +/* XXX: should snapshots support dioread_nolock? */ +return 0 ; +#endif if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return 0 ;if (ext4_should_journal_data (inode))
@@ -327,4 +350,6 @@ static inline int ext4_should_dioread_nolock(struct inode *inode) return 1; } +#ifdef CONFIG_EXT4_FS_SNAPSHOT +#endif #endif /* _EXT4_JBD2_H */
fs/ext4/extents.c +3 -0
@@ -18,6 +18,8 @@* You should have received a copy of the GNU General Public Licens * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- +* +* Snapshot move-on-write (MOW), Yongqiang Yang <[email protected]>, 2011 */ /*
@@ -43,6 +45,7 @@#include <linux/fiemap.h> #include "ext4_jbd2.h" #include "ext4_extents.h" +#include "snapshot.h" #include <trace/events/ext4.h>
fs/ext4/file.c +1 -0
@@ -28,6 +28,7 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" +#include "snapshot.h" /* * Called when an inode is released. Note that this is different
fs/ext4/ialloc.c +1 -0
@@ -28,6 +28,7 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" +#include "snapshot.h" #include <trace/events/ext4.h>
fs/ext4/inode.c +3 -0
@@ -20,6 +20,8 @@* ([email protected]) * * Assorted race fixes, rewrite of ext4_get_block() by Al Viro, 2000 +* +* Snapshot inode extensions, Amir Goldstein <[email protected]>, 2011 */ #include <linux/module.h>
@@ -49,6 +51,7 @@#include "ext4_extents.h" #include <trace/events/ext4.h> +#include "snapshot.h" #define MPAGE_DA_EXTENT_TAIL 0x01
fs/ext4/ioctl.c +3 -0
@@ -5,6 +5,8 @@* Remy Card ([email protected]) * Laboratoire MASI - Institut Blaise Pascal * Universite Pierre et Marie Curie (Paris VI) +* +* Snapshot control API, Amir Goldstein <[email protected]>, 2011 */ #include <linux/fs.h>
@@ -17,6 +19,7 @@#include <asm/uaccess.h> #include "ext4_jbd2.h" #include "ext4.h" +#include "snapshot.h" long ext4_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {
fs/ext4/mballoc.c +5 -0
@@ -25,6 +25,7 @@#include <linux/debugfs.h> #include <linux/slab.h> #include <trace/events/ext4.h> +#include "snapshot.h" /* * MUSTDO:
@@ -2740,6 +2741,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, sbi =EXT4_SB (sb); err = -EIO ; + bitmap_bh =ext4_read_block_bitmap (sb, ac->ac_b_ex.fe_group);if (!bitmap_bh) goto out_err;
@@ -2791,6 +2793,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, }#endif mb_set_bits (bitmap_bh->b_data, ac->ac_b_ex.fe_start,ac->ac_b_ex.fe_len); +if (gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { gdp->bg_flags &=cpu_to_le16 (~EXT4_BG_BLOCK_UNINIT ); ext4_free_blks_set(sb, gdp,
@@ -2820,6 +2823,8 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, err =ext4_handle_dirty_metadata (handle,NULL , bitmap_bh);if (err) goto out_err; + + err =ext4_handle_dirty_metadata (handle,NULL , gdp_bh); out_err:
fs/ext4/namei.c +1 -0
@@ -39,6 +39,7 @@#include "xattr.h" #include "acl.h" +#include "snapshot.h" #include <trace/events/ext4.h> /*
fs/ext4/resize.c +1 -0
@@ -15,6 +15,7 @@#include <linux/slab.h> #include "ext4_jbd2.h" +#include "snapshot.h" #define outside (b, first, last) ((b) < (first) || (b) >= (last))#define inside (b, first, last) ((b) >= (first) && (b) < (last))
fs/ext4/snapshot.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* linux/fs/ext4/snapshot.c +* +* Written by Amir Goldstein <[email protected]>, 2008 +* +* Copyright (C) 2008-2011 CTERA Networks +* +* This file is part of the Linux kernel and is made available under +* the terms of the GNU General Public License, version 2, or at your +* option, any later version, incorporated herein by reference. +* +* Ext4 snapshots core functions. +*/ + +#include <linux/quotaops.h> +#include "snapshot.h" +#include "ext4.h" +#include "mballoc.h"
fs/ext4/snapshot.h new file +193 -0
193 lines not on this page · raw message
fs/ext4/snapshot_buffer.c new file +238 -0
238 lines not on this page · raw message
fs/ext4/snapshot_ctl.c new file +22 -0
@@ -0,0 +1,22 @@ +/* +* linux/fs/ext4/snapshot_ctl.c +* +* Written by Amir Goldstein <[email protected]>, 2008 +* +* Copyright (C) 2008-2011 CTERA Networks +* +* This file is part of the Linux kernel and is made available under +* the terms of the GNU General Public License, version 2, or at your +* option, any later version, incorporated herein by reference. +* +* Ext4 snapshots control functions. +*/ + +#include <linux/statfs.h> +#include "ext4_jbd2.h" +#include "snapshot.h" +#define ext4_snapshot_reset_bitmap_cache (sb, init) 0 + +/* +* Snapshot constructor/destructor +*/
fs/ext4/snapshot_debug.c new file +0 -0
fs/ext4/snapshot_debug.h new file +0 -0
fs/ext4/snapshot_inode.c new file +42 -0
42 lines not on this page · raw message
fs/ext4/super.c +43 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/36 ext4: snapshot debugging support
In reply to [email protected]From: Amir Goldstein <[email protected]>
Control snapshot debug level via debugfs entry /ext4/snapshot-debug and induce delay tests via debugfs entries /ext4/test-XXX-delay-msec.
--- fs/ext4/Makefile | 1 + fs/ext4/mballoc.c | 3 + fs/ext4/snapshot.h | 9 ++++ fs/ext4/snapshot_debug.c | 100 +++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_debug.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 0 deletions(-)
fs/ext4/Makefile +1 -0
@@ -13,3 +13,4 @@ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o ext4-$(CONFIG_EXT4_FS_SNAPSHOT) += snapshot.o snapshot_ctl.o ext4-$(CONFIG_EXT4_FS_SNAPSHOT) += snapshot_inode.o snapshot_buffer.o +ext4-$(CONFIG_EXT4_FS_SNAPSHOT) += snapshot_debug.o
fs/ext4/mballoc.c +3 -0
@@ -2658,10 +2658,13 @@ static void __init ext4_create_debugfs_entry(void)S_IRUGO |S_IWUSR , debugfs_dir, &mb_enable_debug); +if (debugfs_dir) +ext4_snapshot_create_debugfs_entry (debugfs_dir); }static void ext4_remove_debugfs_entry (void ) { +ext4_snapshot_remove_debugfs_entry ();debugfs_remove (debugfs_debug);debugfs_remove (debugfs_dir); }
fs/ext4/snapshot.h +9 -0
@@ -18,6 +18,7 @@#include <linux/version.h> #include <linux/delay.h> #include "ext4.h" +#include "snapshot_debug.h" /*
@@ -109,6 +110,14 @@static inline void snapshot_size_extend (struct inode *inode,ext4_fsblk_t blocks) { +#ifdef CONFIG_EXT4_DEBUG +ext4_fsblk_t old_blocks =SNAPSHOT_PROGRESS (inode); +ext4_fsblk_t max_blocks =SNAPSHOT_BLOCKS (inode); + +/* sleep total of tunable delay unit over 100% progress */ +snapshot_test_delay_progress (SNAPTEST_DELETE , + old_blocks, blocks, max_blocks); +#endif i_size_write ((inode), (loff_t)(blocks) <<SNAPSHOT_BLOCK_SIZE_BITS ); }
fs/ext4/snapshot_debug.c +100 -0
100 lines not on this page · raw message
fs/ext4/snapshot_debug.h +105 -0
105 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 3/36 ext4: snapshot hooks - inside JBD hooks
In reply to [email protected]From: Amir Goldstein <[email protected]>
Before every metadata buffer write, the journal API is called, namely, one of the ext4_journal_get_XXX_access() functions. We use these journal hooks to call the snapshot API, namely ext4_snapshot_get_XXX_access(), to COW the metadata buffer before it is modified for the first time.
--- fs/ext4/ext4_jbd2.c | 9 ++++++- fs/ext4/ext4_jbd2.h | 15 ++++++++++--- fs/ext4/extents.c | 3 +- fs/ext4/inode.c | 22 ++++++++++++++------ fs/ext4/move_extent.c | 3 +- fs/ext4/snapshot.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 15 deletions(-)
fs/ext4/ext4_jbd2.c +7 -2
@@ -23,13 +23,16 @@ int __ext4_journal_get_undo_access(const char *where, unsigned int line,return err; } -int __ext4_journal_get_write_access (const char *where,unsigned int line, -handle_t *handle,struct buffer_head *bh) +int __ext4_journal_get_write_access_inode (const char *where,unsigned int line, +handle_t *handle,struct inode *inode, +struct buffer_head *bh,int exclude) {int err =0 ;if (ext4_handle_valid (handle)) { err =jbd2_journal_get_write_access (handle, bh); +if (!err && !exclude) + err =ext4_snapshot_get_write_access (handle, inode, bh);if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err);
@@ -111,6 +114,8 @@ int __ext4_journal_get_create_access(const char *where, unsigned int line,if (ext4_handle_valid (handle)) { err =jbd2_journal_get_create_access (handle, bh); +if (!err) + err =ext4_snapshot_get_create_access (handle, bh);if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err);
fs/ext4/ext4_jbd2.h +11 -4
@@ -132,9 +132,9 @@ void ext4_journal_abort_handle(const char *caller, unsigned int line,int __ext4_journal_get_undo_access (const char *where,unsigned int line,handle_t *handle,struct buffer_head *bh); -int __ext4_journal_get_write_access (const char *where,unsigned int line, -handle_t *handle,struct buffer_head *bh); - +int __ext4_journal_get_write_access_inode (const char *where,unsigned int line, +handle_t *handle,struct inode *inode, +struct buffer_head *bh,int exclude);int __ext4_forget (const char *where,unsigned int line,handle_t *handle,int is_metadata,struct inode *inode,struct buffer_head *bh,ext4_fsblk_t blocknr);
@@ -151,8 +151,15 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,#define ext4_journal_get_undo_access (handle, bh) \ __ext4_journal_get_undo_access(__func__, __LINE__, (handle), (bh)) +#define ext4_journal_get_write_access_exclude (handle, bh) \ + __ext4_journal_get_write_access_inode(__func__, __LINE__, \ + (handle), NULL, (bh), 1)#define ext4_journal_get_write_access (handle, bh) \ - __ext4_journal_get_write_access(__func__, __LINE__, (handle), (bh)) + __ext4_journal_get_write_access_inode(__func__, __LINE__, \ + (handle), NULL, (bh), 0) +#define ext4_journal_get_write_access_inode (handle, inode, bh) \ + __ext4_journal_get_write_access_inode(__func__, __LINE__, \ + (handle), (inode), (bh), 0)#define ext4_forget (handle, is_metadata, inode, bh, block_nr) \ __ext4_forget(__func__, __LINE__, (handle), (is_metadata), (inode), \ (bh), (block_nr))
fs/ext4/extents.c +2 -1
@@ -79,7 +79,8 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode, {if (path->p_bh) {/* path points to block */ -return ext4_journal_get_write_access (handle, path->p_bh); +return ext4_journal_get_write_access_inode (handle, + inode, path->p_bh); }/* path points to leaf/index in inode body */ /* we use in-core data, no need to protect them */
fs/ext4/inode.c +15 -7
@@ -874,7 +874,8 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,*/ if (where->bh) {BUFFER_TRACE (where->bh,"get_write_access" ); - err =ext4_journal_get_write_access (handle, where->bh); + err =ext4_journal_get_write_access_inode (handle, inode, + where->bh);if (err) goto err_out; }
@@ -4149,7 +4150,8 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode, goto out_err;if (bh) {BUFFER_TRACE (bh,"retaking write access" ); - err =ext4_journal_get_write_access (handle, bh); + err =ext4_journal_get_write_access_inode (handle, + inode, bh);if (unlikely (err)) goto out_err; }
@@ -4200,7 +4202,8 @@ static void ext4_free_data(handle_t *handle, struct inode *inode,if (this_bh) {/* For indirect block */ BUFFER_TRACE (this_bh,"get_write_access" ); - err =ext4_journal_get_write_access (handle, this_bh); + err =ext4_journal_get_write_access_inode (handle, inode, + this_bh);/* Important: if we can't update the indirect pointers * to the blocks, we can't free them. */ if (err)
@@ -4363,8 +4366,8 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,* pointed to by an indirect block: journal it */ BUFFER_TRACE (parent_bh,"get_write_access" ); -if (!ext4_journal_get_write_access (handle, - parent_bh)){ +if (!ext4_journal_get_write_access_inode ( + handle, inode, parent_bh)){ *p =0 ;BUFFER_TRACE (parent_bh,"call ext4_handle_dirty_metadata" );
@@ -4741,9 +4744,14 @@ has_buffer:int ext4_get_inode_loc (struct inode *inode,struct ext4_iloc *iloc) { -/* We have all inode data except xattrs in memory here. */ -return __ext4_get_inode_loc (inode, iloc, +int in_mem = (!EXT4_SNAPSHOTS (inode->i_sb) && !ext4_test_inode_state (inode,EXT4_STATE_XATTR )); + +/* +* We have all inode's data except xattrs in memory here, +* but we must always read-in the entire inode block for COW. +*/ +return __ext4_get_inode_loc (inode, iloc, in_mem); }void ext4_set_inode_flags (struct inode *inode)
fs/ext4/move_extent.c +2 -1
@@ -421,7 +421,8 @@ mext_insert_extents(handle_t *handle, struct inode *orig_inode,if (depth) {/* Register to journal */ - ret =ext4_journal_get_write_access (handle, orig_path->p_bh); + ret =ext4_journal_get_write_access_inode (handle, + orig_inode, orig_path->p_bh);if (ret)return ret; }
fs/ext4/snapshot.h +51 -0
57 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 4/36 ext4: snapshot hooks - block bitmap access
In reply to [email protected]From: Amir Goldstein <[email protected]>
The API ext4_handle_get_bitmap_access() is used instead of ext4_journal_get_write_access(), before modifying a block bitmap while allocating or deleting blocks. The bitmap access API is used to initialize the COW bitmap for that group.
The old ext4_journal_get_undo_access() API was removed because it is not being used in the code.
--- fs/ext4/ext4_jbd2.c | 10 +++++++--- fs/ext4/ext4_jbd2.h | 10 ++++++---- fs/ext4/mballoc.c | 7 ++++--- fs/ext4/snapshot.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 10 deletions(-)
fs/ext4/ext4_jbd2.c +7 -3
@@ -9,13 +9,17 @@#include <trace/events/ext4.h> -int __ext4_journal_get_undo_access (const char *where,unsigned int line, -handle_t *handle,struct buffer_head *bh) +int __ext4_handle_get_bitmap_access (const char *where,unsigned int line, +handle_t *handle,struct super_block *sb, +ext4_group_t group,struct buffer_head *bh) {int err =0 ;if (ext4_handle_valid (handle)) { - err =jbd2_journal_get_undo_access (handle, bh); + err =jbd2_journal_get_write_access (handle, bh); +if (!err) + err =ext4_snapshot_get_bitmap_access (handle, sb, + group, bh);if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err);
fs/ext4/ext4_jbd2.h +6 -4
@@ -129,8 +129,9 @@ void ext4_journal_abort_handle(const char *caller, unsigned int line,const char *err_fn, struct buffer_head *bh, handle_t *handle, int err); -int __ext4_journal_get_undo_access (const char *where,unsigned int line, -handle_t *handle,struct buffer_head *bh); +int __ext4_handle_get_bitmap_access (const char *where,unsigned int line, +handle_t *handle,struct super_block *sb, +ext4_group_t group,struct buffer_head *bh); int __ext4_journal_get_write_access_inode(const char *where, unsigned int line, handle_t *handle, struct inode *inode,
@@ -149,8 +150,9 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,int __ext4_handle_dirty_super (const char *where,unsigned int line,handle_t *handle,struct super_block *sb); -#define ext4_journal_get_undo_access (handle, bh) \ - __ext4_journal_get_undo_access(__func__, __LINE__, (handle), (bh)) +#define ext4_handle_get_bitmap_access (handle, sb, group, bh) \ + __ext4_handle_get_bitmap_access(__func__, __LINE__, \ + (handle), (sb), (group), (bh))#define ext4_journal_get_write_access_exclude (handle, bh) \ __ext4_journal_get_write_access_inode(__func__, __LINE__, \ (handle), NULL, (bh), 1)
fs/ext4/mballoc.c +4 -3
@@ -2749,7 +2749,8 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,if (!bitmap_bh) goto out_err; - err =ext4_journal_get_write_access (handle, bitmap_bh); + err =ext4_handle_get_bitmap_access (handle, sb, ac->ac_b_ex.fe_group, + bitmap_bh);if (err) goto out_err;
@@ -4549,7 +4550,7 @@ do_more: }BUFFER_TRACE (bitmap_bh,"getting write access" ); - err =ext4_journal_get_write_access (handle, bitmap_bh); + err =ext4_handle_get_bitmap_access (handle, sb, block_group, bitmap_bh);if (err) goto error_return;
@@ -4698,7 +4699,7 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, }BUFFER_TRACE (bitmap_bh,"getting write access" ); - err =ext4_journal_get_write_access (handle, bitmap_bh); + err =ext4_handle_get_bitmap_access (handle, sb, block_group, bitmap_bh);if (err) goto error_return;
fs/ext4/snapshot.h +31 -0
@@ -196,6 +196,37 @@ static inline int ext4_snapshot_get_create_access(handle_t *handle,return err; } +/* +* get_bitmap_access() is called before modifying a block bitmap. +* this call initializes the COW bitmap for @group. +* +* Return values: +* = 0 - COW bitmap is initialized +* < 0 - error +*/ +static inline int ext4_snapshot_get_bitmap_access (handle_t *handle, +struct super_block *sb,ext4_group_t group, +struct buffer_head *bh) +{ +if (!EXT4_SNAPSHOTS (sb)) +return 0 ; +/* +* With flex_bg, block bitmap may reside in a different group than +* the group it describes, so we need to init both COW bitmaps: +* 1. init the COW bitmap for @group by testing +* if the first block in the group should be COWed +*/ +if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) { +int err =ext4_snapshot_cow (handle,NULL , +ext4_group_first_block_no (sb, group), +NULL ,0 ); +if (err <0 ) +return err; + } +/* 2. COW the block bitmap itself, which may be in another group */ +return ext4_snapshot_cow (handle,NULL , bh->b_blocknr, bh,1 ); +} +/* snapshot_ctl.c */
Signature · 1 line
1.7.4.1
PATCH 5/36 ext4: snapshot hooks - delete blocks
In reply to [email protected]From: Amir Goldstein <[email protected]>
Before deleting file blocks in ext4_free_blocks(), we call the snapshot API ext4_snapshot_get_delete_access(), to optionally move the block to the snapshot file instead of freeing them.
--- fs/ext4/ext4.h | 10 +++++++--- fs/ext4/mballoc.c | 30 +++++++++++++++++++++++++++--- fs/ext4/snapshot.h | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-)
fs/ext4/ext4.h +7 -3
@@ -1731,9 +1731,13 @@ extern int ext4_mb_reserve_blocks(struct super_block *, int);extern void ext4_discard_preallocations (struct inode *);extern int __init ext4_init_mballoc (void );extern void ext4_exit_mballoc (void ); -extern void ext4_free_blocks (handle_t *handle,struct inode *inode, -struct buffer_head *bh,ext4_fsblk_t block, -unsigned long count,int flags); +extern void __ext4_free_blocks (const char *where,unsigned int line, +handle_t *handle,struct inode *inode, +struct buffer_head *bh,ext4_fsblk_t block, +unsigned long count,int flags); +#define ext4_free_blocks (handle, inode, bh, block, count, flags) \ + __ext4_free_blocks(__func__, __LINE__ , (handle), (inode), (bh), \ + (block), (count), (flags))extern int ext4_mb_add_groupinfo (struct super_block *sb,ext4_group_t i,struct ext4_group_desc *desc);extern int ext4_trim_fs (struct super_block *,struct fstrim_range *);
fs/ext4/mballoc.c +27 -3
@@ -4451,9 +4451,9 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,* @count: number of blocks to count * @metadata: Are these metadata blocks */ -void ext4_free_blocks (handle_t *handle,struct inode *inode, -struct buffer_head *bh,ext4_fsblk_t block, -unsigned long count,int flags) +void __ext4_free_blocks (const char *where,unsigned int line,handle_t *handle, +struct inode *inode,struct buffer_head *bh, +ext4_fsblk_t block,unsigned long count,int flags) {struct buffer_head *bitmap_bh =NULL ;struct super_block *sb = inode->i_sb;
@@ -4467,6 +4467,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,struct ext4_buddy e4b;int err =0 ;int ret; +int maxblocks;if (bh) {if (block)
@@ -4549,6 +4550,29 @@ do_more: goto error_return; } + maxblocks = count; + ret =ext4_snapshot_get_delete_access (handle, inode, + block, &maxblocks); +if (ret <0 ) { +ext4_journal_abort_handle (where, line, __func__, +NULL , handle, ret); + err = ret; + goto error_return; + } +if (ret >0 ) { +/* 'ret' blocks were moved to snapshot - skip them */ + block += maxblocks; + count -= maxblocks; + count += overflow; +cond_resched (); +if (count >0 ) + goto do_more; +/* no more blocks to free/move to snapshot */ +ext4_mark_super_dirty (sb); + goto error_return; + } + overflow += count - maxblocks; + count = maxblocks;BUFFER_TRACE (bitmap_bh,"getting write access" ); err =ext4_handle_get_bitmap_access (handle, sb, block_group, bitmap_bh);if (err)
fs/ext4/snapshot.h +26 -0
@@ -227,6 +227,32 @@ static inline int ext4_snapshot_get_bitmap_access(handle_t *handle,return ext4_snapshot_cow (handle,NULL , bh->b_blocknr, bh,1 ); } +/* +* get_delete_access() - move blocks to snapshot or approve to free them +* @handle: JBD handle +* @inode: owner of blocks if known (or NULL otherwise) +* @block: address of start @block +* @pcount: pointer to no. of blocks about to move or approve +* +* Called from ext4_free_blocks() before deleting blocks with +* i_data_sem held +* +* Return values: +* > 0 - blocks were moved to snapshot and may not be freed +* = 0 - blocks may be freed +* < 0 - error +*/ +static inline int ext4_snapshot_get_delete_access (handle_t *handle, +struct inode *inode,ext4_fsblk_t block,int *pcount) +{ +struct super_block *sb; + + sb = handle->h_transaction->t_journal->j_private; +if (!EXT4_SNAPSHOTS (sb)) +return 0 ; + +return ext4_snapshot_move (handle, inode, block, pcount,1 ); +}/* snapshot_ctl.c */
Signature · 1 line
1.7.4.1
PATCH 6/36 ext4: snapshot hooks - move data blocks
In reply to [email protected]From: Amir Goldstein <[email protected]>
Before every regular file data buffer write, the function ext4_get_block() is called to map the buffer to disk. We add a new function ext4_get_block_mow() which is called when we want to snapshot the blocks. We use this hook to call the snapshot API snapshot_get_move_access(), to optionally move the block to the snapshot file.
--- fs/ext4/ext4.h | 15 +++- fs/ext4/ext4_jbd2.h | 17 ++++ fs/ext4/inode.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++---- fs/ext4/mballoc.c | 23 +++++ fs/ext4/snapshot.h | 31 +++++++ 5 files changed, 311 insertions(+), 17 deletions(-)
fs/ext4/ext4.h +14 -1
@@ -143,9 +143,10 @@ struct ext4_allocation_request {#define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)#define EXT4_MAP_BOUNDARY (1 << BH_Boundary)#define EXT4_MAP_UNINIT (1 << BH_Uninit) +#define EXT4_MAP_REMAP (1 << BH_Remap)#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\ - EXT4_MAP_UNINIT) + EXT4_MAP_UNINIT | EXT4_MAP_REMAP)struct ext4_map_blocks {ext4_fsblk_t m_pblk;
@@ -512,6 +513,12 @@ struct ext4_new_group_data {/* Convert extent to initialized after IO complete */ #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\ EXT4_GET_BLOCKS_CREATE_UNINIT_EXT) +/* Look up if mapped block is used by snapshot, +* if so and EXT4_GET_BLOCKS_CREATE is set, move it to snapshot +* and allocate a new block for new data. +* if EXT4_GET_BLOCKS_CREATE is not set, return REMAP flags. +*/ +#define EXT4_GET_BLOCKS_MOVE_ON_WRITE 0x0100/* * Flags used by ext4_free_blocks
@@ -2130,10 +2137,16 @@ extern int ext4_bio_write_page(struct ext4_io_submit *io,enum ext4_state_bits { BH_Uninit/* blocks are allocated but uninitialized on disk */ = BH_JBDPrivateStart, + BH_Remap,/* Data block need to be remapped, +* now used by snapshot to do mow +*/ + BH_Partial_Write,/* Buffer should be uptodate before write */ }; BUFFER_FNS(Uninit, uninit) TAS_BUFFER_FNS(Uninit, uninit) +BUFFER_FNS(Remap, remap) +BUFFER_FNS (Partial_Write, partial_write)/* * Add new method to test wether block and inode bitmaps are properly
fs/ext4/ext4_jbd2.h +17 -0
@@ -360,5 +360,22 @@ static inline int ext4_should_dioread_nolock(struct inode *inode) }#ifdef CONFIG_EXT4_FS_SNAPSHOT +/* +* check if @inode data blocks should be moved-on-write +*/ +static inline int ext4_snapshot_should_move_data (struct inode *inode) +{ +if (!EXT4_SNAPSHOTS (inode->i_sb)) +return 0 ; +if (EXT4_JOURNAL (inode) ==NULL ) +return 0 ; +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) +return 0 ; +/* when a data block is journaled, it is already COWed as metadata */ +if (ext4_should_journal_data (inode)) +return 0 ; +return 1 ; +} +#endif #endif /* _EXT4_JBD2_H */
fs/ext4/inode.c +226 -16
417 lines not on this page · raw message
fs/ext4/mballoc.c +23 -0
@@ -3179,6 +3179,29 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)struct ext4_prealloc_space *pa, *cpa =NULL ;ext4_fsblk_t goal_block; +/* +* All inode preallocations allocated before the time when the +* active snapshot is taken need to be discarded, otherwise blocks +* maybe used by both a regular file and the snapshot file that we +* are taking in the below case. +* +* Case: An user take a snapshot when an inode has a preallocation +* 12/512, of which 12/64 has been used by the inode. Here 12 is the +* logical block number. After the snapshot is taken, an user issues +* a write request on the 12th block, then an allocation on 12 is +* needed and allocator will use blocks from the preallocations.As +* a result, the event above happens. +* +* +* For now, all preallocations are discarded. +* +* Please refer to code and comments about preallocation in +* mballoc.c for more information. +*/ +if (ext4_snapshot_active (EXT4_SB (ac->ac_inode->i_sb)) && + !ext4_snapshot_mow_in_tid (ac->ac_inode)) { +ext4_discard_preallocations (ac->ac_inode); + }/* only data can be preallocated */ if (!(ac->ac_flags &EXT4_MB_HINT_DATA ))return 0 ;
fs/ext4/snapshot.h +31 -0
@@ -228,6 +228,37 @@ static inline int ext4_snapshot_get_bitmap_access(handle_t *handle, }/* +* get_move_access() - move block to snapshot +* @handle: JBD handle +* @inode: owner of @block +* @block: address of @block +* @pcount pointer to no. of blocks about to move or approve +* @move: if false, only test if blocks need to be moved +* +* Called from ext4_ind_map_blocks() before overwriting a data block, when the +* buffer_move_on_write() flag is set. Specifically, only data blocks of +* regular files are moved. Directory blocks are COWed on get_write_access(). +* Snapshots and excluded files blocks are never moved-on-write. +* If @move is true, then down_write(&i_data_sem) is held. +* +* Return values: +* > 0 - @blocks a) were moved for @move = 1; +* b) need to be moved for @move = 0. +* = 0 - blocks don't need to be moved. +* < 0 - error +*/ +static inline int ext4_snapshot_get_move_access (handle_t *handle, +struct inode *inode, +ext4_fsblk_t block, +int *pcount,int move) +{ +if (!EXT4_SNAPSHOTS (inode->i_sb)) +return 0 ; + +return ext4_snapshot_move (handle, inode, block, pcount, move); +} + +/* * get_delete_access() - move blocks to snapshot or approve to free them * @handle: JBD handle * @inode: owner of blocks if known (or NULL otherwise)
Signature · 1 line
1.7.4.1
PATCH 7/36 ext4: snapshot hooks - direct I/O
In reply to [email protected]From: Amir Goldstein <[email protected]>
With indirect mapped files, direct I/O write is not allowed to initialize holes, so stale data won't be exposed.
With snapshots, direct I/O write is not allowed to do move-on-write, for the exact same reason.
--- fs/ext4/inode.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 48 insertions(+), 2 deletions(-)
fs/ext4/inode.c +48 -2
@@ -1373,6 +1373,16 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,return ret; } +if (retval >0 && (map->m_flags &EXT4_MAP_REMAP ) && + (flags &EXT4_GET_BLOCKS_PRE_IO )) { +/* +* If mow is needed on the requested block and +* request comes from async-direct-io-write path, +* we return an unmapped buffer to fall back to buffered I/O. +*/ + map->m_flags &= ~EXT4_MAP_MAPPED ; +return 0 ; + }/* If it is only a block(s) look up */ if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 )return retval;
@@ -3654,6 +3664,29 @@ static int ext4_releasepage(struct page *page, gfp_t wait) }/* +* ext4_get_block_dio used when preparing for a DIO write +* to indirect mapped files with snapshots. +*/ +int ext4_get_block_dio_write (struct inode *inode,sector_t iblock, +struct buffer_head *bh,int create) +{ +int flags =EXT4_GET_BLOCKS_CREATE ; + +/* +* DIO_SKIP_HOLES may ask to map direct I/O write with create=0, +* but we know this is a write, so we need to check if block +* needs to be moved to snapshot and fall back to buffered I/O. +* ext4_map_blocks() will return an unmapped buffer if block +* is not allocated or if it needs to be moved to snapshot. +*/ +if (ext4_snapshot_should_move_data (inode)) + flags |=EXT4_GET_BLOCKS_MOVE_ON_WRITE | +EXT4_GET_BLOCKS_PRE_IO ; + +return _ext4_get_block (inode, iblock, bh, flags); +} + +/* * O_DIRECT for ext3 (or indirect map) based files * * If the O_DIRECT write will extend the file then add this inode to the
@@ -3708,6 +3741,16 @@ retry: ret =blockdev_direct_IO (rw, iocb, inode, inode->i_sb->s_bdev, iov, offset, nr_segs, +/* +* snapshots code gets here for DIO write +* to ind mapped files or outside i_size +* of extent mapped files and for DIO read +* to all files. +* XXX: isn't it possible to expose stale data +* on DIO read to newly allocated ind map +* blocks or newly MOWed blocks? +*/ + (rw ==WRITE ) ? ext4_get_block_dio_write : ext4_get_block,NULL );if (unlikely ((rw &WRITE ) && ret <0 )) {
@@ -3769,10 +3812,13 @@ out:static int ext4_get_block_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) { +int flags =EXT4_GET_BLOCKS_IO_CREATE_EXT ; +ext4_debug ("ext4_get_block_write: inode %lu, create flag %d\n" , inode->i_ino, create); -return _ext4_get_block (inode, iblock, bh_result, -EXT4_GET_BLOCKS_IO_CREATE_EXT ); +if (ext4_snapshot_should_move_data (inode)) + flags |=EXT4_GET_BLOCKS_MOVE_ON_WRITE ; +return _ext4_get_block (inode, iblock, bh_result, flags); } static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
Signature · 1 line
1.7.4.1
PATCH 8/36 ext4: snapshot hooks - move extent file data blocks
In reply to [email protected]From: Amir Goldstein <[email protected]>
Extent mapped file data is moved into snapshot in ext4_ext_map_blocks(). If a part of a extent is to be moved, the extent is splitted. Fragmentation is light because of delayed-move-on-write.
--- fs/ext4/ext4_jbd2.h | 2 - fs/ext4/extents.c | 151 +++++++++++++++++++++++++++++++++++++++++++++------ fs/ext4/inode.c | 3 +- 3 files changed, 136 insertions(+), 20 deletions(-)
fs/ext4/ext4_jbd2.h +0 -2
@@ -369,8 +369,6 @@ static inline int ext4_snapshot_should_move_data(struct inode *inode)return 0 ;if (EXT4_JOURNAL (inode) ==NULL )return 0 ; -if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) -return 0 ;/* when a data block is journaled, it is already COWed as metadata */ if (ext4_should_journal_data (inode))return 0 ;
fs/ext4/extents.c +134 -17
217 lines not on this page · raw message
fs/ext4/inode.c +2 -1
@@ -1360,7 +1360,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,*/ down_read ((&EXT4_I (inode)->i_data_sem));if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) { - retval =ext4_ext_map_blocks (handle, inode, map,0 ); + retval =ext4_ext_map_blocks (handle, inode, map, + flags &EXT4_GET_BLOCKS_MOVE_ON_WRITE ); }else { retval =ext4_ind_map_blocks (handle, inode, map, flags &EXT4_GET_BLOCKS_MOVE_ON_WRITE );
Signature · 1 line
1.7.4.1
PATCH 9/36 ext4: snapshot file
In reply to [email protected]From: Amir Goldstein <[email protected]>
Ext4 snapshot implementation as a file inside the file system. Snapshot files are marked with the snapfile flag and have special read-only address space ops.
--- fs/ext4/ext4.h | 70 ++++++++++++++- fs/ext4/ext4_jbd2.h | 2 + fs/ext4/ialloc.c | 8 ++- fs/ext4/inode.c | 29 ++++++ fs/ext4/snapshot.h | 106 ++++++++++++++++++++++ fs/ext4/snapshot_ctl.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/super.c | 9 ++ 7 files changed, 446 insertions(+), 5 deletions(-)
fs/ext4/ext4.h +67 -3
@@ -348,17 +348,23 @@ struct flex_groups {#define EXT4_EXTENTS_FL 0x00080000/* Inode uses extents */ #define EXT4_EA_INODE_FL 0x00200000/* Inode used for large EA */ #define EXT4_EOFBLOCKS_FL 0x00400000/* Blocks allocated beyond EOF */ +/* snapshot persistent flags */ +#define EXT4_SNAPFILE_FL 0x01000000/* snapshot file */ +#define EXT4_SNAPFILE_DELETED_FL 0x04000000/* snapshot is deleted */ +#define EXT4_SNAPFILE_SHRUNK_FL 0x08000000/* snapshot was shrunk */ +/* end of snapshot flags */ #define EXT4_RESERVED_FL 0x80000000/* reserved for ext4 lib */ -#define EXT4_FL_USER_VISIBLE 0x004BDFFF/* User visible flags */ -#define EXT4_FL_USER_MODIFIABLE 0x004B80FF/* User modifiable flags */ + +#define EXT4_FL_USER_VISIBLE 0x014BDFFF/* User visible flags */ +#define EXT4_FL_USER_MODIFIABLE 0x014B80FF/* User modifiable flags */ /* Flags that should be inherited by new inodes from their parent. */ #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ EXT4_SYNC_FL | EXT4_IMMUTABLE_FL | EXT4_APPEND_FL |\ EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ - EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL) + EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL | EXT4_SNAPFILE_FL)/* Flags that are appropriate for regular files (all but dir-specific ones). */ #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
@@ -405,6 +411,9 @@ enum {EXT4_INODE_EXTENTS =19 ,/* Inode uses extents */ EXT4_INODE_EA_INODE =21 ,/* Inode used for large EA */ EXT4_INODE_EOFBLOCKS =22 ,/* Blocks allocated beyond EOF */ +EXT4_INODE_SNAPFILE =24 ,/* Snapshot file/dir */ +EXT4_INODE_SNAPFILE_DELETED =26 ,/* Snapshot is deleted */ +EXT4_INODE_SNAPFILE_SHRUNK =27 ,/* Snapshot was shrunk */ EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ };
@@ -451,6 +460,9 @@ static inline void ext4_check_flag_values(void)CHECK_FLAG_VALUE (EXTENTS );CHECK_FLAG_VALUE (EA_INODE );CHECK_FLAG_VALUE (EOFBLOCKS ); +CHECK_FLAG_VALUE (SNAPFILE ); +CHECK_FLAG_VALUE (SNAPFILE_DELETED ); +CHECK_FLAG_VALUE (SNAPFILE_SHRUNK );CHECK_FLAG_VALUE (RESERVED ); }
@@ -790,6 +802,14 @@ struct ext4_inode_info {struct list_head i_orphan;/* unlinked but open inodes */ /* +* In-memory snapshot list overrides i_orphan to link snapshot inodes, +* but unlike the real orphan list, the next snapshot inode number +* is stored in i_next_snapshot_ino and not in i_dtime +*/ +#define i_snaplist i_orphan +__u32 i_next_snapshot_ino; + +/* * i_disksize keeps track of what the inode size is ON DISK, not * in memory. During truncate, i_size is set to the new size by * the VFS prior to calling ext4_truncate(), but the filesystem won't
@@ -1145,6 +1165,8 @@ struct ext4_sb_info {u32 s_max_batch_time;u32 s_min_batch_time;struct block_device *journal_bdev; +struct mutex s_snapshot_mutex;/* protects 2 fields below: */ +struct inode *s_active_snapshot;/* [ s_snapshot_mutex ] */ #ifdef CONFIG_JBD2_DEBUG struct timer_list turn_ro_timer;/* For turning read-only (crash simulation) */ wait_queue_head_t ro_wait_queue;/* For people waiting for the fs to go read-only */
@@ -1261,6 +1283,24 @@ enum {EXT4_STATE_DIO_UNWRITTEN ,/* need convert on dio done*/ EXT4_STATE_NEWENTRY ,/* File just added to dir */ EXT4_STATE_DELALLOC_RESERVED ,/* blks already reserved for delalloc */ + EXT4_STATE_LAST +}; + +/* +* Snapshot dynamic state flags (starting at offset EXT4_STATE_LAST) +* These flags are read by GETSNAPFLAGS ioctl and interpreted by the lssnap +* utility. Do not change these values. +*/ +enum { +EXT4_SNAPSTATE_LIST =0 ,/* snapshot is on list (S) */ +EXT4_SNAPSTATE_ENABLED =1 ,/* snapshot is enabled (n) */ +EXT4_SNAPSTATE_ACTIVE =2 ,/* snapshot is active (a) */ +EXT4_SNAPSTATE_INUSE =3 ,/* snapshot is in-use (p) */ +EXT4_SNAPSTATE_DELETED =4 ,/* snapshot is deleted (s) */ +EXT4_SNAPSTATE_SHRUNK =5 ,/* snapshot was shrunk (h) */ +EXT4_SNAPSTATE_OPEN =6 ,/* snapshot is mounted (o) */ +EXT4_SNAPSTATE_TAGGED =7 ,/* snapshot is tagged (t) */ +EXT4_SNAPSTATE_LAST };#define EXT4_INODE_BIT_FNS (name, field, offset) \
@@ -1277,9 +1317,19 @@ static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ } +#define EXT4_INODE_FLAGS_FNS (name, field, offset, count) \ +static inline int ext4_get_##name##_flags(struct inode *inode) \ +{ \ + return (EXT4_I(inode)->i_##field >> (offset)) & \ + ((1UL << (count)) - 1); \ +} \ + EXT4_INODE_BIT_FNS(flag, flags, 0)#if (BITS_PER_LONG <64 ) EXT4_INODE_BIT_FNS(state, state_flags, 0) +EXT4_INODE_BIT_FNS(snapstate, state_flags, EXT4_STATE_LAST) +EXT4_INODE_FLAGS_FNS (snapstate, state_flags,EXT4_STATE_LAST , \ + EXT4_SNAPSTATE_LAST)static inline void ext4_clear_state_flags (struct ext4_inode_info *ei) {
@@ -1287,6 +1337,9 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) }#else EXT4_INODE_BIT_FNS(state, flags, 32) +EXT4_INODE_BIT_FNS(snapstate, flags, 32 + EXT4_STATE_LAST) +EXT4_INODE_FLAGS_FNS (snapstate, flags,32 +EXT4_STATE_LAST , \ + EXT4_SNAPSTATE_LAST)static inline void ext4_clear_state_flags (struct ext4_inode_info *ei) {
@@ -1301,6 +1354,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)#endif #define NEXT_ORPHAN (inode) EXT4_I(inode)->i_dtime +#define NEXT_SNAPSHOT (inode) (EXT4_I(inode)->i_next_snapshot_ino)/* * Codes for operating systems
@@ -1783,6 +1837,10 @@ extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);extern qsize_t *ext4_get_reserved_space (struct inode *inode);extern void ext4_da_update_reserve_space (struct inode *inode,int used,int quota_claim); + +/* snapshot_inode.c */ +extern int ext4_snapshot_readpage (struct file *file,struct page *page); +/* ioctl.c */ extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long );
@@ -2006,6 +2064,12 @@ struct ext4_group_info {void *bb_bitmap;#endif struct rw_semaphore alloc_sem; +/* +* bg_cow_bitmap is reset to zero on mount time and on every snapshot +* take and initialized lazily on first block group write access. +* bg_cow_bitmap is protected by sb_bgl_lock(). +*/ +unsigned long bg_cow_bitmap;/* COW bitmap cache */ ext4_grpblk_t bb_counters[];/* Nr of free power-of-two-block * regions, index is order. * bb_counters[3] = 5 means
fs/ext4/ext4_jbd2.h +2 -0
@@ -369,6 +369,8 @@ static inline int ext4_snapshot_should_move_data(struct inode *inode)return 0 ;if (EXT4_JOURNAL (inode) ==NULL )return 0 ; +if (ext4_snapshot_excluded (inode)) +return 0 ;/* when a data block is journaled, it is already COWed as metadata */ if (ext4_should_journal_data (inode))return 0 ;
fs/ext4/ialloc.c +6 -2
@@ -1049,8 +1049,12 @@ got: goto fail_free_drop;if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_EXTENTS )) { -/* set extent flag only for directory, file and normal symlink*/ -if (S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode)) { +/* +* Set extent flag only for non-snapshot file, directory +* and normal symlink +*/ +if ((S_ISREG (mode) && !ext4_snapshot_file (inode)) || +S_ISDIR (mode) ||S_ISLNK (mode)) {ext4_set_inode_flag (inode,EXT4_INODE_EXTENTS );ext4_ext_tree_init (handle, inode); }
fs/ext4/inode.c +29 -0
@@ -4139,9 +4139,38 @@ static const struct address_space_operations ext4_da_aops = { .is_partially_uptodate = block_is_partially_uptodate, .error_remove_page = generic_error_remove_page, }; +static int ext4_no_writepage (struct page *page, +struct writeback_control *wbc) +{ +unlock_page (page); +return -EIO ; +} + +/* +* Snapshot file page operations: +* always readpage (by page) with buffer tracked read. +* user cannot writepage or direct_IO to a snapshot file. +* +* snapshot file pages are written to disk after a COW operation in "ordered" +* mode and are never changed after that again, so there is no data corruption +* risk when using "ordered" mode on snapshot files. +* some snapshot data pages are written to disk by sync_dirty_buffer(), namely +* the snapshot COW bitmaps and a few initial blocks copied on snapshot_take(). +*/ +static const struct address_space_operations ext4_snapfile_aops = { + .readpage = ext4_readpage, + .readpages = ext4_readpages, + .writepage = ext4_no_writepage, + .bmap = ext4_bmap, + .invalidatepage = ext4_invalidatepage, + .releasepage = ext4_releasepage, +};void ext4_set_aops (struct inode *inode) { +if (ext4_snapshot_file (inode)) + inode->i_mapping->a_ops = &ext4_snapfile_aops; +else if (ext4_should_order_data (inode) &&test_opt (inode->i_sb,DELALLOC )) inode->i_mapping->a_ops = &ext4_da_aops;
fs/ext4/snapshot.h +106 -0
119 lines not on this page · raw message
fs/ext4/snapshot_ctl.c +227 -0
235 lines not on this page · raw message
fs/ext4/super.c +9 -0
@@ -761,6 +761,8 @@ static void ext4_put_super(struct super_block *sb)destroy_workqueue (sbi->dio_unwritten_wq);lock_super (sb); +if (EXT4_SNAPSHOTS (sb)) +ext4_snapshot_destroy (sb);if (sb->s_dirt)ext4_commit_super (sb,1 );
@@ -3521,6 +3523,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sb->s_root =NULL ; +mutex_init (&sbi->s_snapshot_mutex); + sbi->s_active_snapshot =NULL ; + needs_recovery = (es->s_last_orphan !=0 ||EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ));
@@ -3727,6 +3732,10 @@ no_journal: goto failed_mount4; }; +if (EXT4_SNAPSHOTS (sb) && +ext4_snapshot_load (sb, es, sb->s_flags &MS_RDONLY )) +/* XXX: how can we fail and force read-only at this point? */ +ext4_error (sb,"load snapshot failed\n" );EXT4_SB (sb)->s_mount_state |=EXT4_ORPHAN_FS ;ext4_orphan_cleanup (sb, es);EXT4_SB (sb)->s_mount_state &= ~EXT4_ORPHAN_FS ;
Signature · 1 line
1.7.4.1
PATCH 10/36 ext4: snapshot file - read through to block device
In reply to [email protected]From: Amir Goldstein <[email protected]>
On active snapshot page read, the function ext4_snapshot_get_block() is called to map the page to a disk block. If the page is not mapped in the snapshot file a direct mapping to the block device is returned.
--- fs/ext4/inode.c | 3 +- fs/ext4/snapshot_inode.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 2 deletions(-)
fs/ext4/inode.c +1 -2
@@ -4158,8 +4158,7 @@ static int ext4_no_writepage(struct page *page,* the snapshot COW bitmaps and a few initial blocks copied on snapshot_take(). */ static const struct address_space_operations ext4_snapfile_aops = { - .readpage = ext4_readpage, - .readpages = ext4_readpages, + .readpage = ext4_snapshot_readpage, .writepage = ext4_no_writepage, .bmap = ext4_bmap, .invalidatepage = ext4_invalidatepage,
fs/ext4/snapshot_inode.c +244 -0
249 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 11/36 ext4: snapshot file - permissions
In reply to [email protected]From: Amir Goldstein <[email protected]>
Enforce snapshot file permissions.
Write, truncate and unlink of snapshot inodes is not allowed.
--- fs/ext4/file.c | 7 +++++++ fs/ext4/inode.c | 7 +++++++ fs/ext4/namei.c | 8 ++++++++ 3 files changed, 22 insertions(+), 0 deletions(-)
fs/ext4/file.c +7 -0
@@ -168,6 +168,13 @@ static int ext4_file_open(struct inode * inode, struct file * filp)struct path path;char buf[64 ], *cp; +if (ext4_snapshot_file (inode) && + (filp->f_flags &O_ACCMODE ) !=O_RDONLY ) +/* +* allow only read-only access to snapshot files +*/ +return -EPERM ; +if (unlikely (!(sbi->s_mount_flags &EXT4_MF_MNTDIR_SAMPLED ) && !(sb->s_flags &MS_RDONLY ))) { sbi->s_mount_flags |=EXT4_MF_MNTDIR_SAMPLED ;
fs/ext4/inode.c +7 -0
@@ -4727,6 +4727,13 @@ void ext4_truncate(struct inode *inode)trace_ext4_truncate_enter (inode); +/* prevent truncate of files on snapshot list */ +if (ext4_snapshot_list (inode)) { +snapshot_debug (1 ,"snapshot (%u) cannot be truncated!\n" , + inode->i_generation); +return ; + } +if (!ext4_can_truncate (inode))return ;
fs/ext4/namei.c +8 -0
@@ -2225,6 +2225,14 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) inode->i_ino, inode->i_nlink); inode->i_nlink =1 ; } +/* prevent unlink of files on snapshot list */ +if (inode->i_nlink ==1 && +ext4_snapshot_list (inode)) { +snapshot_debug (1 ,"snapshot (%u) cannot be unlinked!\n" , + inode->i_generation); + retval = -EPERM ; + goto end_unlink; + } retval =ext4_delete_entry (handle, dir, de, bh);if (retval) goto end_unlink;
Signature · 1 line
1.7.4.1
PATCH 12/36 ext4: snapshot file - store on disk
In reply to [email protected]From: Amir Goldstein <[email protected]>
Snapshot inode is stored differently in memory and on disk. During store and load of snapshot inode, some of the inode flags and fields are converted.
--- fs/ext4/inode.c | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-)
fs/ext4/inode.c +27 -6
@@ -5183,6 +5183,17 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)*/ for (block =0 ; block <EXT4_N_BLOCKS ; block++) ei->i_data[block] = raw_inode->i_block[block]; +/* snapshot on-disk list is stored in snapshot inode on-disk version */ +if (ext4_snapshot_file (inode)) { + ei->i_next_snapshot_ino = +le32_to_cpu (raw_inode->i_disk_version); +/* +* snapshot volume size is stored in i_disksize. +* in-memory i_size of snapshot files is set to 0 (disabled). +* enabling a snapshot is setting i_size to i_disksize. +*/ + inode->i_size =0 ; + }INIT_LIST_HEAD (&ei->i_orphan);/*
@@ -5447,12 +5458,22 @@ static int ext4_do_update_inode(handle_t *handle,for (block =0 ; block <EXT4_N_BLOCKS ; block++) raw_inode->i_block[block] = ei->i_data[block]; - raw_inode->i_disk_version =cpu_to_le32 (inode->i_version); -if (ei->i_extra_isize) { -if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) - raw_inode->i_version_hi = -cpu_to_le32 (inode->i_version >>32 ); - raw_inode->i_extra_isize =cpu_to_le16 (ei->i_extra_isize); +if (ext4_snapshot_file (inode)) { +/* +* Snapshot on-disk list overrides snapshot on-disk version. +* Snapshot files are not writable and have a fixed version. +*/ + raw_inode->i_disk_version = +cpu_to_le32 (ei->i_next_snapshot_ino); + }else { + raw_inode->i_disk_version =cpu_to_le32 (inode->i_version); +if (ei->i_extra_isize) { +if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) + raw_inode->i_version_hi = +cpu_to_le32 (inode->i_version >>32 ); + raw_inode->i_extra_isize = +cpu_to_le16 (ei->i_extra_isize); + } }BUFFER_TRACE (bh,"call ext4_handle_dirty_metadata" );
Signature · 1 line
1.7.4.1
PATCH 13/36 ext4: snapshot file - increase maximum file size limit to 16TB
In reply to [email protected]From: Amir Goldstein <[email protected]>
Files larger than 2TB use Ext4 huge_file flag to store i_blocks in file system blocks units, so the upper limit on snapshot actual size is increased from 512*2^32 = 2TB to 4K*2^32 = 16TB, which is also the upper limit on file system size.
To map 2^32 logical blocks, 4 triple indirect blocks are used instead of just one. The extra 3 triple indirect blocks are stored in-place of direct blocks, which are not in use by snapshot files.
--- fs/ext4/ext4.h | 13 +++++++++++++ fs/ext4/file.c | 3 ++- fs/ext4/inode.c | 43 +++++++++++++++++++++++++++++++++++++++++-- fs/ext4/super.c | 3 +++ 4 files changed, 59 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +13 -0
@@ -320,6 +320,19 @@ struct flex_groups {#define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)#define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)#define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) +/* +* Snapshot files have different indirection mapping that can map up to 2^32 +* logical blocks, so they can cover the mapped filesystem block address space. +* Ext4 must use either 4K or 8K blocks (depending on PAGE_SIZE). +* With 8K blocks, 1 triple indirect block maps 2^33 logical blocks. +* With 4K blocks (the system default), each triple indirect block maps 2^30 +* logical blocks, so 4 triple indirect blocks map 2^32 logical blocks. +* Snapshot files in small filesystems (<= 4G), use only 1 double indirect +* block to map the entire filesystem. +*/ +#define EXT4_SNAPSHOT_EXTRA_TIND_BLOCKS 3 +#define EXT4_SNAPSHOT_N_BLOCKS (EXT4_TIND_BLOCK + 1 + \ + EXT4_SNAPSHOT_EXTRA_TIND_BLOCKS)/* * Inode flags
fs/ext4/file.c +2 -1
@@ -228,7 +228,8 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int origin)struct inode *inode = file->f_mapping->host;loff_t maxbytes; -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) +if (!ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ) && + !ext4_snapshot_file (inode)) maxbytes =EXT4_SB (inode->i_sb)->s_bitmap_maxbytes;else maxbytes = inode->i_sb->s_maxbytes;
fs/ext4/inode.c +41 -2
85 lines not on this page · raw message
fs/ext4/super.c +3 -0
@@ -3302,6 +3302,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) EXT4_FEATURE_RO_COMPAT_HUGE_FILE); sbi->s_bitmap_maxbytes =ext4_max_bitmap_size (sb->s_blocksize_bits, has_huge_files); +if (EXT4_SNAPSHOTS (sb)) +/* Snapshot files are huge files */ + has_huge_files =1 ; sb->s_maxbytes =ext4_max_size (sb->s_blocksize_bits, has_huge_files);if (le32_to_cpu (es->s_rev_level) ==EXT4_GOOD_OLD_REV ) {
Signature · 1 line
1.7.4.1
PATCH 14/36 ext4: snapshot block operations
In reply to [email protected]From: Amir Goldstein <[email protected]>
Core API of special snapshot file block operations. The argument @create to the function ext4_getblk()
is re-interpreted as a snapshot block command argument. The old argument values 0(=read) and 1(=create) preserve the original behavior of the function. The bit field h_cowing in the current transaction handle is used to prevent COW recursions.
--- fs/ext4/ext4.h | 10 ++++++++++ fs/ext4/ext4_jbd2.h | 3 +++ fs/ext4/inode.c | 4 ++-- fs/ext4/snapshot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +10 -0
@@ -544,6 +544,16 @@ struct ext4_new_group_data {* if EXT4_GET_BLOCKS_CREATE is not set, return REMAP flags. */ #define EXT4_GET_BLOCKS_MOVE_ON_WRITE 0x0100 +/* +* snapshot_map_blocks() flags passed to ext4_map_blocks() for mapping +* blocks to snapshot. +*/ +/* handle COW race conditions */ +#define EXT4_GET_BLOCKS_COW 0x200 +/* allocate only indirect blocks */ +#define EXT4_GET_BLOCKS_MOVE 0x400 +/* bypass journal and sync allocated indirect blocks directly to disk */ +#define EXT4_GET_BLOCKS_SYNC 0x800/* * Flags used by ext4_free_blocks
fs/ext4/ext4_jbd2.h +3 -0
@@ -173,6 +173,9 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,#define ext4_handle_dirty_super (handle, sb) \ __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb)) +#define trace_cow_add (handle, name, num) +#define trace_cow_inc (handle, name) +handle_t *ext4_journal_start_sb (struct super_block *sb,int nblocks);int __ext4_journal_stop (const char *where,unsigned int line,handle_t *handle);
fs/ext4/inode.c +2 -2
@@ -1603,8 +1603,8 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, map.m_lblk = block; map.m_len =1 ; - err =ext4_map_blocks (handle, inode, &map, - create ?EXT4_GET_BLOCKS_CREATE :0 ); +/* passing SNAPMAP flags on create argument */ + err =ext4_map_blocks (handle, inode, &map, create);if (err <0 ) *errp = err;
fs/ext4/snapshot.c +43 -0
46 lines not on this page · raw message
fs/ext4/snapshot.h +37 -0
@@ -137,6 +137,43 @@ static inline int EXT4_SNAPSHOTS(struct super_block *sb) EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT); } +/* +* snapshot_map_blocks() command flags passed to ext4_map_blocks() on its +* @flags argument. The higher bits are used for mapping snapshot blocks. +*/ +/* original meaning - only check if blocks are mapped */ +#define SNAPMAP_READ 0 +/* original meaning - allocate missing blocks and indirect blocks */ +#define SNAPMAP_WRITE EXT4_GET_BLOCKS_CREATE +/* creating COWed block */ +#define SNAPMAP_COW (SNAPMAP_WRITE|EXT4_GET_BLOCKS_COW) +/* moving blocks to snapshot */ +#define SNAPMAP_MOVE (SNAPMAP_WRITE|EXT4_GET_BLOCKS_MOVE) +/* creating COW bitmap - handle COW races and bypass journal */ +#define SNAPMAP_BITMAP (SNAPMAP_COW|EXT4_GET_BLOCKS_SYNC) + +/* test special cases when mapping snapshot blocks */ +#define SNAPMAP_ISCOW (cmd) (unlikely((cmd) & EXT4_GET_BLOCKS_COW)) +#define SNAPMAP_ISMOVE (cmd) (unlikely((cmd) & EXT4_GET_BLOCKS_MOVE)) +#define SNAPMAP_ISSYNC (cmd) (unlikely((cmd) & EXT4_GET_BLOCKS_SYNC)) + +#define IS_COWING (handle) (unlikely((handle)->h_cowing)) + +/* snapshot.c */ + +/* helper functions for ext4_snapshot_create() */ +extern int ext4_snapshot_map_blocks (handle_t *handle,struct inode *inode, +ext4_snapblk_t block, +unsigned long maxblocks, +ext4_fsblk_t *mapped,int cmd); +/* helper function for ext4_snapshot_take() */ +extern void ext4_snapshot_copy_buffer (struct buffer_head *sbh, +struct buffer_head *bh, +const char *mask); +/* helper function for ext4_snapshot_get_block() */ +extern int ext4_snapshot_read_block_bitmap (struct super_block *sb, +unsigned int block_group,struct buffer_head *bitmap_bh); +#define ext4_snapshot_cow (handle, inode, block, bh, cow) 0#define ext4_snapshot_move (handle, inode, block, pcount, move) (0)
Signature · 1 line
1.7.4.1
PATCH 15/36 ext4: snapshot block operation - copy blocks to snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
Implementation of copying blocks into a snapshot file. This mechanism is used to copy-on-write metadata blocks to snapshot.
--- fs/ext4/ext4.h | 3 + fs/ext4/inode.c | 40 +++++++- fs/ext4/mballoc.c | 18 ++++ fs/ext4/resize.c | 10 ++- fs/ext4/snapshot.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot.h | 12 ++- 6 files changed, 346 insertions(+), 6 deletions(-)
fs/ext4/ext4.h +3 -0
@@ -109,6 +109,8 @@ typedef unsigned int ext4_group_t;/* We are doing stream allocation */ #define EXT4_MB_STREAM_ALLOC 0x0800 +/* allocate blocks for active snapshot */ +#define EXT4_MB_HINT_COWING 0x02000struct ext4_allocation_request {/* target inode for block we're allocating */
@@ -1825,6 +1827,7 @@ extern void __ext4_free_blocks(const char *where, unsigned int line,extern int ext4_mb_add_groupinfo (struct super_block *sb,ext4_group_t i,struct ext4_group_desc *desc);extern int ext4_trim_fs (struct super_block *,struct fstrim_range *); +extern int ext4_mb_test_bit_range (int bit,void *addr,int *pcount);/* inode.c */ struct buffer_head *ext4_getblk(handle_t *, struct inode *,
fs/ext4/inode.c +36 -4
@@ -699,8 +699,17 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, ar.goal = goal; ar.len = target; ar.logical = iblock; -if (S_ISREG (inode->i_mode)) -/* enable in-core preallocation only for regular files */ +if (IS_COWING (handle)) { +/* +* This hint is used to tell the allocator not to fail +* on quota limits and allow allocation from blocks which +* are reserved for snapshots. +* Failing allocation during COW operations would result +* in I/O error, which is not desirable. +*/ + ar.flags =EXT4_MB_HINT_COWING ; + }else if (S_ISREG (inode->i_mode) && !ext4_snapshot_file (inode)) +/* Enable preallocation only for non-snapshot regular files */ ar.flags =EXT4_MB_HINT_DATA ; current_block =ext4_mb_new_blocks (handle, &ar, err);
@@ -1362,6 +1371,21 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, int flags) { int retval; +int cowing =0 ; + +if (handle &&IS_COWING (handle)) { +/* +* locking order for locks validator: +* inode (VFS operation) -> active snapshot (COW operation) +* +* The i_data_sem lock is nested during COW operation, but +* the active snapshot i_data_sem write lock is not taken +* otherwise, because snapshot file has read-only aops and +* because truncate/unlink of active snapshot is not permitted. +*/ +BUG_ON (!ext4_snapshot_is_active (inode)); + cowing =1 ; + } map->m_flags =0 ; ext_debug("ext4_map_blocks(): inode %lu, flag %d, max_blocks %u,"
@@ -1371,7 +1395,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,* Try to see if we can get the block without requesting a new * file system block. */ -down_read ((&EXT4_I (inode)->i_data_sem)); +down_read_nested ((&EXT4_I (inode)->i_data_sem), cowing);if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) { retval =ext4_ext_map_blocks (handle, inode, map, flags &EXT4_GET_BLOCKS_MOVE_ON_WRITE );
@@ -1430,7 +1454,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,* the write lock of i_data_sem, and call get_blocks() * with create == 1 flag. */ -down_write ((&EXT4_I (inode)->i_data_sem)); +down_write_nested ((&EXT4_I (inode)->i_data_sem), cowing);/* * if the caller is from delayed allocation writeout path
@@ -1621,6 +1645,14 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,J_ASSERT (create !=0 );J_ASSERT (handle !=NULL ); +if (SNAPMAP_ISCOW (create)) { +/* COWing block or creating COW bitmap */ +lock_buffer (bh); +clear_buffer_uptodate (bh); +/* flag locked buffer and return */ + *errp =1 ; +return bh; + }/* * Now that we do not always journal data, we should * keep in mind whether this should always journal the
fs/ext4/mballoc.c +18 -0
@@ -420,6 +420,24 @@ static inline int mb_find_next_bit(void *addr, int max, int start)return ret; } +/* +* Find the largest range of set or clear bits. +* Return 1 for set bits and 0 for clear bits. +* Set *pcount to number of bits in range. +*/ +int ext4_mb_test_bit_range (int bit,void *addr,int *pcount) +{ +int i, ret; + + ret =mb_test_bit (bit, addr); +if (ret) + i =mb_find_next_zero_bit (addr, bit + *pcount, bit); +else + i =mb_find_next_bit (addr, bit + *pcount, bit); + *pcount = i - bit; +return ret ?1 :0 ; +} +static void *mb_find_buddy (struct ext4_buddy *e4b,int order,int *max) {char *bb;
fs/ext4/resize.c +9 -1
@@ -673,7 +673,15 @@ static void update_backups(struct super_block *sb, (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA))) break; - bh =sb_getblk (sb, group * bpg + blk_off); +if (ext4_snapshot_has_active (sb)) +/* +* test_and_cow() expects an uptodate buffer. +* Read the buffer here to suppress the +* "non uptodate buffer" warning. +*/ + bh =sb_bread (sb, group * bpg + blk_off); +else + bh =sb_getblk (sb, group * bpg + blk_off);if (!bh) { err = -EIO ;break ;
fs/ext4/snapshot.c +269 -0
272 lines not on this page · raw message
fs/ext4/snapshot.h +11 -1
@@ -174,7 +174,17 @@ extern void ext4_snapshot_copy_buffer(struct buffer_head *sbh,extern int ext4_snapshot_read_block_bitmap (struct super_block *sb,unsigned int block_group,struct buffer_head *bitmap_bh); -#define ext4_snapshot_cow (handle, inode, block, bh, cow) 0 +extern int ext4_snapshot_test_and_cow (const char *where, +handle_t *handle,struct inode *inode, +ext4_fsblk_t block,struct buffer_head *bh,int cow); + +/* +* test if a metadata block should be COWed +* and if it should, copy the block to the active snapshot +*/ +#define ext4_snapshot_cow (handle, inode, block, bh, cow) \ + ext4_snapshot_test_and_cow(__func__, handle, inode, \ + block, bh, cow)#define ext4_snapshot_move (handle, inode, block, pcount, move) (0)
Signature · 1 line
1.7.4.1
PATCH 16/36 ext4: snapshot block operation - move blocks to snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
Implementation of moving blocks into a snapshot file.
The move block command maps an allocated blocks to the snapshot file, allocating only the indirect blocks when needed.
This mechanism is used to move-on-write data blocks to snapshot.
--- fs/ext4/inode.c | 62 +++++++++++++++++++------- fs/ext4/snapshot.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot.h | 12 +++++- 3 files changed, 176 insertions(+), 18 deletions(-)
fs/ext4/inode.c +45 -17
@@ -676,6 +676,11 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, new_blocks[index++] = current_block++; count--; } +if (blks ==0 && target ==0 ) { +/* mapping data blocks */ + *err =0 ; +return 0 ; + }if (count >0 ) {/* * save the new block number
@@ -777,10 +782,10 @@ failed_out:* ext4_alloc_block() (normally -ENOSPC). Otherwise we set the chain * as described above and return 0. */ -static int ext4_alloc_branch (handle_t *handle,struct inode *inode, -ext4_lblk_t iblock,int indirect_blks, -int *blks,ext4_fsblk_t goal, -ext4_lblk_t *offsets,Indirect *branch) +static int ext4_alloc_branch_cow (handle_t *handle,struct inode *inode, +ext4_fsblk_t iblock,int indirect_blks, +int *blks,ext4_fsblk_t goal, +int *offsets,Indirect *branch,int flags) {int blocksize = inode->i_sb->s_blocksize;int i, n =0 ;
@@ -790,6 +795,22 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,ext4_fsblk_t new_blocks[4 ];ext4_fsblk_t current_block; +if (SNAPMAP_ISMOVE (flags)) { +/* mapping snapshot block to block device block */ + current_block =SNAPSHOT_BLOCK (iblock); + num =0 ; +if (indirect_blks >0 ) { +/* allocating only indirect blocks */ +ext4_alloc_blocks (handle, inode, iblock, goal, + indirect_blks,0 , new_blocks, &err); +if (err) +return err; + } +/* charge snapshot file owner for moved blocks */ +dquot_alloc_block_nofail (inode, *blks); + num = *blks; + new_blocks[indirect_blks] = current_block; + }else num =ext4_alloc_blocks (handle, inode, iblock, goal, indirect_blks, *blks, new_blocks, &err);if (err)
@@ -861,8 +882,11 @@ failed: }for (i = n+1 ; i < indirect_blks; i++)ext4_free_blocks (handle, inode,NULL , new_blocks[i],1 ,0 ); - -ext4_free_blocks (handle, inode,NULL , new_blocks[i], num,0 ); +if (SNAPMAP_ISMOVE (flags) && num >0 ) +/* don't charge snapshot file owner if move failed */ +dquot_free_block (inode, num); +else if (num >0 ) +ext4_free_blocks (handle, inode,NULL , new_blocks[i], num,0 );return err; }
@@ -882,9 +906,8 @@ failed:* inode (->i_blocks, etc.). In case of success we end up with the full * chain to new block and return 0. */ -static int ext4_splice_branch (handle_t *handle,struct inode *inode, -ext4_lblk_t block,Indirect *where,int num, -int blks) +static int ext4_splice_branch_cow (handle_t *handle,struct inode *inode, +long block,Indirect *where,int num,int blks,int flags) {int i;int err =0 ;
@@ -951,8 +974,12 @@ err_out:ext4_free_blocks (handle, inode, where[i].bh,0 ,1 ,EXT4_FREE_BLOCKS_FORGET ); } -ext4_free_blocks (handle, inode,NULL ,le32_to_cpu (where[num].key), - blks,0 ); +if (SNAPMAP_ISMOVE (flags)) +/* don't charge snapshot file owner if move failed */ +dquot_free_block (inode, blks); +else +ext4_free_blocks (handle, inode,NULL , +le32_to_cpu (where[num].key), blks,0 );return err; }
@@ -1099,9 +1126,11 @@ static int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,/* * Block out ext4_truncate while we alter the tree */ - err =ext4_alloc_branch (handle, inode, map->m_lblk, indirect_blks, - &count, goal, - offsets + (partial - chain), partial); + err =ext4_alloc_branch_cow (handle, inode, map->m_lblk, indirect_blks, + &count, goal, offsets + (partial - chain), + partial, flags); +if (err) + goto cleanup;if (map->m_flags &EXT4_MAP_REMAP ) { map->m_len = count;
@@ -1127,9 +1156,8 @@ static int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,* credits cannot be returned. Can we handle this somehow? We * may need to return -EAGAIN upwards in the worst case. --sct */ -if (!err) - err =ext4_splice_branch (handle, inode, map->m_lblk, - partial, indirect_blks, count); + err =ext4_splice_branch_cow (handle, inode, map->m_lblk, partial, + indirect_blks, count, flags);if (err) goto cleanup;
fs/ext4/snapshot.c +120 -0
123 lines not on this page · raw message
fs/ext4/snapshot.h +11 -1
@@ -186,7 +186,17 @@ extern int ext4_snapshot_test_and_cow(const char *where,ext4_snapshot_test_and_cow (__func__, handle, inode, \ block, bh, cow) -#define ext4_snapshot_move (handle, inode, block, pcount, move) (0) +extern int ext4_snapshot_test_and_move (const char *where, +handle_t *handle,struct inode *inode, +ext4_fsblk_t block,int *pcount,int move); + +/* +* test if blocks should be moved to snapshot +* and if they should, try to move them to the active snapshot +*/ +#define ext4_snapshot_move (handle, inode, block, pcount, move) \ + ext4_snapshot_test_and_move(__func__, handle, inode, \ + block, pcount, move)/* * Block access functions
Signature · 1 line
1.7.4.1
PATCH 17/36 ext4: snapshot block operation - copy block bitmap to snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
The snapshot copy of the file system block bitmap is called the COW bitmap and it is used to check if a block was allocated at the time that the snapshot was taken.
--- fs/ext4/snapshot.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/snapshot_ctl.c | 19 ++++- 2 files changed, 264 insertions(+), 5 deletions(-)
fs/ext4/snapshot.c +246 -4
@@ -75,6 +75,27 @@ __ext4_snapshot_copy_buffer(struct buffer_head *sbh, }/* +* use @mask to clear exclude bitmap bits from block bitmap +* when creating COW bitmap and mark snapshot buffer @sbh uptodate +*/ +static inline void +__ext4_snapshot_copy_bitmap (struct buffer_head *sbh, +char *dst,const char *src,const char *mask) +{ +const u32 *ps = (const u32 *)src, *pm = (const u32 *)mask; +u32 *pd = (u32 *)dst; +int i; + +if (mask) { +for (i =0 ; i <SNAPSHOT_ADDR_PER_BLOCK ; i++) + *pd++ = *ps++ & ~*pm++; + }else +memcpy (dst, src,SNAPSHOT_BLOCK_SIZE ); + +set_buffer_uptodate (sbh); +} + +/* * ext4_snapshot_complete_cow() * Unlock a newly COWed snapshot buffer and complete the COW operation. * Optionally, sync the buffer to disk or add it to the current transaction
@@ -123,13 +144,228 @@ void ext4_snapshot_copy_buffer(struct buffer_head *sbh, struct buffer_head *bh, const char *mask) {lock_buffer (sbh ); -__ext4_snapshot_copy_buffer (sbh, bh); +if (mask) +__ext4_snapshot_copy_bitmap (sbh, + sbh->b_data, bh->b_data, mask); +else +__ext4_snapshot_copy_buffer (sbh, bh);unlock_buffer (sbh);mark_buffer_dirty (sbh);sync_dirty_buffer (sbh); }/* +* COW bitmap functions +*/ + +/* +* ext4_snapshot_init_cow_bitmap() init a new allocated (locked) COW bitmap +* buffer on first time block group access after snapshot take. +* COW bitmap is created by masking the block bitmap with exclude bitmap. +*/ +static int +ext4_snapshot_init_cow_bitmap (struct super_block *sb, +unsigned int block_group,struct buffer_head *cow_bh) +{ +struct buffer_head *bitmap_bh; +char *dst, *src, *mask =NULL ; + + bitmap_bh =ext4_read_block_bitmap (sb, block_group); +if (!bitmap_bh) +return -EIO ; + + src = bitmap_bh->b_data; +/* +* Another COWing task may be changing this block bitmap +* (allocating active snapshot blocks) while we are trying +* to copy it. At this point we are guaranteed that the only +* changes to block bitmap are the new active snapshot blocks, +* because before allocating/freeing any other blocks a task +* must first get_write_access() on the bitmap and get here. +*/ +ext4_lock_group (sb, block_group); + +/* +* in the path coming from ext4_snapshot_read_block_bitmap(), +* cow_bh is a user page buffer so it has to be kmapped. +*/ + dst =kmap_atomic (cow_bh->b_page,KM_USER0 ); +__ext4_snapshot_copy_bitmap (cow_bh, dst, src, mask); +kunmap_atomic (dst,KM_USER0 ); + +ext4_unlock_group (sb, block_group); + +brelse (bitmap_bh); +return 0 ; +} + +/* +* ext4_snapshot_read_block_bitmap() +* helper function for ext4_snapshot_get_block() +* used for fixing the block bitmap user page buffer when +* reading through to block device. +*/ +int ext4_snapshot_read_block_bitmap (struct super_block *sb, +unsigned int block_group,struct buffer_head *bitmap_bh) +{ +int err; + +lock_buffer (bitmap_bh); + err =ext4_snapshot_init_cow_bitmap (sb, block_group, bitmap_bh); +unlock_buffer (bitmap_bh); +return err; +} + +/* +* ext4_snapshot_read_cow_bitmap - read COW bitmap from active snapshot +* @handle: JBD handle +* @snapshot: active snapshot +* @block_group: block group +* +* Reads the COW bitmap block (i.e., the active snapshot copy of block bitmap). +* Creates the COW bitmap on first access to @block_group after snapshot take. +* COW bitmap cache is non-persistent, so no need to mark the group descriptor +* block dirty. COW bitmap races are handled internally, so no locks are +* required when calling this function, only a valid @handle. +* +* Return COW bitmap buffer on success or NULL in case of failure. +*/ +static struct buffer_head * +ext4_snapshot_read_cow_bitmap (handle_t *handle,struct inode *snapshot, +unsigned int block_group) +{ +struct super_block *sb = snapshot->i_sb; +struct ext4_group_info *grp =ext4_get_group_info (sb, block_group); +struct ext4_group_desc *desc; +struct buffer_head *cow_bh; +ext4_fsblk_t bitmap_blk; +ext4_fsblk_t cow_bitmap_blk; +int err =0 ; + + desc =ext4_get_group_desc (sb, block_group,NULL ); +if (!desc) +return NULL ; + + bitmap_blk =ext4_block_bitmap (sb, desc); + +ext4_lock_group (sb, block_group); + cow_bitmap_blk = grp->bg_cow_bitmap; +ext4_unlock_group (sb, block_group); +if (cow_bitmap_blk) +return sb_bread (sb, cow_bitmap_blk); + +/* +* Try to read cow bitmap block from snapshot file. If COW bitmap +* is not yet allocated, create the new COW bitmap block. +*/ + cow_bh =ext4_bread (handle, snapshot,SNAPSHOT_IBLOCK (bitmap_blk), +SNAPMAP_READ , &err); +if (cow_bh) + goto out; + +/* allocate snapshot block for COW bitmap */ + cow_bh =ext4_getblk (handle, snapshot,SNAPSHOT_IBLOCK (bitmap_blk), +SNAPMAP_BITMAP , &err); +if (!cow_bh) + goto out; +if (!err) { +/* +* err should be 1 to indicate new allocated (locked) buffer. +* if err is 0, it means that someone mapped this block +* before us, while we are updating the COW bitmap cache. +* the pending COW bitmap code should prevent that. +*/ +WARN_ON (1 ); + err = -EIO ; + goto out; + } + + err =ext4_snapshot_init_cow_bitmap (sb, block_group, cow_bh); +if (err) + goto out; +/* +* complete pending COW operation. no need to wait for tracked reads +* of block bitmap, because it is copied directly to page buffer by +* ext4_snapshot_read_block_bitmap() +*/ + err =ext4_snapshot_complete_cow (handle, snapshot, cow_bh,NULL ,1 ); +if (err) + goto out; + +trace_cow_inc (handle, bitmaps); +out: +if (!err && cow_bh) { +/* initialized COW bitmap block */ + cow_bitmap_blk = cow_bh->b_blocknr; +snapshot_debug (3 ,"COW bitmap #%u of snapshot (%u) " +"mapped to block [%lld/%lld]\n" , + block_group, snapshot->i_generation, +SNAPSHOT_BLOCK_TUPLE (cow_bitmap_blk)); + }else { +/* uninitialized COW bitmap block */ + cow_bitmap_blk =0 ; +snapshot_debug (1 ,"failed to read COW bitmap #%u of snapshot " +"(%u)\n" , block_group, snapshot->i_generation); +brelse (cow_bh); + cow_bh =NULL ; + } + +/* update or reset COW bitmap cache */ +ext4_lock_group (sb, block_group); + grp->bg_cow_bitmap = cow_bitmap_blk; +ext4_unlock_group (sb, block_group); + +return cow_bh; +} + +/* +* ext4_snapshot_test_cow_bitmap - test if blocks are in use by snapshot +* @handle: JBD handle +* @snapshot: active snapshot +* @block: address of block +* @maxblocks: max no. of blocks to be tested +* @excluded: if not NULL, blocks belong to this excluded inode +* +* If the block bit is set in the COW bitmap, than it was allocated at the time +* that the active snapshot was taken and is therefore "in use" by the snapshot. +* +* Return values: +* > 0 - blocks are in use by snapshot +* = 0 - @blocks are not in use by snapshot +* < 0 - error +*/ +static int +ext4_snapshot_test_cow_bitmap (handle_t *handle,struct inode *snapshot, +ext4_fsblk_t block,int *maxblocks,struct inode *excluded) +{ +struct buffer_head *cow_bh; +unsigned long block_group =SNAPSHOT_BLOCK_GROUP (block); +ext4_grpblk_t bit =SNAPSHOT_BLOCK_GROUP_OFFSET (block); +ext4_fsblk_t snapshot_blocks =SNAPSHOT_BLOCKS (snapshot); +int ret; + +if (block >= snapshot_blocks) +/* +* Block is not is use by snapshot because it is past the +* last f/s block at the time that the snapshot was taken. +* (suggests that f/s was resized after snapshot take) +*/ +return 0 ; + + cow_bh =ext4_snapshot_read_cow_bitmap (handle, snapshot, block_group); +if (!cow_bh) +return -EIO ; +/* +* if the bit is set in the COW bitmap, +* then the block is in use by snapshot +*/ + + ret =ext4_mb_test_bit_range (bit, cow_bh->b_data, maxblocks); + +brelse (cow_bh); +return ret; +} +/* * COW functions */
@@ -248,8 +484,11 @@ int ext4_snapshot_test_and_cow(const char *where, handle_t *handle, cow =0 ; } -if (clear <0 ) - goto cowed; +/* get the COW bitmap and test if blocks are in use by snapshot */ + err =ext4_snapshot_test_cow_bitmap (handle, active_snapshot, + block, &count, clear <0 ? inode :NULL ); +if (err <0 ) + goto out;if (!err) {trace_cow_inc (handle, ok_bitmap); goto cowed;
@@ -374,7 +613,10 @@ int ext4_snapshot_test_and_move(const char *where, handle_t *handle, move =0 ; } -if (excluded) +/* get the COW bitmap and test if blocks are in use by snapshot */ + err =ext4_snapshot_test_cow_bitmap (handle, active_snapshot, + block, &count, excluded ? inode :NULL ); +if (err <0 ) goto out;if (!err) {/* block not in COW bitmap - no need to move */
fs/ext4/snapshot_ctl.c +18 -1
@@ -112,7 +112,24 @@ static int ext4_snapshot_set_active(struct super_block *sb,return 0 ; } -#define ext4_snapshot_reset_bitmap_cache (sb, init) 0 +/* +* ext4_snapshot_reset_bitmap_cache(): +* +* Resets the COW/exclude bitmap cache for all block groups. +* +* Called from snapshot_take() under journal_lock_updates(). +*/ +static void ext4_snapshot_reset_bitmap_cache (struct super_block *sb) +{ +struct ext4_group_info *grp; +int i; + +for (i =0 ; i <EXT4_SB (sb)->s_groups_count; i++) { + grp =ext4_get_group_info (sb, i); + grp->bg_cow_bitmap =0 ; +cond_resched (); + } +}/* * Snapshot constructor/destructor
Signature · 1 line
1.7.4.1
PATCH 18/36 ext4: snapshot control
In reply to [email protected]From: Amir Goldstein <[email protected]>
Snapshot control with chsnap/lssnap.
Take/delete snapshot with chsnap +/-S.
Enable/disable snapshot with chsnap +/-n.
Show snapshot status with lssnap.
--- fs/ext4/ext4.h | 2 + fs/ext4/ioctl.c | 117 ++++++++++ fs/ext4/snapshot.h | 8 + fs/ext4/snapshot_ctl.c | 593 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 720 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -584,6 +584,8 @@ struct ext4_new_group_data {/* note ioctl 10 reserved for an early version of the FIEMAP ioctl */ /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) +#define EXT4_IOC_GETSNAPFLAGS _IOR('f', 13, long) +#define EXT4_IOC_SETSNAPFLAGS _IOW('f', 14, long)#define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent)#if defined(__KERNEL__) && defined(CONFIG_COMPAT )
fs/ext4/ioctl.c +117 -0
153 lines not on this page · raw message
fs/ext4/snapshot.h +8 -0
@@ -346,6 +346,14 @@ static inline int ext4_snapshot_get_delete_access(handle_t *handle,/* snapshot_ctl.c */ /* +* Snapshot control functions +*/ +extern void ext4_snapshot_get_flags (struct inode *inode,struct file *filp); +extern int ext4_snapshot_set_flags (handle_t *handle,struct inode *inode, +unsigned int flags); +extern int ext4_snapshot_take (struct inode *inode); + +/* * Snapshot constructor/destructor */ extern int ext4_snapshot_load(struct super_block *sb,
fs/ext4/snapshot_ctl.c +593 -0
610 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 19/36 ext4: snapshot control - init new snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
On snapshot create, a few special blocks (i.e., the super block and group descriptors) are pre-allocated and on snapshot take, they are copied under journal_lock_updates(). This is done to avoid the recursion that would be caused by COWing these blocks after the snapshot becomes active.
--- fs/ext4/snapshot_ctl.c | 308 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 308 insertions(+), 0 deletions(-)
fs/ext4/snapshot_ctl.c +308 -0
@@ -299,6 +299,48 @@ int __extend_or_restart_transaction(const char *where,#define extend_or_restart_transaction_inode (handle, inode, nblocks) \ __extend_or_restart_transaction(__func__, (handle), (inode), (nblocks)) +/* +* helper function for snapshot_create(). +* places pre-allocated [d,t]ind blocks in position +* after they have been allocated as direct blocks. +*/ +static inline int ext4_snapshot_shift_blocks (struct ext4_inode_info *ei, +int from,int to,int count) +{ +int i, err = -EIO ; + +/* move from direct blocks range */ +BUG_ON (from <0 || from + count >EXT4_NDIR_BLOCKS ); +/* to indirect blocks range */ +BUG_ON (to <EXT4_NDIR_BLOCKS || to + count >EXT4_SNAPSHOT_N_BLOCKS ); + +/* +* truncate_mutex is held whenever allocating or freeing inode +* blocks. +*/ +down_write (&ei->i_data_sem); + +/* +* verify that 'from' blocks are allocated +* and that 'to' blocks are not allocated. +*/ +for (i =0 ; i < count; i++) +if (!ei->i_data[from+i] || + ei->i_data[(to+i)%EXT4_N_BLOCKS ]) + goto out; + +/* +* shift 'count' blocks from position 'from' to 'to' +*/ +for (i =0 ; i < count; i++) { + ei->i_data[(to+i)%EXT4_N_BLOCKS ] = ei->i_data[from+i]; + ei->i_data[from+i] =0 ; + } + err =0 ; +out: +up_write (&ei->i_data_sem); +return err; +} static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb, unsigned long ino,
@@ -344,6 +386,13 @@ static int ext4_snapshot_create(struct inode *inode)struct inode *active_snapshot =ext4_snapshot_has_active (sb);struct ext4_inode_info *ei =EXT4_I (inode);int i, err, ret; +int count, nind; +const long double_blocks = (1 << (2 *SNAPSHOT_ADDR_PER_BLOCK_BITS )); +struct buffer_head *bh =NULL ; +struct ext4_group_desc *desc; +unsigned long ino; +struct ext4_iloc iloc; +ext4_fsblk_t bmap_blk =0 , imap_blk =0 , inode_blk =0 ;ext4_fsblk_t snapshot_blocks =ext4_blocks_count (sbi->s_es);if (active_snapshot) { snapshot_debug(1, "failed to add snapshot because active "
@@ -418,6 +467,140 @@ static int ext4_snapshot_create(struct inode *inode)if (err) goto out_handle; +/* small filesystems can be mapped with just 1 double indirect block */ + nind =1 ; +if (snapshot_blocks > double_blocks) +/* add up to 4 triple indirect blocks to map 2^32 blocks */ + nind += ((snapshot_blocks - double_blocks) >> + (3 *SNAPSHOT_ADDR_PER_BLOCK_BITS )) +1 ; +if (nind >2 +EXT4_SNAPSHOT_EXTRA_TIND_BLOCKS ) { +snapshot_debug (1 ,"need too many [d,t]ind blocks (%d) " +"for snapshot (%u)\n" , + nind, inode->i_generation); + err = -EFBIG ; + goto out_handle; + } + + err =extend_or_restart_transaction_inode (handle, inode, + nind *EXT4_DATA_TRANS_BLOCKS (sb)); +if (err) + goto out_handle; + +/* pre-allocate and zero out [d,t]ind blocks */ +for (i =0 ; i < nind; i++) { +brelse (bh); + bh =ext4_getblk (handle, inode, i,SNAPMAP_WRITE , &err); +if (!bh) +break ; +/* zero out indirect block and journal as dirty metadata */ + err =ext4_journal_get_write_access (handle, bh); +if (err) +break ; +lock_buffer (bh); +memset (bh->b_data,0 , bh->b_size); +set_buffer_uptodate (bh); +unlock_buffer (bh); + err =ext4_handle_dirty_metadata (handle,NULL , bh); +if (err) +break ; + } +brelse (bh); +if (!bh || err) { +snapshot_debug (1 ,"failed to initiate [d,t]ind block (%d) " +"for snapshot (%u)\n" , + i, inode->i_generation); + goto out_handle; + } +/* place pre-allocated [d,t]ind blocks in position */ + err =ext4_snapshot_shift_blocks (ei,0 ,EXT4_DIND_BLOCK , nind); +if (err) { +snapshot_debug (1 ,"failed to move pre-allocated [d,t]ind blocks" +" for snapshot (%u)\n" , + inode->i_generation); + goto out_handle; + } + +/* allocate super block and group descriptors for snapshot */ + count = sbi->s_gdb_count +1 ; + err = count; +for (i =0 ; err >0 && i < count; i += err) { + err =extend_or_restart_transaction_inode (handle, inode, +EXT4_DATA_TRANS_BLOCKS (sb)); +if (err) + goto out_handle; + err =ext4_snapshot_map_blocks (handle, inode, i, count - i, +NULL ,SNAPMAP_WRITE ); + } +if (err <=0 ) { +snapshot_debug (1 ,"failed to allocate super block and %d " +"group descriptor blocks for snapshot (%u)\n" , + count -1 , inode->i_generation); +if (err) + err = -EIO ; + goto out_handle; + } + + ino = inode->i_ino; +/* +* pre-allocate the following blocks in the new snapshot: +* - block and inode bitmap blocks of ino's block group +* - inode table block that contains ino +*/ + err =extend_or_restart_transaction_inode (handle, inode, +3 *EXT4_DATA_TRANS_BLOCKS (sb)); +if (err) + goto out_handle; + + inode_blk =ext4_get_inode_block (sb, ino, &iloc); + + bmap_blk =0 ; + imap_blk =0 ; + desc =ext4_get_group_desc (sb, iloc.block_group,NULL ); +if (!desc) + goto next_snapshot; + + bmap_blk =ext4_block_bitmap (sb, desc); + imap_blk =ext4_inode_bitmap (sb, desc); +if (!bmap_blk || !imap_blk) + goto next_snapshot; + + count =1 ; +if (imap_blk == bmap_blk +1 ) + count++; +if ((count >1 ) && (inode_blk == imap_blk +1 )) + count++; +/* try to allocate all blocks at once */ + err =ext4_snapshot_map_blocks (handle, inode, + bmap_blk, count, +NULL ,SNAPMAP_WRITE ); + count = err; +/* allocate remaining blocks one by one */ +if (err >0 && count <2 ) + err =ext4_snapshot_map_blocks (handle, inode, + imap_blk,1 , +NULL , +SNAPMAP_WRITE ); +if (err >0 && count <3 ) + err =ext4_snapshot_map_blocks (handle, inode, + inode_blk,1 , +NULL , +SNAPMAP_WRITE ); +next_snapshot: +if (!bmap_blk || !imap_blk || !inode_blk || err <0 ) { +#ifdef CONFIG_EXT4_DEBUG +ext4_fsblk_t blk0 = iloc.block_group * +EXT4_BLOCKS_PER_GROUP (sb); +snapshot_debug (1 ,"failed to allocate block/inode bitmap " +"or inode table block of inode (%lu) " +"(%llu,%llu,%llu/%u) for snapshot (%u)\n" , + ino, bmap_blk - blk0, + imap_blk - blk0, inode_blk - blk0, + iloc.block_group, inode->i_generation); +#endif +if (!err) + err = -EIO ; + goto out_handle; + }snapshot_debug (1 ,"snapshot (%u) created\n" , inode->i_generation); err =0 ; out_handle:
@@ -427,6 +610,68 @@ out_handle:return err; } +/* +* ext4_snapshot_copy_block() - copy block to new snapshot +* @snapshot: new snapshot to copy block to +* @bh: source buffer to be copied +* @mask: if not NULL, mask buffer data before copying to snapshot +* (used to mask block bitmap with exclude bitmap) +* @name: name of copied block to print +* @idx: index of copied block to print +* +* Called from ext4_snapshot_take() under journal_lock_updates() +* Returns snapshot buffer on success, NULL on error +*/ +static struct buffer_head *ext4_snapshot_copy_block (struct inode *snapshot, +struct buffer_head *bh,const char *mask, +const char *name,unsigned long idx) +{ +struct buffer_head *sbh =NULL ; +int err; + +if (!bh) +return NULL ; + + sbh =ext4_getblk (NULL , snapshot, +SNAPSHOT_IBLOCK (bh->b_blocknr), +SNAPMAP_READ , &err); + +if (!sbh || sbh->b_blocknr == bh->b_blocknr) { +snapshot_debug (1 ,"failed to copy %s (%lu) " +"block [%llu/%llu] to snapshot (%u)\n" , + name, idx, +SNAPSHOT_BLOCK_TUPLE (bh->b_blocknr), + snapshot->i_generation); +brelse (sbh); +return NULL ; + } + +ext4_snapshot_copy_buffer (sbh, bh, mask); + +snapshot_debug (4 ,"copied %s (%lu) block [%llu/%llu] " +"to snapshot (%u)\n" , + name, idx, +SNAPSHOT_BLOCK_TUPLE (bh->b_blocknr), + snapshot->i_generation); +return sbh; +} + +/* +* List of blocks which are copied to snapshot for every special inode. +* Keep block bitmap first and inode table block last in the list. +*/ +enum copy_inode_block { +COPY_BLOCK_BITMAP , +COPY_INODE_BITMAP , +COPY_INODE_TABLE , +COPY_INODE_BLOCKS_NUM +}; + +static char *copy_inode_block_name[COPY_INODE_BLOCKS_NUM ] = { +"block bitmap" , +"inode bitmap" , +"inode table" +};/* * ext4_snapshot_take() makes a new snapshot file
@@ -443,6 +688,12 @@ int ext4_snapshot_take(struct inode *inode)struct ext4_super_block *es =NULL ;struct buffer_head *es_bh =NULL ;struct buffer_head *sbh =NULL ; +struct buffer_head *bhs[COPY_INODE_BLOCKS_NUM ] = {NULL }; +const char *mask =NULL ; +struct inode *curr_inode; +struct ext4_iloc iloc; +struct ext4_group_desc *desc; +int i;int err = -EIO ;if (!sbi->s_sbh)
@@ -489,6 +740,61 @@ int ext4_snapshot_take(struct inode *inode) }#endif +/* +* copy group descriptors to snapshot +*/ +for (i =0 ; i < sbi->s_gdb_count; i++) { +brelse (sbh); + sbh =ext4_snapshot_copy_block (inode, + sbi->s_group_desc[i],NULL , +"GDT" , i); +if (!sbh) + goto out_unlockfs; + } + + curr_inode = inode; +/* +* copy the following blocks to the new snapshot: +* - block and inode bitmap blocks of curr_inode block group +* - inode table block that contains curr_inode +*/ + iloc.block_group =0 ; + err =ext4_get_inode_loc (curr_inode, &iloc); +brelse (bhs[COPY_INODE_TABLE ]); + bhs[COPY_INODE_TABLE ] = iloc.bh; + desc =ext4_get_group_desc (sb, iloc.block_group,NULL ); +if (err || !desc) { +snapshot_debug (1 ,"failed to read inode and bitmap blocks " +"of inode (%lu)\n" , curr_inode->i_ino); + err = err ? : -EIO ; + goto out_unlockfs; + } +brelse (bhs[COPY_BLOCK_BITMAP ]); + bhs[COPY_BLOCK_BITMAP ] =sb_bread (sb, +ext4_block_bitmap (sb, desc)); +brelse (bhs[COPY_INODE_BITMAP ]); + bhs[COPY_INODE_BITMAP ] =sb_bread (sb, +ext4_inode_bitmap (sb, desc)); + err = -EIO ; +for (i =0 ; i <COPY_INODE_BLOCKS_NUM ; i++) { +brelse (sbh); + sbh =ext4_snapshot_copy_block (inode, bhs[i], mask, + copy_inode_block_name[i], curr_inode->i_ino); +if (!sbh) + goto out_unlockfs; + mask =NULL ; + } + +/* +* copy super block to snapshot and fix it +*/ +lock_buffer (es_bh); +memcpy (es_bh->b_data, sbi->s_sbh->b_data, sb->s_blocksize); +set_buffer_uptodate (es_bh); +unlock_buffer (es_bh); +mark_buffer_dirty (es_bh); +sync_dirty_buffer (es_bh); +/* reset i_size and invalidate page cache */ SNAPSHOT_SET_DISABLED (inode);
@@ -523,6 +829,8 @@ out_unlockfs: out_err:brelse (es_bh);brelse (sbh); +for (i =0 ; i <COPY_INODE_BLOCKS_NUM ; i++) +brelse (bhs[i]);return err; }
Signature · 1 line
1.7.4.1
PATCH 20/36 ext4: snapshot control - fix new snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
On snapshot take, after copying the pre-allocated blocks, some are fixed to make the snapshot image appear as a valid Ext4 file system. The has_snapshot flags is cleared from the super block as well as the last_snapshot field and all snapshot inodes are cleared (to appear as empty inodes).
--- fs/ext4/ext4.h | 2 + fs/ext4/inode.c | 4 +- fs/ext4/snapshot_ctl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 4 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -1839,6 +1839,8 @@ struct buffer_head *ext4_bread(handle_t *, struct inode *,int ext4_get_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create); +extern blkcnt_t ext4_inode_blocks (struct ext4_inode *raw_inode, +struct ext4_inode_info *ei);extern struct inode *ext4_iget (struct super_block *,unsigned long );extern int ext4_write_inode (struct inode *,struct writeback_control *);extern int ext4_setattr (struct dentry *,struct iattr *);
fs/ext4/inode.c +2 -2
@@ -5178,8 +5178,8 @@ void ext4_get_inode_flags(struct ext4_inode_info *ei) }while (cmpxchg (&ei->i_flags, old_fl, new_fl) != old_fl); } -static blkcnt_t ext4_inode_blocks (struct ext4_inode *raw_inode, -struct ext4_inode_info *ei) +blkcnt_t ext4_inode_blocks (struct ext4_inode *raw_inode, +struct ext4_inode_info *ei) {blkcnt_t i_blocks ;struct inode *inode = &(ei->vfs_inode);
fs/ext4/snapshot_ctl.c +72 -2
128 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 21/36 ext4: snapshot control - reserve disk space for snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
Ensure there is enough disk space for snapshot file future use. Reserve disk space on snapshot take based on file system overhead size, number of directories and number of blocks/inodes in use.
--- fs/ext4/balloc.c | 25 +++++++++++++++++++++++++ fs/ext4/ext4.h | 2 ++ fs/ext4/mballoc.c | 6 ++++++ fs/ext4/snapshot_ctl.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/super.c | 16 +++++++++++++++- 5 files changed, 92 insertions(+), 1 deletions(-)
fs/ext4/balloc.c +25 -0
@@ -372,6 +372,8 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)static int ext4_has_free_blocks (struct ext4_sb_info *sbi,s64 nblocks) {s64 free_blocks, dirty_blocks, root_blocks; +ext4_fsblk_t snapshot_r_blocks; +handle_t *handle =journal_current_handle ();struct percpu_counter *fbc = &sbi->s_freeblocks_counter;struct percpu_counter *dbc = &sbi->s_dirtyblocks_counter;
@@ -379,6 +381,29 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks) dirty_blocks =percpu_counter_read_positive (dbc); root_blocks =ext4_r_blocks_count (sbi->s_es); +if (ext4_snapshot_active (sbi)) { +if (unlikely (free_blocks < (nblocks + dirty_blocks))) +/* sorry, but we're really out of space */ +return 0 ; +if (handle &&unlikely (IS_COWING (handle))) +/* any available space may be used by COWing task */ +return 1 ; +/* reserve blocks for active snapshot */ + snapshot_r_blocks = +le64_to_cpu (sbi->s_es->s_snapshot_r_blocks_count); +/* +* The last snapshot_r_blocks are reserved for active snapshot +* and may not be allocated even by root. +*/ +if (free_blocks < (nblocks + dirty_blocks + snapshot_r_blocks)) +return 0 ; +/* +* Mortal users must reserve blocks for both snapshot and +* root user. +*/ + root_blocks += snapshot_r_blocks; + } +if (free_blocks - (nblocks + root_blocks + dirty_blocks) <EXT4_FREEBLOCKS_WATERMARK ) { free_blocks =percpu_counter_sum_positive (fbc);
fs/ext4/ext4.h +2 -0
@@ -1963,6 +1963,8 @@ extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group, struct ext4_group_desc *gdp);extern int ext4_group_desc_csum_verify (struct ext4_sb_info *sbi,__u32 group,struct ext4_group_desc *gdp); +struct kstatfs ; +extern int ext4_statfs_sb (struct super_block *sb,struct kstatfs *buf);static inline ext4_fsblk_t ext4_blocks_count (struct ext4_super_block *es) {
fs/ext4/mballoc.c +6 -0
@@ -4296,10 +4296,16 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,return 0 ; } reserv_blks = ar->len; +if (unlikely (ar->flags &EXT4_MB_HINT_COWING )) { +/* don't fail when allocating blocks for COW */ +dquot_alloc_block_nofail (ar->inode, ar->len); + goto nofail; + }while (ar->len &&dquot_alloc_block (ar->inode, ar->len)) { ar->flags |=EXT4_MB_HINT_NOPREALLOC ; ar->len--; } +nofail: inquota = ar->len;if (ar->len ==0 ) { *errp = -EDQUOT ;
fs/ext4/snapshot_ctl.c +44 -0
62 lines not on this page · raw message
fs/ext4/super.c +15 -1
@@ -4515,7 +4515,11 @@ restore_opts:static int ext4_statfs (struct dentry *dentry,struct kstatfs *buf) { -struct super_block *sb = dentry->d_sb; +return ext4_statfs_sb (dentry->d_sb, buf); +} + +int ext4_statfs_sb (struct super_block *sb,struct kstatfs *buf) +{struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_super_block *es = sbi->s_es;u64 fsid;
@@ -4567,6 +4571,16 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_bavail = buf->f_bfree -ext4_r_blocks_count (es);if (buf->f_bfree <ext4_r_blocks_count (es)) buf->f_bavail =0 ; +if (ext4_snapshot_active (sbi)) { +if (buf->f_bfree <ext4_r_blocks_count (es) + +le64_to_cpu (es->s_snapshot_r_blocks_count)) + buf->f_bavail =0 ; +else + buf->f_bavail -= +le64_to_cpu (es->s_snapshot_r_blocks_count); + } + buf->f_spare[0 ] =percpu_counter_sum_positive (&sbi->s_dirs_counter); + buf->f_spare[1 ] = sbi->s_overhead_last; buf->f_files =le32_to_cpu (es->s_inodes_count); buf->f_ffree =percpu_counter_sum_positive (&sbi->s_freeinodes_counter); buf->f_namelen =EXT4_NAME_LEN ;
Signature · 1 line
1.7.4.1
PATCH 22/36 ext4: snapshot journaled - increase transaction credits
In reply to [email protected]From: Amir Goldstein <[email protected]>
Snapshot operations are journaled as part of the running transaction. The amount of requested credits is multiplied with a factor, to ensure that enough buffer credits are reserved in the running transaction. The new field h_base_credits stored to original credits request and the new filed u_user_credits counts the number of credits used by non-COW operations. They are especially useful when exteding a large transaction, which did not use the extra COW credits it requested. In this case, only the missing extra credits are requested.
--- fs/ext4/ext4_jbd2.c | 21 +++++++ fs/ext4/ext4_jbd2.h | 159 ++++++++++++++++++++++++++++++++++++++++++++++----- fs/ext4/resize.c | 2 +- fs/ext4/snapshot.c | 12 ++++ fs/ext4/super.c | 38 ++++++++++++- 5 files changed, 214 insertions(+), 18 deletions(-)
fs/ext4/ext4_jbd2.c +21 -0
@@ -131,6 +131,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, handle_t *handle, struct inode *inode, struct buffer_head *bh) { + struct super_block *sb;int err =0 ;if (ext4_handle_valid (handle)) {
@@ -138,6 +139,26 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err); +if (err) +return err; + sb = handle->h_transaction->t_journal->j_private; +if (EXT4_SNAPSHOTS (sb) && !IS_COWING (handle)) { +struct journal_head *jh =bh2jh (bh); +jbd_lock_bh_state (bh); +/* +* buffer_credits was decremented when buffer was +* modified for the first time in the current +* transaction, which may have been during a COW +* operation. We decrement user_credits and mark +* b_modified = 2, on the first time that the buffer +* is modified not during a COW operation (!h_cowing). +*/ +if (jh->b_modified ==1 ) { + jh->b_modified =2 ; + handle->h_user_credits--; + } +jbd_unlock_bh_state (bh); + } }else {if (inode)mark_buffer_dirty_inode (bh, inode);
fs/ext4/ext4_jbd2.h +144 -15
193 lines not on this page · raw message
fs/ext4/resize.c +1 -1
@@ -668,7 +668,7 @@ static void update_backups(struct super_block *sb,/* Out of journal space, and can't get more - abort - so sad */ if (ext4_handle_valid (handle) && - handle->h_buffer_credits ==0 && + !ext4_handle_has_enough_credits (handle,1 ) &&ext4_journal_extend (handle,EXT4_MAX_TRANS_DATA ) && (err =ext4_journal_restart (handle,EXT4_MAX_TRANS_DATA )))break ;
fs/ext4/snapshot.c +12 -0
@@ -405,6 +405,18 @@ __ext4_snapshot_trace_cow(const char *where, handle_t *handle,*/ static inline void ext4_snapshot_cow_begin (handle_t *handle) { +if (!ext4_handle_has_enough_credits (handle,1 )) { +/* +* The test above is based on lower limit heuristics of +* user_credits/buffer_credits, which is not always accurate, +* so it is possible that there is no bug here, just another +* false alarm. +*/ +snapshot_debug_hl (1 ,"warning: insufficient buffer/user " +"credits (%d/%d) for COW operation?\n" , + handle->h_buffer_credits, + handle->h_user_credits); + }snapshot_debug_hl (4 ,"{\n" ); handle->h_cowing =1 ; }
fs/ext4/super.c +36 -2
@@ -264,8 +264,10 @@ static void ext4_put_nojournal(handle_t *handle)* ext4 prevents a new handle from being started by s_frozen, which * is in an upper layer. */ -handle_t *ext4_journal_start_sb (struct super_block *sb,int nblocks) +handle_t *__ext4_journal_start (const char *where, +struct super_block *sb,int nblocks) { +int credits;journal_t *journal;handle_t *handle;
@@ -296,7 +298,18 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)ext4_abort (sb,"Detected aborted journal" );return ERR_PTR (-EROFS ); } -return jbd2_journal_start (journal, nblocks); + + credits =EXT4_SNAPSHOTS (sb) ? +EXT4_SNAPSHOT_START_TRANS_BLOCKS (nblocks) : nblocks; + handle =jbd2_journal_start (journal, credits); +if (EXT4_SNAPSHOTS (sb) && !IS_ERR (handle)) { +if (handle->h_ref ==1 ) { + handle->h_base_credits = nblocks; + handle->h_user_credits = nblocks; + } +ext4_journal_trace (SNAP_WARN , where, handle, nblocks); + } +return handle; }/*
@@ -3874,6 +3887,27 @@ static journal_t *ext4_get_journal(struct super_block *sb,return NULL ; } +if (EXT4_SNAPSHOTS (sb) && + (journal_inode->i_size >>EXT4_BLOCK_SIZE_BITS (sb)) < +EXT4_MIN_JOURNAL_BLOCKS ) { +ext4_msg (sb,KERN_ERR , +"journal is too small (%lld < %u) for snapshots" , + journal_inode->i_size >>EXT4_BLOCK_SIZE_BITS (sb), +EXT4_MIN_JOURNAL_BLOCKS ); +iput (journal_inode); +return NULL ; + } + +if (EXT4_SNAPSHOTS (sb) && + (journal_inode->i_size >>EXT4_BLOCK_SIZE_BITS (sb)) < +EXT4_BIG_JOURNAL_BLOCKS ) { +snapshot_debug (1 ,"warning: journal is not big enough " +"(%lld < %u) - this might affect concurrent " +"filesystem writers performance!\n" , + journal_inode->i_size >>EXT4_BLOCK_SIZE_BITS (sb), +EXT4_BIG_JOURNAL_BLOCKS ); + } + journal =jbd2_journal_init_inode (journal_inode);if (!journal) {ext4_msg (sb,KERN_ERR ,"Could not load journal inode" );
Signature · 1 line
1.7.4.1
PATCH 23/36 ext4: snapshot journaled - implement journal_release_buffer()
In reply to [email protected]From: Amir Goldstein <[email protected]>
The API journal_release_buffer() is called to cancel a previous call to journal_get_write_access() and to recall the used buffer credit. Current implementation of journal_release_buffer() in JBD is empty, since no buffer credits are used until the buffer is marked dirty. However, since the resulting snapshot COW operation cannot be undone, we try to extend the current transaction to compensate for the used credits of the extra COW operation, so we don't run out of buffer credits too soon.
--- fs/ext4/ext4_jbd2.c | 39 +++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4_jbd2.h | 11 +++++------ fs/ext4/ialloc.c | 10 ++++++++-- fs/ext4/xattr.c | 4 +++- 4 files changed, 55 insertions(+), 9 deletions(-)
fs/ext4/ext4_jbd2.c +39 -0
@@ -127,6 +127,45 @@ int __ext4_journal_get_create_access(const char *where, unsigned int line,return err; } +int __ext4_handle_release_buffer (const char *where,handle_t *handle, +struct buffer_head *bh) +{ +struct super_block *sb; +int err =0 ; + +if (!ext4_handle_valid (handle)) +return 0 ; + + sb = handle->h_transaction->t_journal->j_private; +if (!EXT4_SNAPSHOTS (sb) ||IS_COWING (handle)) + goto out; + +/* +* Trying to cancel a previous call to get_write_access(), which may +* have resulted in a single COW operation. We don't need to add +* user credits, but if COW credits are too low we will try to +* extend the transaction to compensate for the buffer credits used +* by the extra COW operation. +*/ + err =ext4_journal_extend (handle,0 ); +if (err >0 ) { +/* well, we can't say we didn't try - now lets hope +* we have enough buffer credits to spare */ +snapshot_debug (handle->h_buffer_credits <EXT4_MAX_TRANS_DATA + ?1 :2 , +"%s: warning: couldn't extend transaction " +"from %s (credits=%d/%d)\n" , __func__, + where, handle->h_buffer_credits, + handle->h_user_credits); + err =0 ; + } +ext4_journal_trace (SNAP_WARN , where, handle,-1 ); +out: +if (!err) +jbd2_journal_release_buffer (handle, bh); +return err; +} +int __ext4_handle_dirty_metadata (const char *where,unsigned int line,handle_t *handle,struct inode *inode,struct buffer_head *bh)
fs/ext4/ext4_jbd2.h +5 -6
@@ -264,12 +264,11 @@ static inline void ext4_handle_sync(handle_t *handle) handle->h_sync =1 ; } -static inline void ext4_handle_release_buffer (handle_t *handle, -struct buffer_head *bh) -{ -if (ext4_handle_valid (handle)) -jbd2_journal_release_buffer (handle, bh); -} +int __ext4_handle_release_buffer (const char *where,handle_t *handle, +struct buffer_head *bh); + +#define ext4_handle_release_buffer (handle, bh) \ + __ext4_handle_release_buffer(__func__, (handle), (bh))static inline int ext4_handle_is_aborted (handle_t *handle) {
fs/ext4/ialloc.c +8 -2
@@ -917,8 +917,14 @@ repeat_in_this_group: goto got; }/* we lost it */ -ext4_handle_release_buffer (handle, inode_bitmap_bh); -ext4_handle_release_buffer (handle, group_desc_bh); + err =ext4_handle_release_buffer (handle, + inode_bitmap_bh); +if (err) + goto fail; + err =ext4_handle_release_buffer (handle, + group_desc_bh); +if (err) + goto fail;if (++ino <EXT4_INODES_PER_GROUP (sb)) goto repeat_in_this_group;
fs/ext4/xattr.c +3 -1
@@ -735,7 +735,9 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,int offset = (char *)s->here - bs->bh->b_data;unlock_buffer (bs->bh); -ext4_handle_release_buffer (handle, bs->bh); + error =ext4_handle_release_buffer (handle, bs->bh); +if (error) + goto cleanup;if (ce) {mb_cache_entry_release (ce); ce =NULL ;
Signature · 1 line
1.7.4.1
PATCH 24/36 ext4: snapshot journaled - bypass to save credits
In reply to [email protected]From: Amir Goldstein <[email protected]>
Don't journal COW bitmap indirect blocks to save journal credits. On very few COW operations (i.e., first block group access after snapshot take), there may be up to 3 extra blocks allocated for the active snapshot (i.e., COW bitmap block and up to 2 indirect blocks). Taking these 2 indorect blocks into account on every COW operation would further increase the transaction's COW credits factor. Instead, we choose to pay a small performance penalty on these few COW bitmap operations and wait until they are synced to disk.
--- fs/ext4/inode.c | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-)
fs/ext4/inode.c +27 -4
@@ -835,7 +835,8 @@ static int ext4_alloc_branch_cow(handle_t *handle, struct inode *inode, branch[n].bh = bh;lock_buffer (bh);BUFFER_TRACE (bh,"call get_create_access" ); - err =ext4_journal_get_create_access (handle, bh); +if (!SNAPMAP_ISSYNC (flags)) + err =ext4_journal_get_create_access (handle, bh);if (err) {/* Don't brelse(bh) here; it's done in * ext4_journal_forget() below */
@@ -862,7 +863,21 @@ static int ext4_alloc_branch_cow(handle_t *handle, struct inode *inode,unlock_buffer (bh);BUFFER_TRACE (bh,"call ext4_handle_dirty_metadata" ); - err =ext4_handle_dirty_metadata (handle, inode, bh); +/* +* When accessing a block group for the first time, the +* block bitmap is the first block to be copied to the +* snapshot. We don't want to reserve journal credits for +* the indirect blocks that map the bitmap copy (the COW +* bitmap), so instead of writing through the journal, we +* sync the indirect blocks directly to disk. Of course, +* this is not good for performance but it only happens once +* per snapshot/blockgroup. +*/ +if (SNAPMAP_ISSYNC (flags)) { +mark_buffer_dirty (bh); +sync_dirty_buffer (bh); + }else + err =ext4_handle_dirty_metadata (handle, inode, bh);if (err) goto failed; }
@@ -871,6 +886,9 @@ static int ext4_alloc_branch_cow(handle_t *handle, struct inode *inode, failed:/* Allocation failed, free what we already allocated */ ext4_free_blocks (handle, inode,NULL , new_blocks[0 ],1 ,0 ); +/* If we bypassed journal, we don't need to forget any block */ +if (SNAPMAP_ISSYNC (flags)) + n =1 ;for (i =1 ; i <= n ; i++) {/* * branch[i].bh is newly allocated, so there is no
@@ -966,13 +984,18 @@ static int ext4_splice_branch_cow(handle_t *handle, struct inode *inode, err_out:for (i =1 ; i <= num; i++) { +int forget =EXT4_FREE_BLOCKS_FORGET ; + +/* If we bypassed journal, we don't need to forget */ +if (SNAPMAP_ISSYNC (flags)) + forget =0 ; +/* * branch[i].bh is newly allocated, so there is no * need to revoke the block, which is why we don't * need to set EXT4_FREE_BLOCKS_METADATA. */ -ext4_free_blocks (handle, inode, where[i].bh,0 ,1 , -EXT4_FREE_BLOCKS_FORGET ); +ext4_free_blocks (handle, inode, where[i].bh,0 ,1 , forget); }if (SNAPMAP_ISMOVE (flags))/* don't charge snapshot file owner if move failed */
Signature · 1 line
1.7.4.1
PATCH 25/36 ext4: snapshot journaled - cache last COW tid in journal_head
In reply to [email protected]From: Amir Goldstein <[email protected]>
Cache last COW transaction id in buffer's journal_head. The cache suppresses COW tests until the transaction in committed. By default, the running transaction is committed every 5 seconds which implies an average COW cache expiry of 2.5 seconds. Before taking a new snapshot, the journal is flushed to disk and the current transaction in committed, so the COW cache is invalidated (as it should be).
--- fs/ext4/snapshot.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot.h | 2 + fs/ext4/snapshot_debug.c | 7 +++ 3 files changed, 102 insertions(+), 0 deletions(-)
fs/ext4/snapshot.c +93 -0
@@ -400,6 +400,90 @@ __ext4_snapshot_trace_cow(const char *where, handle_t *handle,#define ext4_snapshot_trace_cow (where, handle, sb, inode, bh, blk, cnt, cmd)#endif /* +* The last transaction ID during which the buffer has been COWed is stored in +* the b_cow_tid field of the journal_head struct. If we know that the buffer +* was COWed during the current transaction, we don't need to COW it again. +* [jbd_lock_bh_state()] +*/ + +void init_ext4_snapshot_cow_cache (void ) +{ +#ifdef CONFIG_EXT4_DEBUG + cow_cache_enabled =1 ; +#endif +} + +#ifdef CONFIG_EXT4_DEBUG +#define cow_cache_enabled () (cow_cache_enabled) +#else +#define cow_cache_enabled () (1) +#endif + +#define test_cow_tid (jh, handle) \ + ((jh)->b_cow_tid == (handle)->h_transaction->t_tid) +#define set_cow_tid (jh, handle) \ + ((jh)->b_cow_tid = (handle)->h_transaction->t_tid) + +/* +* Journal COW cache functions. +* a block can only be COWed once per snapshot, +* so a block can only be COWed once per transaction, +* so a buffer that was COWed in the current transaction, +* doesn't need to be COWed. +* +* Return values: +* 1 - block was COWed in current transaction +* 0 - block wasn't COWed in current transaction +*/ +static int +ext4_snapshot_test_cowed (handle_t *handle,struct buffer_head *bh) +{ +struct journal_head *jh; + +if (!cow_cache_enabled ()) +return 0 ; + +/* check the COW tid in the journal head */ +if (bh &&buffer_jbd (bh)) { +jbd_lock_bh_state (bh); + jh =bh2jh (bh); +if (jh && !test_cow_tid (jh, handle)) + jh =NULL ; +jbd_unlock_bh_state (bh); +if (jh) +/* +* Block was already COWed in the running transaction, +* so we don't need to COW it again. +*/ +return 1 ; + } +return 0 ; +} + +static void +ext4_snapshot_mark_cowed (handle_t *handle,struct buffer_head *bh) +{ +struct journal_head *jh; + +if (!cow_cache_enabled ()) +return ; + +if (bh &&buffer_jbd (bh)) { +jbd_lock_bh_state (bh); + jh =bh2jh (bh); +if (jh && !test_cow_tid (jh, handle)) +/* +* this is the first time this block was COWed +* in the running transaction. +* update the COW tid in the journal head +* to mark that this block doesn't need to be COWed. +*/ +set_cow_tid (jh, handle); +jbd_unlock_bh_state (bh); + } +} + +/* * Begin COW or move operation. * No locks needed here, because @handle is a per-task struct. */
@@ -479,6 +563,13 @@ int ext4_snapshot_test_and_cow(const char *where, handle_t *handle,snapshot_debug_hl (4 ,"active snapshot access denied!\n" );return -EPERM ; } +/* check if the buffer was COWed in the current transaction */ +if (ext4_snapshot_test_cowed (handle, bh)) { +snapshot_debug_hl (4 ,"buffer found in COW cache - " +"skip block cow!\n" ); +trace_cow_inc (handle, ok_jh); +return 0 ; + }/* BEGIN COWing */ ext4_snapshot_cow_begin (handle);
@@ -572,6 +663,8 @@ int ext4_snapshot_test_and_cow(const char *where, handle_t *handle, test_pending_cow: cowed: +/* mark the buffer COWed in the current transaction */ +ext4_snapshot_mark_cowed (handle, bh); out:brelse (sbh);/* END COWing */
fs/ext4/snapshot.h +2 -0
@@ -342,6 +342,7 @@ static inline int ext4_snapshot_get_delete_access(handle_t *handle,return ext4_snapshot_move (handle, inode, block, pcount,1 ); } +extern void init_ext4_snapshot_cow_cache (void );/* snapshot_ctl.c */
@@ -364,6 +365,7 @@ extern void ext4_snapshot_destroy(struct super_block *sb);static inline int init_ext4_snapshot (void ) { +init_ext4_snapshot_cow_cache ();return 0 ; }
fs/ext4/snapshot_debug.c +7 -0
@@ -47,10 +47,12 @@ static const char *snapshot_test_names[SNAPSHOT_TESTS_NUM] = {u16 snapshot_enable_test[SNAPSHOT_TESTS_NUM ]__read_mostly = {0 };u8 snapshot_enable_debug__read_mostly =1 ; +u8 cow_cache_enabled__read_mostly =1 ;static struct dentry *snapshot_debug;static struct dentry *snapshot_version;static struct dentry *snapshot_test[SNAPSHOT_TESTS_NUM ]; +static struct dentry *cow_cache;static char snapshot_version_str[] =EXT4_SNAPSHOT_VERSION ;static struct debugfs_blob_wrapper snapshot_version_blob = {
@@ -79,6 +81,9 @@ void ext4_snapshot_create_debugfs_entry(struct dentry *debugfs_dir)S_IRUGO |S_IWUSR , debugfs_dir, &snapshot_enable_test[i]); + cow_cache =debugfs_create_u8 ("cow-cache" ,S_IRUGO |S_IWUSR , + debugfs_dir, + &cow_cache_enabled); }/*
@@ -89,6 +94,8 @@ void ext4_snapshot_remove_debugfs_entry(void) {int i; +if (cow_cache) +debugfs_remove (cow_cache);for (i =0 ; i <SNAPSHOT_TESTS_NUM && i <SNAPSHOT_TEST_NAMES ; i++)if (snapshot_test[i])debugfs_remove (snapshot_test[i]);
Signature · 1 line
1.7.4.1
PATCH 26/36 ext4: snapshot journaled - trace COW/buffer credits
In reply to [email protected]From: Amir Goldstein <[email protected]>
Extra debug prints to trace snapshot usage of buffer credits.
--- fs/ext4/ext4_jbd2.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4_jbd2.h | 26 ++++++++++++++++ fs/ext4/super.c | 2 + 3 files changed, 108 insertions(+), 0 deletions(-)
fs/ext4/ext4_jbd2.c +80 -0
@@ -23,6 +23,7 @@ int __ext4_handle_get_bitmap_access(const char *where, unsigned int line,if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err); +ext4_journal_trace (SNAP_DEBUG , where, handle,1 ); }return err; }
@@ -40,6 +41,7 @@ int __ext4_journal_get_write_access_inode(const char *where, unsigned int line,if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err); +ext4_journal_trace (SNAP_DEBUG , where, handle,1 ); }return err; }
@@ -91,6 +93,7 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle,if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err); +ext4_journal_trace (SNAP_DEBUG , where, handle,1 );return err; }return 0 ;
@@ -108,6 +111,7 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle, "error %d when attempting revoke", err); }BUFFER_TRACE (bh,"exit" ); +ext4_journal_trace (SNAP_DEBUG , where, handle,1 );return err; }
@@ -123,6 +127,7 @@ int __ext4_journal_get_create_access(const char *where, unsigned int line,if (err)ext4_journal_abort_handle (where, line, __func__, bh, handle, err); +ext4_journal_trace (SNAP_DEBUG , where, handle,-1 ); }return err; }
@@ -198,6 +203,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, }jbd_unlock_bh_state (bh); } +ext4_journal_trace (SNAP_DEBUG , where, handle,-1 ); }else {if (inode)mark_buffer_dirty_inode (bh, inode);
@@ -236,3 +242,77 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line, sb->s_dirt =1 ;return err; } + +#ifdef CONFIG_JBD2_DEBUG +static void ext4_journal_cow_stats (int n,handle_t *handle) +{ +snapshot_debug (n,"COW stats: moved/copied=%d/%d, " +"mapped/bitmap/cached=%d/%d/%d, " +"bitmaps/cleared=%d/%d\n" , handle->h_cow_moved, + handle->h_cow_copied, handle->h_cow_ok_mapped, + handle->h_cow_ok_bitmap, handle->h_cow_ok_jh, + handle->h_cow_bitmaps, handle->h_cow_excluded); +} +#else +#define ext4_journal_cow_stats (n, handle) +#endif + +#ifdef CONFIG_EXT4_DEBUG +void __ext4_journal_trace (int n,const char *fn,const char *caller, +handle_t *handle,int nblocks) +{ +int active_snapshot; +int upper; +int lower; +int final; +struct super_block *sb; + + sb = handle->h_transaction->t_journal->j_private; +if (!EXT4_SNAPSHOTS (sb)) +return ; + + active_snapshot =ext4_snapshot_active (EXT4_SB (sb)); + upper =EXT4_SNAPSHOT_START_TRANS_BLOCKS (handle->h_base_credits); + lower =EXT4_SNAPSHOT_TRANS_BLOCKS (handle->h_user_credits); + final = (nblocks ==0 && handle->h_ref ==1 && + !IS_COWING (handle)); + +switch (snapshot_enable_debug) { +case SNAP_INFO : +/* trace final journal_stop if any credits have been used */ +if (final && (handle->h_buffer_credits < upper || + handle->h_user_credits < handle->h_base_credits)) +break ; +case SNAP_WARN : +/* +* trace if buffer credits are too low - lower limit is only +* valid if there is an active snapshot and not during COW +*/ +if (handle->h_buffer_credits < lower && + active_snapshot && !IS_COWING (handle)) +break ; +case SNAP_ERR : +/* trace if user credits are too low */ +if (handle->h_user_credits <0 ) +break ; +case 0 : +/* no trace */ +return ; + +case SNAP_DEBUG : +default : +/* trace all calls */ +break ; + } + +snapshot_debug_l (n,IS_COWING (handle),"%s(%d): credits=%d," +" limit=%d/%d, user=%d/%d, ref=%d, caller=%s\n" , + fn, nblocks, handle->h_buffer_credits, lower, upper, + handle->h_user_credits, handle->h_base_credits, + handle->h_ref, caller); +if (!final) +return ; + +ext4_journal_cow_stats (n, handle); +} +#endif
fs/ext4/ext4_jbd2.h +26 -0
@@ -229,10 +229,36 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,#define ext4_handle_dirty_super (handle, sb) \ __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb)) +/* +* macros for ext4 to update transaction COW statistics. +* if the kernel was compiled without CONFIG_JBD2_DEBUG +* then the h_cow_* fields are not allocated in handle objects. +*/ +#ifdef CONFIG_JBD2_DEBUG +#define trace_cow_add (handle, name, num) \ + (handle)->h_cow_##name += (num) +#define trace_cow_inc (handle, name) \ + (handle)->h_cow_##name++; + +#else #define trace_cow_add (handle, name, num)#define trace_cow_inc (handle, name) +#endif +#ifdef CONFIG_EXT4_DEBUG +void __ext4_journal_trace (int debug,const char *fn,const char *caller, +handle_t *handle,int nblocks); + +#define ext4_journal_trace (n, caller, handle, nblocks) \ + do { \ + if ((n) <= snapshot_enable_debug) \ + __ext4_journal_trace((n), __func__, (caller), \ + (handle), (nblocks)); \ + } while (0) + +#else #define ext4_journal_trace (n, caller, handle, nblocks) +#endif handle_t *__ext4_journal_start (const char *where,struct super_block *sb,int nblocks);
fs/ext4/super.c +2 -0
@@ -324,6 +324,8 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)int err;int rc; +ext4_journal_trace (SNAP_WARN , where, handle,0 ); +if (!ext4_handle_valid (handle)) {ext4_put_nojournal (handle);return 0 ;
Signature · 1 line
1.7.4.1
PATCH 27/36 ext4: snapshot list support
In reply to [email protected]From: Amir Goldstein <[email protected]>
Implementation of multiple incremental snapshots. Snapshot inodes are chained on a list starting at the super block, both on-disk and in-memory, similar to the orphan inodes. Unlink and truncate of snapshot inodes on the list is not allowed, so an inode can never be chained on both orphan and snapshot lists. We make use of this fact to overload the in-memory inode field ext4_inode_info.i_orphan for the chaining of snapshots.
--- fs/ext4/ext4.h | 1 + fs/ext4/snapshot_ctl.c | 329 ++++++++++++++++++++++++++++++++++++++++++++---- fs/ext4/super.c | 1 + 3 files changed, 307 insertions(+), 24 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1194,6 +1194,7 @@ struct ext4_sb_info {struct block_device *journal_bdev;struct mutex s_snapshot_mutex;/* protects 2 fields below: */ struct inode *s_active_snapshot;/* [ s_snapshot_mutex ] */ +struct list_head s_snapshot_list;/* [ s_snapshot_mutex ] */ #ifdef CONFIG_JBD2_DEBUG struct timer_list turn_ro_timer;/* For turning read-only (crash simulation) */ wait_queue_head_t ro_wait_queue;/* For people waiting for the fs to go read-only */
fs/ext4/snapshot_ctl.c +305 -24
404 lines not on this page · raw message
fs/ext4/super.c +1 -0
@@ -3543,6 +3543,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)mutex_init (&sbi->s_snapshot_mutex); sbi->s_active_snapshot =NULL ; +INIT_LIST_HEAD (&sbi->s_snapshot_list);/* snapshot files */ needs_recovery = (es->s_last_orphan !=0 || EXT4_HAS_INCOMPAT_FEATURE(sb,
Signature · 1 line
1.7.4.1
PATCH 28/36 ext4: snapshot list - read through to previous snapshot
In reply to [email protected]From: Amir Goldstein <[email protected]>
On snapshot page read, the function ext4_get_block() is called to map the page to a disk block. If the page is not mapped in the snapshot file, the newer snapshots on the list are checked and the oldest found mapping is returned. If the page is not mapped in any of the newer snapshots, a direct mapping to the block device is returned.
--- fs/ext4/snapshot_inode.c | 74 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 73 insertions(+), 1 deletions(-)
fs/ext4/snapshot_inode.c +73 -1
@@ -46,12 +46,62 @@* in which case 'prev_snapshot' is pointed to the previous snapshot * on the list or set to NULL to indicate read through to block device. */ +/* +* In-memory snapshot list manipulation is protected by snapshot_mutex. +* In this function we read the in-memory snapshot list without holding +* snapshot_mutex, because we don't want to slow down snapshot read performance. +* Following is a proof, that even though we don't hold snapshot_mutex here, +* reading the list is safe from races with snapshot list delete and add (take). +* +* Proof of no race with snapshot delete: +* -------------------------------------- +* We get here only when reading from an enabled snapshot or when reading +* through from an enabled snapshot to a newer snapshot. Snapshot delete +* operation is only allowed for a disabled snapshot, when no older enabled +* snapshot exists (i.e., the deleted snapshot in not 'in-use'). Hence, +* read through is safe from races with snapshot list delete operations. +* +* Proof of no race with snapshot take: +* ------------------------------------ +* Snapshot B take is composed of the following steps: +* ext4_snapshot_create(): +* - Add snapshot B to head of list (active_snapshot is A). +* - Allocate and copy snapshot B initial blocks. +* ext4_snapshot_take(): +* - Freeze FS +* - Clear snapshot A 'active' flag. +* - Set snapshot B 'list'+'active' flags. +* - Set snapshot B as active snapshot (active_snapshot=B). +* - Unfreeze FS +* +* Note that we do not need to rely on correct order of instructions within +* each of the functions above, but we can assume that Freeze FS will provide +* a strong barrier between adding B to list and the ops inside snapshot_take. +* +* When reading from snapshot A during snapshot B take, we have 2 cases: +* 1. is_active(A) is tested before setting active_snapshot=B - +* read through from A to block device. +* 2. is_active(A) is tested after setting active_snapshot=B - +* read through from A to B. +* +* When reading from snapshot B during snapshot B take, we have 2 cases: +* 1. B->flags and B->prev are read before adding B to list +* AND/OR before setting the 'list'+'active' flags - +* access to B denied. +* 2. is_active(B) is tested after setting active_snapshot=B +* AND/OR after setting the 'list'+'active' flags - +* read through from B to block device. +*/ static int ext4_snapshot_get_block_access (struct inode *inode,struct inode **prev_snapshot) {struct ext4_inode_info *ei =EXT4_I (inode);unsigned long flags =ext4_get_snapstate_flags (inode); +struct list_head *prev = ei->i_snaplist.prev; +if (!(flags &1UL <<EXT4_SNAPSTATE_LIST )) +/* snapshot not on the list - read/write access denied */ +return -EPERM ; *prev_snapshot =NULL ; if (ext4_snapshot_is_active(inode) ||
@@ -59,7 +109,23 @@ static int ext4_snapshot_get_block_access(struct inode *inode,/* read through from active snapshot to block device */ return 0 ; -return -EPERM ; +if (prev == &ei->i_snaplist) +/* not on snapshots list? */ +return -EIO ; + +if (prev == &EXT4_SB (inode->i_sb)->s_snapshot_list) +/* active snapshot not found on list? */ +return -EIO ; + +/* read through to prev snapshot on the list */ + ei = list_entry(prev, struct ext4_inode_info, i_snaplist); + *prev_snapshot = &ei->vfs_inode; + +if (!ext4_snapshot_file (*prev_snapshot)) +/* non snapshot file on the list? */ +return -EIO ; + +return 0 ; }#ifdef CONFIG_EXT4_DEBUG
@@ -122,6 +188,7 @@ static int ext4_snapshot_read_through(struct inode *inode, sector_t iblock, map.m_pblk =0 ; map.m_len = bh_result->b_size >> inode->i_blkbits; +get_block: prev_snapshot =NULL ;/* request snapshot file read access */ err =ext4_snapshot_get_block_access (inode, &prev_snapshot);
@@ -134,6 +201,11 @@ static int ext4_snapshot_read_through(struct inode *inode, sector_t iblock, prev_snapshot ? prev_snapshot->i_generation : 0);if (err <0 )return err; +if (!err && prev_snapshot) { +/* hole in snapshot - check again with prev snapshot */ + inode = prev_snapshot; + goto get_block; + }if (!err)/* hole in active snapshot - read though to block device */ return 0 ;
Signature · 1 line
1.7.4.1
PATCH 29/36 ext4: snapshot race conditions - concurrent COW bitmap operations
In reply to [email protected]From: Amir Goldstein <[email protected]>
Wait for pending COW bitmap creations to complete.
When concurrent tasks try to COW buffers from the same block group for the first time, the first task to reset the COW bitmap cache is elected to create the new COW bitmap block. The rest of the tasks wait (in msleep(1) loop), until the COW bitmap cache is uptodate. The COWing task copies the bitmap block into the new COW bitmap block and updates the COW bitmap cache with the new block number.
--- fs/ext4/snapshot.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 42 insertions(+), 3 deletions(-)
fs/ext4/snapshot.c +42 -3
@@ -248,9 +248,48 @@ ext4_snapshot_read_cow_bitmap(handle_t *handle, struct inode *snapshot, bitmap_blk =ext4_block_bitmap (sb, desc); -ext4_lock_group (sb, block_group); - cow_bitmap_blk = grp->bg_cow_bitmap; -ext4_unlock_group (sb, block_group); +/* +* Handle concurrent COW bitmap operations. +* bg_cow_bitmap has 3 states: +* = 0 - uninitialized (after mount and after snapshot take). +* = bg_block_bitmap - marks pending COW of block bitmap. +* other - location of initialized COW bitmap block. +* +* The first task to access block group after mount or snapshot take, +* will read the uninitialized state, mark pending COW state, initialize +* the COW bitmap block and update COW bitmap cache. Other tasks will +* busy wait until the COW bitmap cache is in initialized state, before +* reading the COW bitmap block. +*/ +do { +ext4_lock_group (sb, block_group); + cow_bitmap_blk = grp->bg_cow_bitmap; +if (cow_bitmap_blk ==0 ) +/* mark pending COW of bitmap block */ + grp->bg_cow_bitmap = bitmap_blk; +ext4_unlock_group (sb, block_group); + +if (cow_bitmap_blk ==0 ) { +snapshot_debug (3 ,"initializing COW bitmap #%u " +"of snapshot (%u)...\n" , + block_group, snapshot->i_generation); +/* sleep 1 tunable delay unit */ +snapshot_test_delay (SNAPTEST_BITMAP ); +break ; + } +if (cow_bitmap_blk == bitmap_blk) { +/* wait for another task to COW bitmap block */ +snapshot_debug_once (2 ,"waiting for pending COW " +"bitmap #%d...\n" , block_group); +/* +* This is an unlikely event that can happen only once +* per block_group/snapshot, so msleep(1) is sufficient +* and there is no need for a wait queue. +*/ +msleep (1 ); + } +/* XXX: Should we fail after N retries? */ + }while (cow_bitmap_blk ==0 || cow_bitmap_blk == bitmap_blk);if (cow_bitmap_blk)return sb_bread (sb, cow_bitmap_blk);
Signature · 1 line
1.7.4.1
PATCH 30/36 ext4: snapshot race conditions - concurrent COW operations
In reply to [email protected]From: Amir Goldstein <[email protected]>
Wait for pending COW operations to complete.
When concurrent tasks try to COW the same buffer, the task that takes the active snapshot i_data_sem is elected as the the COWing task. The COWing task allocates a new snapshot block and creates a buffer cache entry with ref_count=1 for that new block. It then locks the new buffer and marks it with the buffer_new flag. The rest of the tasks wait (in msleep(1) loop), until the buffer_new flag is cleared. The COWing task copies the source buffer into the 'new' buffer, unlocks it, clears the new_buffer flag and drops its reference count. On active snapshot readpage, the buffer cache is checked. If a 'new' buffer entry is found, the reader task waits until the buffer_new flag is cleared and then copies the 'new' buffer directly into the snapshot file page.
The sleep loop method was copied from LVM snapshot code, which does the same thing to deal with these (rare) races without wait queues.
--- fs/ext4/inode.c | 26 ++++++++++++++++++ fs/ext4/snapshot.c | 11 ++++++++ fs/ext4/snapshot.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_inode.c | 40 ++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 0 deletions(-)
fs/ext4/inode.c +26 -0
@@ -1049,6 +1049,7 @@ static int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,int depth;int count =0 ;ext4_fsblk_t first_block =0 ; +struct buffer_head *sbh =NULL ;trace_ext4_ind_map_blocks_enter (inode, map->m_lblk, map->m_len, flags);J_ASSERT (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )));
@@ -1155,6 +1156,25 @@ static int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,if (err) goto cleanup; +if (SNAPMAP_ISCOW (flags)) { +/* +* COWing block or creating COW bitmap. +* we now have exclusive access to the COW destination block +* and we are about to create the snapshot block mapping +* and make it public. +* grab the buffer cache entry and mark it new +* to indicate a pending COW operation. +* the refcount for the buffer cache will be released +* when the COW operation is either completed or canceled. +*/ + sbh =sb_getblk (inode->i_sb,le32_to_cpu (chain[depth-1 ].key)); +if (!sbh) { + err = -EIO ; + goto cleanup; + } +ext4_snapshot_start_pending_cow (sbh); + } +if (map->m_flags &EXT4_MAP_REMAP ) { map->m_len = count;/* move old block to snapshot */
@@ -1198,6 +1218,12 @@ got_it:/* Clean up and exit */ partial = chain + depth -1 ;/* the whole chain */ cleanup: +/* cancel pending COW operation on failure to alloc snapshot block */ +if (SNAPMAP_ISCOW (flags)) { +if (err <0 && sbh) +ext4_snapshot_end_pending_cow (sbh); +brelse (sbh); + }while (partial > chain) {BUFFER_TRACE (partial->bh,"call brelse" );brelse (partial->bh);
fs/ext4/snapshot.c +11 -0
@@ -115,6 +115,8 @@ ext4_snapshot_complete_cow(handle_t *handle, struct inode *snapshot,if (sync)sync_dirty_buffer (sbh); out: +/* COW operation is complete */ +ext4_snapshot_end_pending_cow (sbh);return err; }
@@ -688,6 +690,12 @@ int ext4_snapshot_test_and_cow(const char *where, handle_t *handle,* we allocated this block - * copy block data to snapshot and complete COW operation */ +snapshot_debug (3 ,"COWing block [%llu/%llu] of snapshot " +"(%u)...\n" , +SNAPSHOT_BLOCK_TUPLE (block), + active_snapshot->i_generation); +/* sleep 1 tunable delay unit */ +snapshot_test_delay (SNAPTEST_COW ); err =ext4_snapshot_copy_buffer_cow (handle, active_snapshot, sbh, bh);if (err)
@@ -700,6 +708,9 @@ int ext4_snapshot_test_and_cow(const char *where, handle_t *handle,trace_cow_inc (handle, copied); test_pending_cow: +if (sbh) +/* wait for pending COW to complete */ +ext4_snapshot_test_pending_cow (sbh, block); cowed:/* mark the buffer COWed in the current transaction */
fs/ext4/snapshot.h +64 -0
70 lines not on this page · raw message
fs/ext4/snapshot_inode.c +40 -0
@@ -183,6 +183,7 @@ static int ext4_snapshot_read_through(struct inode *inode, sector_t iblock,int err;struct ext4_map_blocks map;struct inode *prev_snapshot; +struct buffer_head *sbh =NULL ; map.m_lblk = iblock; map.m_pblk =0 ;
@@ -214,6 +215,45 @@ get_block: bh_result->b_state = (bh_result->b_state & ~EXT4_MAP_FLAGS ) | map.m_flags; +/* +* On read of active snapshot, a mapped block may belong to a non +* completed COW operation. Use the buffer cache to test this +* condition. if (bh_result->b_blocknr == SNAPSHOT_BLOCK(iblock)), +* then this is either read through to block device or moved block. +* Either way, it is not a COWed block, so it cannot be pending COW. +*/ +if (ext4_snapshot_is_active (inode) && + bh_result->b_blocknr !=SNAPSHOT_BLOCK (iblock)) + sbh =sb_find_get_block (inode->i_sb, bh_result->b_blocknr); +if (!sbh) +return 0 ; +/* wait for pending COW to complete */ +ext4_snapshot_test_pending_cow (sbh,SNAPSHOT_BLOCK (iblock)); +lock_buffer (sbh); +if (buffer_uptodate (sbh)) { +/* +* Avoid disk I/O and copy out snapshot page directly +* from block device page when possible. +*/ +BUG_ON (!sbh->b_page); +BUG_ON (!bh_result->b_page); +lock_buffer (bh_result); +copy_highpage (bh_result->b_page, sbh->b_page); +set_buffer_uptodate (bh_result); +unlock_buffer (bh_result); + }else if (buffer_dirty (sbh)) { +/* +* If snapshot data buffer is dirty (just been COWed), +* then it is not safe to read it from disk yet. +* We shouldn't get here because snapshot data buffer +* only becomes dirty during COW and because we waited +* for pending COW to complete, which means that a +* dirty snapshot data buffer should be uptodate. +*/ +WARN_ON (1 ); + } +unlock_buffer (sbh); +brelse (sbh);return 0 ; }
Signature · 1 line
1.7.4.1
PATCH 31/36 ext4: snapshot race conditions - tracked reads
In reply to [email protected]From: Amir Goldstein <[email protected]>
Wait for pending read I/O requests to complete.
When a snapshot file readpage reads through to the block device, the reading task increments the block tracked readers count. Upon completion of the async read I/O request of the snapshot page, the tracked readers count is decremented.
When a task is COWing a block with non-zero tracked readers count, that task has to wait (in msleep(1) loop), until the block's tracked readers count drops to zero, before the COW operation is completed. After a pending COW operation has started, reader tasks have to wait (again, in msleep(1) loop), until the pending COW operation is completed, so the COWing task cannot be starved by reader tasks. The sleep loop method was copied from LVM snapshot code, which does the same thing to deal with these (rare) races without wait queues.
--- fs/ext4/ext4.h | 6 ++ fs/ext4/snapshot.c | 17 +++++ fs/ext4/snapshot.h | 76 ++++++++++++++++++++++ fs/ext4/snapshot_buffer.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_inode.c | 24 +++++++ 5 files changed, 278 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +6 -0
@@ -2238,12 +2238,18 @@ enum ext4_state_bits {* now used by snapshot to do mow */ BH_Partial_Write,/* Buffer should be uptodate before write */ + BH_Tracked_Read,/* Buffer read I/O is being tracked, +* to serialize write I/O to block device. +* that is, don't write over this block +* until I finished reading it. +*/ }; BUFFER_FNS(Uninit, uninit) TAS_BUFFER_FNS(Uninit, uninit) BUFFER_FNS(Remap, remap) BUFFER_FNS(Partial_Write, partial_write) +BUFFER_FNS (Tracked_Read, tracked_read)/* * Add new method to test wether block and inode bitmaps are properly
fs/ext4/snapshot.c +17 -0
@@ -107,6 +107,23 @@ ext4_snapshot_complete_cow(handle_t *handle, struct inode *snapshot, {int err =0 ; +/* wait for completion of tracked reads before completing COW */ +while (bh &&buffer_tracked_readers_count (bh) >0 ) { +snapshot_debug_once (2 ,"waiting for tracked reads: " +"block = [%llu/%llu], " +"tracked_readers_count = %d...\n" , +SNAPSHOT_BLOCK_TUPLE (bh->b_blocknr), +buffer_tracked_readers_count (bh)); +/* +* Quote from LVM snapshot pending_complete() function: +* "Check for conflicting reads. This is extremely improbable, +* so msleep(1) is sufficient and there is no need for a wait +* queue." (drivers/md/dm-snap.c). +*/ +msleep (1 ); +/* XXX: Should we fail after N retries? */ + } +unlock_buffer (sbh); err =ext4_jbd2_file_inode (handle, snapshot);if (err)
fs/ext4/snapshot.h +76 -0
82 lines not on this page · raw message
fs/ext4/snapshot_buffer.c +155 -0
173 lines not on this page · raw message
fs/ext4/snapshot_inode.c +24 -0
@@ -195,11 +195,35 @@ get_block: err =ext4_snapshot_get_block_access (inode, &prev_snapshot);if (err <0 )return err; +if (!prev_snapshot) { +/* +* Possible read through to block device. +* Start tracked read before checking if block is mapped to +* avoid race condition with COW that maps the block after +* we checked if the block is mapped. If we find that the +* block is mapped, we will cancel the tracked read before +* returning from this function. +*/ +map_bh (bh_result, inode->i_sb,SNAPSHOT_BLOCK (iblock)); + err =start_buffer_tracked_read (bh_result); +if (err <0 ) { +snapshot_debug (1 , +"snapshot (%u) failed to start " +"tracked read on block (%lld) " +"(err=%d)\n" , inode->i_generation, + (long long )bh_result->b_blocknr, err); +return err; + } + } err =ext4_map_blocks (NULL , inode, &map,0 );snapshot_debug (4 ,"ext4_snapshot_read_through(%lld): block = " "(%lld), err = %d\n prev_snapshot = %u" , (long long )iblock, map.m_pblk, err, prev_snapshot ? prev_snapshot->i_generation :0 ); +/* if it's not a hole - cancel tracked read before we deadlock +* on pending COW */ +if (err &&buffer_tracked_read (bh_result)) +cancel_buffer_tracked_read (bh_result);if (err <0 )return err;if (!err && prev_snapshot) {
Signature · 1 line
1.7.4.1
PATCH 32/36 ext4: snapshot exclude - the exclude bitmap
In reply to [email protected]From: Amir Goldstein <[email protected]>
Mark all snapshot blocks excluded from COW (i.e., mark that they do not need to be COWed). The excluded blocks appear as not allocated inside the snapshot image (no snapshots of snapshot files). Excluding snapshot file blocks is essential for efficient cleanup of deleted snapshot files.
Excluding blocks is done by setting their bit in the exclude bitmap. There is one exclude bitmap block per block group, which is allocated on mkfs when setting the exclude_bitmap feature. The exclude bitmap location is stored in the group descriptor.
The exclude_bitmap feature is backward compatible, but online resize support with exclude_bitmap was not yet implemented.
--- fs/ext4/balloc.c | 107 ++++++++++++++++++++++++++++++++++++ fs/ext4/ext4.h | 12 ++++- fs/ext4/mballoc.c | 69 +++++++++++++++++++++++ fs/ext4/resize.c | 6 ++ fs/ext4/snapshot.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot.h | 28 ++++++++++ fs/ext4/snapshot_ctl.c | 7 +++ fs/ext4/snapshot_inode.c | 11 ++++ fs/ext4/super.c | 35 ++++++++++++- 9 files changed, 408 insertions(+), 3 deletions(-)
fs/ext4/balloc.c +107 -0
@@ -65,6 +65,11 @@ static int ext4_group_used_meta_blocks(struct super_block *sb,/* block bitmap, inode bitmap, and inode table blocks */ int used_blocks = sbi->s_itb_per_group +2 ; +if (EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) +/* exclude bitmap */ + used_blocks +=1 ; +if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) {if (!ext4_block_in_group (sb,ext4_block_bitmap (sb, gdp), block_group))
@@ -157,6 +162,14 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, tmp =ext4_block_bitmap (sb, gdp);if (!flex_bg ||ext4_block_in_group (sb, tmp, block_group))ext4_set_bit (tmp - start, bh->b_data); +if (EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) { + tmp =ext4_exclude_bitmap (sb, gdp); +if (!flex_bg || +ext4_block_in_group (sb, tmp, block_group)) +ext4_set_bit (tmp - start, bh->b_data); + } + tmp =ext4_inode_bitmap (sb, gdp);if (!flex_bg ||ext4_block_in_group (sb, tmp, block_group))ext4_set_bit (tmp - start, bh->b_data);
@@ -361,6 +374,100 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)return bh; } +/* Initializes an uninitialized exclude bitmap if given, and returns 0 */ +unsigned ext4_init_exclude_bitmap (struct super_block *sb, +struct buffer_head *bh, +ext4_group_t block_group, +struct ext4_group_desc *gdp) +{ +if (!bh) +/* we can return no. of blocks in exclude bitmap */ +return 0 ; + +J_ASSERT_BH (bh,buffer_locked (bh)); +memset (bh->b_data,0 , sb->s_blocksize); +return 0 ; +} + +/** +* read_exclude_bitmap() +* @sb: super block +* @block_group: given block group +* +* Read the exclude bitmap for a given block_group +* +* Return buffer_head on success or NULL in case of failure. +*/ +struct buffer_head * +ext4_read_exclude_bitmap (struct super_block *sb,ext4_group_t block_group) +{ +struct ext4_group_desc *desc; +struct buffer_head *bh =NULL ; +ext4_fsblk_t bitmap_blk; + + desc =ext4_get_group_desc (sb, block_group,NULL ); +if (!desc) +return NULL ; + bitmap_blk =ext4_exclude_bitmap (sb, desc); +if (!bitmap_blk) +return NULL ; + bh =sb_getblk (sb, bitmap_blk); +if (unlikely (!bh)) { +ext4_error (sb,"Cannot read exclude bitmap - " +"block_group = %d, exclude_bitmap = %llu" , + block_group, bitmap_blk); +return NULL ; + } + +if (bitmap_uptodate (bh)) +return bh; + +lock_buffer (bh); +if (bitmap_uptodate (bh)) { +unlock_buffer (bh); +return bh; + } + +ext4_lock_group (sb, block_group); +if (desc->bg_flags &cpu_to_le16 (EXT4_BG_EXCLUDE_UNINIT )) { +ext4_init_exclude_bitmap (sb, bh, block_group, desc); +set_bitmap_uptodate (bh); +set_buffer_uptodate (bh); +ext4_unlock_group (sb, block_group); +unlock_buffer (bh); +return bh; + } +ext4_unlock_group (sb, block_group); +if (buffer_uptodate (bh)) { +/* +* if not uninit if bh is uptodate, +* bitmap is also uptodate +*/ +set_bitmap_uptodate (bh); +unlock_buffer (bh); +return bh; + } +/* +* submit the buffer_head for read. We can +* safely mark the bitmap as uptodate now. +* We do it here so the bitmap uptodate bit +* get set with buffer lock held. +*/ +set_bitmap_uptodate (bh); +if (bh_submit_read (bh) <0 ) { +put_bh (bh); +ext4_error (sb,"Cannot read exclude bitmap - " +"block_group = %u, block_bitmap = %llu" , + block_group, bitmap_blk); +return NULL ; + } +/* +* file system mounted not to panic on error, +* continue with corrupt bitmap +*/ +return bh; +} +/** * ext4_has_free_blocks() * @sbi: in-core super block structure.
fs/ext4/ext4.h +10 -2
@@ -269,7 +269,8 @@ struct ext4_group_desc__le16 bg_free_inodes_count_lo;/* Free inodes count */ __le16 bg_used_dirs_count_lo;/* Directories count */ __le16 bg_flags;/* EXT4_BG_flags (INODE_UNINIT, etc) */ -__u32 bg_reserved[2 ];/* Likely block/inode bitmap checksum */ +__le32 bg_exclude_bitmap_lo;/* Exclude bitmap block */ +__u32 bg_reserved[1 ];/* Likely block/inode bitmap checksum */ __le16 bg_itable_unused_lo;/* Unused inodes count */ __le16 bg_checksum;/* crc16(sb_uuid+group+desc) */ __le32 bg_block_bitmap_hi;/* Blocks bitmap block MSB */
@@ -279,7 +280,8 @@ struct ext4_group_desc__le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ __le16 bg_used_dirs_count_hi;/* Directories count MSB */ __le16 bg_itable_unused_hi;/* Unused inodes count MSB */ -__u32 bg_reserved2[3 ]; +__le32 bg_exclude_bitmap_hi;/* Exclude bitmap block MSB */ +__u32 bg_reserved2[2 ]; };/*
@@ -295,6 +297,7 @@ struct flex_groups {#define EXT4_BG_INODE_UNINIT 0x0001/* Inode table/bitmap not in use */ #define EXT4_BG_BLOCK_UNINIT 0x0002/* Block bitmap not in use */ #define EXT4_BG_INODE_ZEROED 0x0004/* On-disk itable initialized to zero */ +#define EXT4_BG_EXCLUDE_UNINIT 0x0008/* Exclude bitmap not in use */ /* * Macro-instructions used to manage group descriptors
@@ -1433,6 +1436,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 +#define EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP 0x0100/* Has exclude bitmap */ #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
@@ -1775,6 +1779,8 @@ extern unsigned ext4_init_block_bitmap(struct super_block *sb, struct ext4_group_desc *desc);#define ext4_free_blocks_after_init (sb, group, desc) \ ext4_init_block_bitmap(sb, NULL, group, desc) +extern struct buffer_head *ext4_read_exclude_bitmap (struct super_block *sb, +unsigned int block_group);/* dir.c */ extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
@@ -1936,6 +1942,8 @@ extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, struct ext4_group_desc *bg);extern ext4_fsblk_t ext4_inode_bitmap (struct super_block *sb,struct ext4_group_desc *bg); +extern ext4_fsblk_t ext4_exclude_bitmap (struct super_block *sb, +struct ext4_group_desc *bg);extern ext4_fsblk_t ext4_inode_table (struct super_block *sb,struct ext4_group_desc *bg); extern __u32 ext4_free_blks_count(struct super_block *sb,
fs/ext4/mballoc.c +69 -0
111 lines not on this page · raw message
fs/ext4/resize.c +6 -0
@@ -753,6 +753,12 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) gdb_num = input->group /EXT4_DESC_PER_BLOCK (sb); gdb_off = input->group %EXT4_DESC_PER_BLOCK (sb); +if (EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) { +ext4_warning (sb,"Can't resize filesystem with exclude bitmap" ); +return -ENOTSUPP ; + } +if (gdb_off ==0 && !EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER )) {ext4_warning (sb,"Can't resize non-sparse filesystem further" );
fs/ext4/snapshot.c +136 -0
176 lines not on this page · raw message
fs/ext4/snapshot.h +28 -0
@@ -341,6 +341,34 @@ static inline int ext4_snapshot_get_delete_access(handle_t *handle,return ext4_snapshot_move (handle, inode, block, pcount,1 ); } +extern int ext4_snapshot_test_and_exclude (const char *where,handle_t *handle, +struct super_block *sb,ext4_fsblk_t block,int maxblocks, +int exclude); + +/* +* ext4_snapshot_exclude_blocks() - exclude snapshot blocks +* +* Called from ext4_snapshot_test_and_{cow,move}() when copying/moving +* blocks to active snapshot. +* +* Return <0 on error. +*/ +#define ext4_snapshot_exclude_blocks (handle, sb, block, count) \ + ext4_snapshot_test_and_exclude(__func__, (handle), (sb), \ + (block), (count), 1) + +/* +* ext4_snapshot_test_excluded() - test that snapshot blocks are excluded +* +* Called from ext4_count_branches() and +* ext4_count_blocks() under snapshot_mutex. +* +* Return <0 on error or if snapshot blocks are not excluded. +*/ +#define ext4_snapshot_test_excluded (inode, block, count) \ + ext4_snapshot_test_and_exclude(__func__, NULL, (inode)->i_sb, \ + (block), (count), 0) +extern void init_ext4_snapshot_cow_cache (void );
fs/ext4/snapshot_ctl.c +7 -0
@@ -886,6 +886,7 @@ int ext4_snapshot_take(struct inode *inode)struct ext4_super_block *es =NULL ;struct buffer_head *es_bh =NULL ;struct buffer_head *sbh =NULL ; +struct buffer_head *exclude_bitmap_bh =NULL ;struct buffer_head *bhs[COPY_INODE_BLOCKS_NUM ] = {NULL };const char *mask =NULL ;struct inode *curr_inode;
@@ -1027,6 +1028,11 @@ copy_inode_blocks:brelse (bhs[COPY_INODE_BITMAP ]); bhs[COPY_INODE_BITMAP ] =sb_bread (sb,ext4_inode_bitmap (sb, desc)); +brelse (exclude_bitmap_bh); + exclude_bitmap_bh =ext4_read_exclude_bitmap (sb, iloc.block_group); +if (exclude_bitmap_bh) +/* mask block bitmap with exclude bitmap */ + mask = exclude_bitmap_bh->b_data; err = -EIO ;for (i =0 ; i <COPY_INODE_BLOCKS_NUM ; i++) {brelse (sbh);
@@ -1134,6 +1140,7 @@ out_unlockfs: inode->i_generation); out_err: +brelse (exclude_bitmap_bh);brelse (es_bh);brelse (sbh);for (i =0 ; i <COPY_INODE_BLOCKS_NUM ; i++)
fs/ext4/snapshot_inode.c +11 -0
@@ -149,6 +149,7 @@ static int ext4_snapshot_get_blockdev_access(struct super_block *sb,unsigned long block_group =SNAPSHOT_BLOCK_GROUP (bh->b_blocknr);ext4_grpblk_t bit =SNAPSHOT_BLOCK_GROUP_OFFSET (bh->b_blocknr);struct buffer_head *bitmap_bh; +struct buffer_head *exclude_bitmap_bh =NULL ;int err =0 ;if (PageReadahead (bh->b_page))
@@ -166,6 +167,16 @@ static int ext4_snapshot_get_blockdev_access(struct super_block *sb,return -EIO ; } + exclude_bitmap_bh =ext4_read_exclude_bitmap (sb, block_group); +if (exclude_bitmap_bh && +ext4_test_bit (bit, exclude_bitmap_bh->b_data)) { +snapshot_debug (2 ,"warning: attempt to read through to " +"excluded block [%d/%lu] - read ahead?\n" , + bit, block_group); + err = -EIO ; + } + +brelse (exclude_bitmap_bh);brelse (bitmap_bh);return err; }
fs/ext4/super.c +34 -1
@@ -126,6 +126,18 @@ ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); } +ext4_fsblk_t ext4_exclude_bitmap (struct super_block *sb, +struct ext4_group_desc *bg) +{ +if (!EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) +return 0 ; + +return le32_to_cpu (bg->bg_exclude_bitmap_lo) | + (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? + (ext4_fsblk_t )le32_to_cpu (bg->bg_exclude_bitmap_hi) <<32 :0 ); +} +ext4_fsblk_t ext4_inode_table (struct super_block *sb,struct ext4_group_desc *bg) {
@@ -2067,6 +2079,7 @@ static int ext4_check_descriptors(struct super_block *sb,ext4_fsblk_t block_bitmap;ext4_fsblk_t inode_bitmap;ext4_fsblk_t inode_table; +ext4_fsblk_t exclude_bitmap;int flexbg_flag =0 ;ext4_group_t i, grp = sbi->s_groups_count;
@@ -2110,10 +2123,23 @@ static int ext4_check_descriptors(struct super_block *sb, "(block %llu)!", i, inode_table);return 0 ; } +if (EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) { + exclude_bitmap =ext4_exclude_bitmap (sb, gdp); +if (exclude_bitmap < first_block || + exclude_bitmap > last_block) { +ext4_msg (sb,KERN_ERR , +"ext4_check_descriptors: " +"Exclude bitmap for group %u " +"not in group (block %llu)!" , + i, exclude_bitmap); +return 0 ; + } + }ext4_lock_group (sb, i);if (!ext4_group_desc_csum_verify (sbi, i, gdp)) {ext4_msg (sb,KERN_ERR ,"ext4_check_descriptors: " -"Checksum for group %u failed (%u!=%u)" , +"Checksum for group %u failed (%x!=%x)" , i,le16_to_cpu (ext4_group_desc_csum (sbi, i, gdp)),le16_to_cpu (gdp->bg_checksum));if (!(sb->s_flags &MS_RDONLY )) {
@@ -2653,6 +2679,13 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly) "features: meta_bg, 64bit");return 0 ; } +if (!EXT4_HAS_COMPAT_FEATURE (sb, +EXT4_FEATURE_COMPAT_EXCLUDE_BITMAP )) { +ext4_msg (sb,KERN_ERR , +"exclude_bitmap feature is required " +"for snapshots" ); +return 0 ; + }if (EXT4_TEST_FLAGS (sb,EXT4_FLAGS_IS_SNAPSHOT )) {ext4_msg (sb,KERN_ERR , "A snapshot image must be mounted read-only. "
Signature · 1 line
1.7.4.1
PATCH 33/36 ext4: snapshot cleanup
In reply to [email protected]From: Amir Goldstein <[email protected]>
Cleanup snapshots list and reclaim unused blocks of deleted snapshots. Oldest snapshot can be removed from list and its blocks can be freed. Non-oldest snapshots have to be shrunk and merged before they can be removed from the list. All snapshot blocks must be excluded in order to properly shrink/merge deleted old snapshots.
--- fs/ext4/ext4.h | 16 ++++++++ fs/ext4/inode.c | 19 ++++++---- fs/ext4/snapshot_ctl.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 118 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +16 -0
@@ -1737,6 +1737,12 @@ struct ext4_features {struct completion f_kobj_unregister; }; +typedef struct { +__le32 *p; +__le32 key; +struct buffer_head *bh; +}Indirect ; +/* * Function prototypes */
@@ -1878,6 +1884,16 @@ extern void ext4_da_update_reserve_space(struct inode *inode,/* snapshot_inode.c */ extern int ext4_snapshot_readpage (struct file *file,struct page *page); +extern int ext4_block_to_path (struct inode *inode, +ext4_lblk_t i_block, +ext4_lblk_t offsets[4 ],int *boundary); +extern Indirect *ext4_get_branch (struct inode *inode,int depth, +ext4_lblk_t *offsets, +Indirect chain[4 ],int *err); +extern void ext4_free_branches (handle_t *handle,struct inode *inode, +struct buffer_head *parent_bh, +__le32 *first,__le32 *last, +int depth);/* ioctl.c */ extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long );
fs/ext4/inode.c +11 -8
@@ -176,6 +176,14 @@ int ext4_truncate_restart_trans(handle_t *handle, struct inode *inode,*/ BUG_ON (EXT4_JOURNAL (inode) ==NULL );jbd_debug (2 ,"restarting handle %p\n" , handle); +/* +* Snapshot shrink/merge/clean do not take i_data_sem, so we cannot +* release it here. Luckily, snapshot files are not writable, +* so deadlock with ext4_map_blocks on writepage is impossible. +* Snapshot files also don't have preallocations. +*/ +if (ext4_snapshot_file (inode)) +return ext4_journal_restart (handle, nblocks);up_write (&EXT4_I (inode)->i_data_sem); ret =ext4_journal_restart (handle, nblocks);down_write (&EXT4_I (inode)->i_data_sem);
@@ -281,11 +289,6 @@ no_delete:ext4_clear_inode (inode);/* We must guarantee clearing of inode... */ } -typedef struct { -__le32 *p; -__le32 key; -struct buffer_head *bh; -}Indirect ;static inline void add_chain (Indirect *p,struct buffer_head *bh,__le32 *v) {
@@ -324,7 +327,7 @@ static inline void add_chain(Indirect *p, struct buffer_head *bh, __le32 *v)* get there at all. */ -static int ext4_block_to_path (struct inode *inode, +int ext4_block_to_path (struct inode *inode,ext4_lblk_t i_block,ext4_lblk_t offsets[4 ],int *boundary) {
@@ -440,7 +443,7 @@ static int __ext4_check_blockref(const char *function, unsigned int line,* Need to be called with * down_read(&EXT4_I(inode)->i_data_sem) */ -static Indirect *ext4_get_branch (struct inode *inode,int depth, +Indirect *ext4_get_branch (struct inode *inode,int depth,ext4_lblk_t *offsets,Indirect chain[4 ],int *err) {
@@ -4679,7 +4682,7 @@ static void ext4_free_data(handle_t *handle, struct inode *inode,* stored as little-endian 32-bit) and updating @inode->i_blocks * appropriately. */ -static void ext4_free_branches (handle_t *handle,struct inode *inode, +void ext4_free_branches (handle_t *handle,struct inode *inode,struct buffer_head *parent_bh,__le32 *first,__le32 *last,int depth) {
fs/ext4/snapshot_ctl.c +91 -3
124 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 34/36 ext4: snapshot cleanup - shrink deleted snapshots
In reply to [email protected]From: Amir Goldstein <[email protected]>
Free blocks of deleted snapshots, which are not in use by an older non-deleted snapshot. Shrinking helps reclaiming disk space while older snapshots are currently in use (enabled).
We modify the indirect inode truncate helper functions so that they can be used by the snapshot cleanup functions to free blocks selectively according to a COW bitmap buffer.
--- fs/ext4/ext4.h | 10 ++ fs/ext4/inode.c | 51 ++++++++--- fs/ext4/snapshot.h | 5 + fs/ext4/snapshot_ctl.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_inode.c | 220 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 504 insertions(+), 14 deletions(-)
fs/ext4/ext4.h +10 -0
@@ -1894,6 +1894,16 @@ extern void ext4_free_branches(handle_t *handle, struct inode *inode,struct buffer_head *parent_bh, __le32 *first, __le32 *last, int depth); +extern void ext4_free_data_cow (handle_t *handle,struct inode *inode, +struct buffer_head *this_bh, +__le32 *first,__le32 *last, +const char *bitmap,int bit, +int *pfreed_blocks); + +#define ext4_free_data (handle, inode, bh, first, last) \ + ext4_free_data_cow(handle, inode, bh, first, last, \ + NULL, 0, NULL) +/* ioctl.c */ extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long );
fs/ext4/inode.c +37 -14
89 lines not on this page · raw message
fs/ext4/snapshot.h +5 -0
@@ -401,6 +401,11 @@ static inline void exit_ext4_snapshot(void) { } +/* snapshot_inode.c */ +extern int ext4_snapshot_shrink_blocks (handle_t *handle,struct inode *inode, +sector_t iblock,unsigned long maxblocks, +struct buffer_head *cow_bh, +int shrink,int *pmapped);/* tests if @inode is a snapshot file */ static inline int ext4_snapshot_file (struct inode *inode)
fs/ext4/snapshot_ctl.c +232 -0
244 lines not on this page · raw message
fs/ext4/snapshot_inode.c +220 -0
226 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 35/36 ext4: snapshot cleanup - merge shrunk snapshots
In reply to [email protected]From: Amir Goldstein <[email protected]>
Move blocks of deleted and shrunk snapshots to an older non-deleted and disabled snapshot. Merging helps removing snapshots from list while older snapshots are not currently in use (disabled).
--- fs/ext4/snapshot.h | 3 + fs/ext4/snapshot_ctl.c | 113 +++++++++++++++++ fs/ext4/snapshot_inode.c | 307 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 423 insertions(+), 0 deletions(-)
fs/ext4/snapshot.h +3 -0
@@ -406,6 +406,9 @@ extern int ext4_snapshot_shrink_blocks(handle_t *handle, struct inode *inode, sector_t iblock, unsigned long maxblocks, struct buffer_head *cow_bh, int shrink, int *pmapped); +extern int ext4_snapshot_merge_blocks (handle_t *handle, +struct inode *src,struct inode *dst, +sector_t iblock,unsigned long maxblocks);/* tests if @inode is a snapshot file */ static inline int ext4_snapshot_file (struct inode *inode)
fs/ext4/snapshot_ctl.c +113 -0
131 lines not on this page · raw message
fs/ext4/snapshot_inode.c +307 -0
313 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 36/36 ext4: snapshot rocompat - enable rw mount
In reply to [email protected]From: Amir Goldstein <[email protected]>
Enable readwrite mount of filesystem with has_snapshot feature only if ext4 was compiled with snapshot support.
--- fs/ext4/ext4.h | 1 + fs/ext4/super.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1483,6 +1483,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) EXT4_FEATURE_INCOMPAT_FLEX_BG)#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT| \ EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
fs/ext4/super.c +10 -0
@@ -2693,6 +2693,16 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly) "must run fsck -xy to make it writable.");return 0 ; } + }else if (EXT4_HAS_RO_COMPAT_FEATURE (sb, +EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT )) { +/* +* We get here when CONFIG_EXT4_FS_SNAPSHOT is not defined +* so EXT4_SNAPSHOTS(sb) is defined to (0) +*/ +ext4_msg (sb,KERN_ERR , +"Filesystem with has_snapshot feature cannot be " +"mounted RDWR without CONFIG_EXT4_FS_SNAPSHOT" ); +return 0 ; }return 1 ; }
Signature · 1 line
1.7.4.1
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new dm_multisnap code. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
So I, for myself, and I believe there are others, would like to see some benchmark numbers and comparison (both, features and performance) with at least new dm-multisnap code and probably btrfs and plain ext4 as well.
Thanks!
-Lukas
Quoted 81 lines · On Tue, 7 Jun 2011, [email protected] wrote:
Hi All,
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.Thanks,
Amir.[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental)
[PATCH v1 02/36] ext4: snapshot debugging support
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks
[PATCH v1 04/36] ext4: snapshot hooks - block bitmap access
[PATCH v1 05/36] ext4: snapshot hooks - delete blocks
[PATCH v1 06/36] ext4: snapshot hooks - move data blocks
[PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocks [PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TB [PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshot [PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot
[PATCH v1 20/36] ext4: snapshot control - fix new snapshot
[PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshot [PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implementjournal_release_buffer()[PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid injournal_head[PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits [PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshot [PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads [PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshots [PATCH v1 36/36] ext4: snapshot rocompat - enable rw mountfs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++ fs/ext4/ext4.h | 188 ++++- fs/ext4/ext4_jbd2.c | 162 ++++- fs/ext4/ext4_jbd2.h | 266 ++++++- fs/ext4/extents.c | 157 ++++- fs/ext4/file.c | 11 +- fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++ fs/ext4/mballoc.c | 161 ++++- fs/ext4/move_extent.c | 3 +- fs/ext4/namei.c | 9 + fs/ext4/resize.c | 19 +- fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++ fs/ext4/snapshot.h | 690 ++++++++++++++++ fs/ext4/snapshot_buffer.c | 393 +++++++++ fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)
Quoted 11 lines · Lukas Czerner
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
Hi Lukas,
Thank you for pointing out the marketing aspect.
I must admit that my user-case rather speaks for itself. CTERA develops a NAS device which is specialized for backing up local networks and snapshots gives the NAS a time dimension without paying for it in disk space and performance.
The reason for not going with btrfs 3 years ago is clear. So why not go with it now instead of moving forward to ext4 with snapshots?
Part of the answer lies in the possibility to run fsck -x, which gets rid of the snapshots in the case of fs corruption and gets you back to good old stable and consistent ext4.
Quoted 9 lines
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new
dm_multisnapcode. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?
Quoted 5 lines
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
Ehm.. I did present this benchmark on LSF:
http://global.phoronix-test-suite.com/index.php?k=profile&u=amir73il-4632-11284-26560
unless you snoozed ;-)
it shows performance vs. ext4 w/o snapshots and with snapshots and while taking snapshots.
I did not compare with btrfs, but I bet there are ext4 vs. btrfs benchmarks out there.
dm-multisnap is better than dm-snap only when it comes to overhead per snapshot. it still copies every written block, which is far from being the case in ext4 snapshots.
Quoted 93 lines
So I, for myself, and I believe there are others, would like to see some benchmark numbers and comparison (both, features and performance) with at least new dm-multisnap code and probably btrfs and plain ext4 as well.
Thanks!
-LukasQuoted 73 lines · On Tue, 7 Jun 2011, [email protected] wrote:
Hi All,
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.Thanks,
Amir.[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental)
[PATCH v1 02/36] ext4: snapshot debugging support
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks
[PATCH v1 04/36] ext4: snapshot hooks - block bitmap access
[PATCH v1 05/36] ext4: snapshot hooks - delete blocks
[PATCH v1 06/36] ext4: snapshot hooks - move data blocks
[PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocks [PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TB [PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshot [PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot
[PATCH v1 20/36] ext4: snapshot control - fix new snapshot
[PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshot [PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implementjournal_release_buffer()[PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid injournal_head[PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits [PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshot [PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads [PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshots [PATCH v1 36/36] ext4: snapshot rocompat - enable rw mountfs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++fs/ext4/ext4.h | 188 ++++-
fs/ext4/ext4_jbd2.c | 162 ++++-
fs/ext4/ext4_jbd2.h | 266 ++++++-
fs/ext4/extents.c | 157 ++++-
fs/ext4/file.c | 11 +-fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++fs/ext4/mballoc.c | 161 ++++-
fs/ext4/move_extent.c | 3 +-
fs/ext4/namei.c | 9 +
fs/ext4/resize.c | 19 +-
fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++fs/ext4/snapshot.h| 690 ++++++++++++++++fs/ext4/snapshot_buffer.c| 393 +++++++++
fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++Quoted 8 lines
fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)
Quoted 2 lines
--
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 22 lines · Amir G.
Quoted 11 lines · Lukas Czerner
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
Hi Lukas,
Thank you for pointing out the marketing aspect.
I must admit that my user-case rather speaks for itself. CTERA develops a NAS device which is specialized for backing up local networks and snapshots gives the NAS a time dimension without paying for it in disk space and performance.
Quoted 6 lines
The reason for not going with btrfs 3 years ago is clear. So why not go with it now instead of moving forward to ext4 with snapshots?
Part of the answer lies in the possibility to run fsck -x, which gets rid of the snapshots in the case of fs corruption and gets you back to good old stable and consistent ext4.
But that is not even a real reason, is it ? When you need snapshots, well, then you just need it and do no want to get rid of it. When fs corruption appears, then it's bad in any case and the fsck should be able to more or less fix it.
So you're saying that when corruption appears, then you *have to* blast all snapshots ? I am not sure how btrfs is going to deal with it, but it does seem like an advantage at all, why are you presenting it as such ?
Quoted 16 lines
Quoted 10 lines
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new
dm_multisnapcode. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?Quoted 5 lines
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
Quoted 6 lines
Ehm.. I did present this benchmark on LSF:
http://global.phoronix-test-suite.com/index.php?k=profile&u=amir73il-4632-11284-26560unless you snoozed ;-)
it shows performance vs. ext4 w/o snapshots and with snapshots and while taking snapshots.
I believe that you just missed the fact that not everyone has attended LSF and your lightning talk, but that's ok.
It seems to me that random writes are usually faster with you snapshot code regardless whether you use snapshots or not. Is that because of non snapshot related changes you've made ?
Also random reads seems to be slower with snapshots, is suspect that this is because of read through, so the reason for the slowdown that it was CPU bound ? I do not see any CPU utilization data.
The postmark results seems quite odd, it is actually a lot faster with one snapshot and a lot slower with multiple snapshots, do you have an idea what is going on ?
Quoted 5 lines
I did not compare with btrfs, but I bet there are ext4 vs. btrfs benchmarks out there.
dm-multisnap is better than dm-snap only when it comes to overhead per snapshot. it still copies every written block, which is far from being the case in ext4 snapshots.
Nevertheless, I still have not seen any comparison with other snapshotting possibilities we have. Note that ext4 to btrfs comparison is not enough, because we do not know what is the difference between the difference of ext4 with/without snapshots and btrfs with/without snapshots. The reason for this is that btrfs performance is very likely to scale up, but ext4 is pretty much done in that matter and I do not expect any huge performance leaps in the future.
Also, rejecting dm-multisnap based on this statement is not enough, show us some numbers.
I believe that it is not very convenient for you, because this feature support your business case and you do not necessarily want to find out that there might be a better way, especially after the work you have done already.
So it might be unpleasant for you that people ask questions and delaying the inclusion of ext4 snapshots. But what you see as obstacles people are throwing at you is really just caution, especially when it comes to ext4 which is seen as a simple, stable, reliable and predictable linux filesystem, but I bet you understand.
And one last note, I also think that the snapshot format change in the future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
Thanks!
-Lukas
Quoted 9 lines
Quoted 9 lines
So I, for myself, and I believe there are others, would like to see some benchmark numbers and comparison (both, features and performance) with at least new dm-multisnap code and probably btrfs and plain ext4 as well.
Thanks!
-Lukas
Quoted 31 lines · Lukas Czerner
Quoted 22 lines · Amir G.
Quoted 11 lines · Lukas Czerner
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
Hi Lukas,
Thank you for pointing out the marketing aspect.
I must admit that my user-case rather speaks for itself. CTERA develops a NAS device which is specialized for backing up local networks and snapshots gives the NAS a time dimension without paying for it in disk space and performance.
Quoted 6 lines
The reason for not going with btrfs 3 years ago is clear. So why not go with it now instead of moving forward to ext4 with snapshots?
Part of the answer lies in the possibility to run fsck -x, which gets rid of the snapshots in the case of fs corruption and gets you back to good old stable and consistent ext4.
Quoted 9 lines
But that is not even a real reason, is it ? When you need snapshots, well, then you just need it and do no want to get rid of it. When fs corruption appears, then it's bad in any case and the fsck should be able to more or less fix it.
So you're saying that when corruption appears, then you *have to* blast all snapshots ? I am not sure how btrfs is going to deal with it, but it does seem like an advantage at all, why are you presenting it as such ?
Hi Lukas,
First of all, thank you for being strict with me.
I admit to having lousy marketing skills...
The market I am targeting are the sys admins who are very cautious about their 'data' and are reluctant therefor to migrate from ext3 to ext4, not to speak of btrfs.
To this market I say, you can have snapshots of your 'data' on ext4 without risking the proven stability of ext4. The snapshots of the 'data' are not guarantied to be as stable (being a new feature), but because the snapshots are second to 'data' in ext4 snapshots, corrupted snapshots will not risk the 'data'.
During 1 year of next3 in production systems, we found bugs. But none of the bugs corrupted 'data'. All of the bugs which caused file system to contain errors, the errors were restricted to snapshot files and in those worst cases, we could always go to emergency plan B (plan A being fsck -p) and run fsck -x which always solved the problem.
The customer was always consulted before resorting to 'plan B' and was given the chance to copy out 'data' from the snapshots (it was always possible) before we discard them.
Needless to say, the said bugs were fixed and ext4 snapshots will enjoy the stability of next3 and the 'fail safe' nature of the solution, which was proven several times on the field.
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new
dm_multisnapcode. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?Quoted 5 lines
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
Ehm.. I did present this benchmark on LSF:
http://global.phoronix-test-suite.com/index.php?k=profile&u=amir73il-4632-11284-26560
Quoted 6 lines
Quoted 3 lines
unless you snoozed ;-)
it shows performance vs. ext4 w/o snapshots and with snapshots and while taking snapshots.I believe that you just missed the fact that not everyone has attended LSF and your lightning talk, but that's ok.
That's not really OK. I should have posted the results and analysis on my wiki (the results are there).
Quoted 4 lines
It seems to me that random writes are usually faster with you snapshot code regardless whether you use snapshots or not. Is that because of non snapshot related changes you've made ?
Not that I know of.
I can explain why random write onesnap is faster than nosnap and why 1snappermin is faster than onesnap, but I am not sure about nosnap vs. plain ext4.
Quoted 5 lines
Also random reads seems to be slower with snapshots, is suspect that this is because of read through, so the reason for the slowdown that it was CPU bound ? I do not see any CPU utilization data.
Only the 1snappermin is slower.
I suspect it has to do with the fs freezes, but I admin I have not looked into it.
Quoted 4 lines
The postmark results seems quite odd, it is actually a lot faster with one snapshot and a lot slower with multiple snapshots, do you have an idea what is going on ?
The name onesnap is misleading. It should have been existingsnaps.
The important factor is whether or not snapshots are taken during the test. In the 1snappermin case, postmark is the only test that exposes the weak spot of ext4 snapshots performance - deletes/truncates. create file+delete file with existing snapshots has no overhead (no COW). create file+take snapshot+delete file has the overhead of moving the deleted blocks to snapshot.
With regards to speed up of onesnap, postmark is randomizing the file creates/write so it may be a similar effect to random write.
I did not investigate this.
Quoted 14 lines
Quoted 5 lines
I did not compare with btrfs, but I bet there are ext4 vs. btrfs benchmarks out there.
dm-multisnap is better than dm-snap only when it comes to overhead per snapshot. it still copies every written block, which is far from being the case in ext4 snapshots.Nevertheless, I still have not seen any comparison with other snapshotting possibilities we have. Note that ext4 to btrfs comparison is not enough, because we do not know what is the difference between the difference of ext4 with/without snapshots and btrfs with/without snapshots. The reason for this is that btrfs performance is very likely to scale up, but ext4 is pretty much done in that matter and I do not expect any huge performance leaps in the future.
Quoted 2 lines
Also, rejecting dm-multisnap based on this statement is not enough, show us some numbers.
Well, if you come to understand the difference between fs level an dm level snapshots, you will see why i am rejecting dm-multisnap (performance wise only!).
Anyway #1: I have already answered this questions 2 years ago and I think the answers are still valid both for LVM and btrfs:
http://sourceforge.net/apps/mediawiki/next3/index.php?title=FAQ#Why_use_Next3_snapshots_and_not_LVM_snapshots.3F
Anyway #2: I need to give you some numbers ;-)
Quoted 5 lines
I believe that it is not very convenient for you, because this feature support your business case and you do not necessarily want to find out that there might be a better way, especially after the work you have done already.
Your analysis of my motives is correct :-)
The use of the term 'better way' I reject.
I think that ext4/btrfs/LVM snapshots are apples and oranges and hamburgers. The question of whether the world needs ext4 snapshots is perfectly valid, but going back to the food analogy, I think it's a case of "the proof of the pudding is in the eating".
I have no doubt that if ext4 snapshots are merged, many people will use it. And I think that is a good enough (if not the best)
reason for inclusion.
Quoted 7 lines
So it might be unpleasant for you that people ask questions and delaying the inclusion of ext4 snapshots. But what you see as obstacles people are throwing at you is really just caution, especially when it comes to ext4 which is seen as a simple, stable, reliable and predictable linux filesystem, but I bet you understand.
Yes, I understand. As evidence, I posted the "core patches"
to get them reviewed for "safely" and "stability" rather than "functionality". (and that didn't work out well, but I understand that as well).
Quoted 5 lines
And one last note, I also think that the snapshot format change in the future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
What can I say, I understand why it looks bad, but is 64bit code upstream and stable? Hell no! e2fsprogs 64bit is not out yet! There is no reason to call it 'format change'.
It's going to be a new format used only for 64bit fs, which are not even out there yet. And when they are finally out there, they won't have
snapshots until the new format is implemented.
And more important, say I do implement a new 48bit logical offsets file format, so my employer can provide snapshots on
Quoted 1 line
16TB volumes in future releases.
I will not recommend my employer to use this format on <16TB volumes, because there is nothing wrong with staying with the simple and well tested indirect mapped snapshot format in future releases.
Thanks for your time and patience,
Amir.
Quoted 5 lines · Amir G.
Quoted 5 lines
And one last note, I also think that the snapshot format change in the
Quoted 4 lines
future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
Quoted 7 lines
What can I say, I understand why it looks bad, but is 64bit code upstream and stable? Hell no! e2fsprogs 64bit is not out yet! There is no reason to call it 'format change'.
It's going to be a new format used only for 64bit fs, which are not even out there yet. And when they are finally out there, they won't have
snapshots until the new format is implemented.
Well, the on-disk format for 64-bit (48-bit?) ext4 is there & fixed; it's just that there is no released userspace which can properly handle it, right?
I don't anticipate ext4 format changes for >16T, or am I missing something?
-Eric
Quoted 14 lines · Eric Sandeen
Quoted 5 lines · Amir G.
Quoted 5 lines
And one last note, I also think that the snapshot format change in the
Quoted 4 lines
future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
Quoted 7 lines
What can I say, I understand why it looks bad, but is 64bit code upstream and stable? Hell no! e2fsprogs 64bit is not out yet! There is no reason to call it 'format change'.
It's going to be a new format used only for 64bit fs, which are not even out there yet. And when they are finally out there, they won't have
snapshots until the new format is implemented.
Quoted 2 lines
Well, the on-disk format for 64-bit (48-bit?) ext4 is there & fixed; it's just that there is no released userspace which can properly handle it, right?
I don't know, you tell me.
Are there many users out there using 64bit feature, without the proper user space tools?
Quoted 5 lines
I don't anticipate ext4 format changes for >16T, or am I missing something?
-Eric
Argh! I wish I hadn't missed the Monday call (it's
not in a good time for me).
This whole 'format change' has gone out of control
and I find it hard to present my case properly on scattered emails.
The message I am trying to get through is:
There is 32bit snapshot file format, which is implemented and well tested. There is 64bit snapshot file format, which is not implemented yet, so 64bit and snapshot feature are mutually exclusive.
If and when 64bit snapshot file format will be implemented, it will be a new type of extent mapped file (v2) with 48bit logical addresses. Is this a 'format change'? Call it what you will, but it shouldn't affect anything on existing structures. It should only affect the non-existing structure of 64bit snapshot file.
Does this answer your question?
Amir.
Quoted 15 lines · Amir G.
Quoted 14 lines · Eric Sandeen
Quoted 12 lines · Amir G.
Quoted 5 lines
And one last note, I also think that the snapshot format change in the
Quoted 4 lines
future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
What can I say, I understand why it looks bad, but is 64bit code upstream and stable? Hell no! e2fsprogs 64bit is not out yet! There is no reason to call it 'format change'.
It's going to be a new format used only for 64bit fs, which are not even out there yet. And when they are finally out there, they won't have
snapshots until the new format is implemented.
Quoted 6 lines
Quoted 2 lines
Well, the on-disk format for 64-bit (48-bit?) ext4 is there & fixed; it's just that there is no released userspace which can properly handle it, right?
I don't know, you tell me.
Are there many users out there using 64bit feature, without the proper user space tools?
No, but that doesn't mean the disk format has to change when the tools come out... I just don't want to confuse "there are no tools" with "the disk format is unstable" - Andreas et. al. have been using that format for years.
Quoted 10 lines
Quoted 5 lines
I don't anticipate ext4 format changes for >16T, or am I missing something?
-Eric
Argh! I wish I hadn't missed the Monday call (it's
not in a good time for me).
This whole 'format change' has gone out of control
and I find it hard to present my case properly on scattered emails.
Sorry; I may have just misunderstood...
Quoted 11 lines
The message I am trying to get through is:
There is 32bit snapshot file format, which is implemented and well tested. There is 64bit snapshot file format, which is not implemented yet, so 64bit and snapshot feature are mutually exclusive.
If and when 64bit snapshot file format will be implemented, it will be a new type of extent mapped file (v2) with 48bit logical addresses. Is this a 'format change'? Call it what you will, but it shouldn't affect anything on existing structures. It should only affect the non-existing structure of 64bit snapshot file.Does this answer your question?
Yes, I guess I had misunderstood your point; I thought you were implying that ext4's format had to change to support 64-bit, so why not change snapshots along with it....
But you're just saying that you wish to push 32-bit snapshots which only work with certain sizes of ext4 filesystems now, and later you will release a new snapshot format which works with the larger filesystems. Right?
(I don't actually know if we'll ever have 64-bit ext4, though, there are still so many scaling issues beyond just being able to mkfs, mount, growfs etc ... it's a serious game of catch-up with xfs in that space, IMHO, which has been doing it well for years now...)
Still, pushing snapshots upstream which will have an on-disk format more limited than the rest of the filesystem's on-disk format does strike me as suboptimal from a pure technical design POV.
What if we proposed, say, xattr code that could only apply xattrs to files located in the first 16T? I don't think it'd be accepted.
I understand that you have a history and a format and a business case, but that really should not change whether we do it right the first time, upstream, IMHO... But I'm just the peanut gallery, here.... ;)
-Eric
Quoted 5 lines
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 53 lines · Eric Sandeen
Quoted 15 lines · Amir G.
Quoted 14 lines · Eric Sandeen
Quoted 12 lines · Amir G.
Quoted 5 lines
And one last note, I also think that the snapshot format change in the
Quoted 4 lines
future, when we'll have snpashots with 64bit feature compatible seems just wrong to me. Adding some features or changing the implementation a bit is ok, but format change is different. When the code is upstream and stable it is just wrong.
What can I say, I understand why it looks bad, but is 64bit code upstream and stable? Hell no! e2fsprogs 64bit is not out yet! There is no reason to call it 'format change'.
It's going to be a new format used only for 64bit fs, which are not even out there yet. And when they are finally out there, they won't have
snapshots until the new format is implemented.Quoted 6 lines
Quoted 2 lines
Well, the on-disk format for 64-bit (48-bit?) ext4 is there & fixed; it's just that there is no released userspace which can properly handle it, right?
I don't know, you tell me.
Are there many users out there using 64bit feature, without the proper user space tools?No, but that doesn't mean the disk format has to change when the tools come out... I just don't want to confuse "there are no tools" with "the disk format is unstable" - Andreas et. al. have been using that format for years.
Quoted 10 lines
Quoted 5 lines
I don't anticipate ext4 format changes for >16T, or am I missing something?
-Eric
Argh! I wish I hadn't missed the Monday call (it's
not in a good time for me).
This whole 'format change' has gone out of control
and I find it hard to present my case properly on scattered emails.Sorry; I may have just misunderstood...
Quoted 11 lines
The message I am trying to get through is:
There is 32bit snapshot file format, which is implemented and well tested. There is 64bit snapshot file format, which is not implemented yet, so 64bit and snapshot feature are mutually exclusive.
If and when 64bit snapshot file format will be implemented, it will be a new type of extent mapped file (v2) with 48bit logical addresses. Is this a 'format change'? Call it what you will, but it shouldn't affect anything on existing structures. It should only affect the non-existing structure of 64bit snapshot file.Does this answer your question?
Quoted 8 lines
Yes, I guess I had misunderstood your point; I thought you were implying that ext4's format had to change to support 64-bit, so why not change snapshots along with it....
But you're just saying that you wish to push 32-bit snapshots which only work with certain sizes of ext4 filesystems now, and later you will release a new snapshot format which works with the larger filesystems. Right?
Right. Where 'Larger filesystems' := 64bit block addresses.
Quoted 5 lines
(I don't actually know if we'll ever have 64-bit ext4, though, there are still so many scaling issues beyond just being able to mkfs, mount, growfs etc ... it's a serious game of catch-up with xfs in that space, IMHO, which has been doing it well for years now...)
More of a good reason to push a snapshot file format that work well with 32bit ext4.
Quoted 7 lines
Still, pushing snapshots upstream which will have an on-disk format more limited than the rest of the filesystem's on-disk format does strike me as suboptimal from a pure technical design POV.
What if we proposed, say, xattr code that could only apply xattrs to files located in the first 16T? I don't think it'd be accepted.
That is not a correct analogy. The correct analogy is not supporting xattrs on 64-bit ext4. Whether it makes sense or not for snapshots depends IMHO on whether people find snapshot on 32bit ext4 only useful or not.
I naturally think that people will find it useful. Anyone can add snapshots to his existing 32-bit ext4, No one can migrate the same fs to 64-bit...
Quoted 14 lines
I understand that you have a history and a format and a business case, but that really should not change whether we do it right the first time, upstream, IMHO... But I'm just the peanut gallery, here.... ;)
-Eric
Quoted 5 lines
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 44 lines · Amir G.
Quoted 31 lines · Lukas Czerner
Quoted 22 lines · Amir G.
Quoted 11 lines · Lukas Czerner
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
Hi Lukas,
Thank you for pointing out the marketing aspect.
I must admit that my user-case rather speaks for itself. CTERA develops a NAS device which is specialized for backing up local networks and snapshots gives the NAS a time dimension without paying for it in disk space and performance.
Quoted 6 lines
The reason for not going with btrfs 3 years ago is clear. So why not go with it now instead of moving forward to ext4 with snapshots?
Part of the answer lies in the possibility to run fsck -x, which gets rid of the snapshots in the case of fs corruption and gets you back to good old stable and consistent ext4.Quoted 9 lines
But that is not even a real reason, is it ? When you need snapshots, well, then you just need it and do no want to get rid of it. When fs corruption appears, then it's bad in any case and the fsck should be able to more or less fix it.
So you're saying that when corruption appears, then you *have to* blast all snapshots ? I am not sure how btrfs is going to deal with it, but it does seem like an advantage at all, why are you presenting it as such ?
Hi Lukas,
Quoted 7 lines
First of all, thank you for being strict with me.
I admit to having lousy marketing skills...The market I am targeting are the sys admins who are very cautious about their 'data' and are reluctant therefor to migrate from ext3 to ext4, not to speak of btrfs.
Well, that's why I am concerned with merging the ext4 snapshots. This is exactly the reason why people will get nervous when you try to push a huge change like ext4 snapshots into the stable code base. Yes, when you do not compile it in, it does not affect the fs very much, but try to tell people that ext4 is not the old-good-stable-ext4 when you enable this feature. And I do not believe that snapshot code does not interfere with the old ext4 code paths, so there is a place for horrible bugs waiting for us.
Quoted 8 lines
To this market I say, you can have snapshots of your 'data' on ext4 without risking the proven stability of ext4. The snapshots of the 'data' are not guarantied to be as stable (being a new feature), but because the snapshots are second to 'data' in ext4 snapshots, corrupted snapshots will not risk the 'data'.
Quoted 6 lines
During 1 year of next3 in production systems, we found bugs. But none of the bugs corrupted 'data'. All of the bugs which caused file system to contain errors, the errors were restricted to snapshot files and in those worst cases, we could always go to emergency plan B (plan A being fsck -p) and run fsck -x which always solved the problem.
It does not matter that much how long or how much your embedded production systems are out there. The fact is that it is really very limited work load variation, hence very limited testing.
Quoted 4 lines
The customer was always consulted before resorting to 'plan B' and was given the chance to copy out 'data' from the snapshots (it was always possible) before we discard them.
So it is true, when you have an fs problem (corruption) you have to blast off all your snapshots ?
Quoted 86 lines
Needless to say, the said bugs were fixed and ext4 snapshots will enjoy the stability of next3 and the 'fail safe' nature of the solution, which was proven several times on the field.
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new
dm_multisnapcode. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?Quoted 5 lines
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
Ehm.. I did present this benchmark on LSF:
http://global.phoronix-test-suite.com/index.php?k=profile&u=amir73il-4632-11284-26560Quoted 6 lines
Quoted 3 lines
unless you snoozed ;-)
it shows performance vs. ext4 w/o snapshots and with snapshots and while taking snapshots.I believe that you just missed the fact that not everyone has attended LSF and your lightning talk, but that's ok.
That's not really OK. I should have posted the results and analysis on my wiki (the results are there).
Quoted 4 lines
It seems to me that random writes are usually faster with you snapshot code regardless whether you use snapshots or not. Is that because of non snapshot related changes you've made ?
Not that I know of.
I can explain why random write onesnap is faster than nosnap and why 1snappermin is faster than onesnap, but I am not sure about nosnap vs. plain ext4.Quoted 5 lines
Also random reads seems to be slower with snapshots, is suspect that this is because of read through, so the reason for the slowdown that it was CPU bound ? I do not see any CPU utilization data.
Only the 1snappermin is slower.
I suspect it has to do with the fs freezes, but I admin I have not looked into it.Quoted 4 lines
The postmark results seems quite odd, it is actually a lot faster with one snapshot and a lot slower with multiple snapshots, do you have an idea what is going on ?
The name onesnap is misleading. It should have been existingsnaps.
The important factor is whether or not snapshots are taken during the test. In the 1snappermin case, postmark is the only test that exposes the weak spot of ext4 snapshots performance - deletes/truncates. create file+delete file with existing snapshots has no overhead (no COW). create file+take snapshot+delete file has the overhead of moving the deleted blocks to snapshot.
With regards to speed up of onesnap, postmark is randomizing the file creates/write so it may be a similar effect to random write.
I did not investigate this.Quoted 14 lines
Quoted 5 lines
I did not compare with btrfs, but I bet there are ext4 vs. btrfs benchmarks out there.
dm-multisnap is better than dm-snap only when it comes to overhead per snapshot. it still copies every written block, which is far from being the case in ext4 snapshots.Nevertheless, I still have not seen any comparison with other snapshotting possibilities we have. Note that ext4 to btrfs comparison is not enough, because we do not know what is the difference between the difference of ext4 with/without snapshots and btrfs with/without snapshots. The reason for this is that btrfs performance is very likely to scale up, but ext4 is pretty much done in that matter and I do not expect any huge performance leaps in the future.
Quoted 6 lines
Quoted 2 lines
Also, rejecting dm-multisnap based on this statement is not enough, show us some numbers.
Well, if you come to understand the difference between fs level an dm level snapshots, you will see why i am rejecting dm-multisnap (performance wise only!).
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Quoted 4 lines
Anyway #1: I have already answered this questions 2 years ago and I think the answers are still valid both for LVM and btrfs:
http://sourceforge.net/apps/mediawiki/next3/index.php?title=FAQ#Why_use_Next3_snapshots_and_not_LVM_snapshots.3F
But again, it was two years ago and even back then you have not had any numbers proving your statements.
Quoted 2 lines
Anyway #2: I need to give you some numbers ;-)
That would be great. Thanks!
Quoted 10 lines
Quoted 6 lines
I believe that it is not very convenient for you, because this feature support your business case and you do not necessarily want to find out that there might be a better way, especially after the work you have done already.
Your analysis of my motives is correct :-)
The use of the term 'better way' I reject.
I think that ext4/btrfs/LVM snapshots are apples and oranges and hamburgers.
But they are really not, because otherwise it would complement each other, but they are all trying to do the same thing, except btrfs has it for free.
Quoted 4 lines
The question of whether the world needs ext4 snapshots is perfectly valid, but going back to the food analogy, I think it's a case of "the proof of the pudding is in the eating".
I have no doubt that if ext4 snapshots are merged, many people will use it.
Well, I would like to have your confidence. Why do you think so ? They will use it for what ? Doing backups ? We can do this easily with LVM without any risk of compromising existing filesystem at all. On desktop ? I very much doubt that since you can not do per directory (or per file) snapshots, can you ?
Quoted 2 lines
And I think that is a good enough (if not the best) reason for inclusion.
It would be of course, except you're the only one saying that.
Thanks!
-Lukas
Quoted 78 lines · Lukas Czerner
Quoted 44 lines · Amir G.
Quoted 31 lines · Lukas Czerner
Quoted 22 lines · Amir G.
Quoted 11 lines · Lukas Czerner
Hi Amir,
thanks very much for the resend. I'll take a look at the whole patch series, but first I want to bring up one important thing.
While this being a huge feature for ext4 (regardless on how intrusive it is for the usual code paths) and while we already have patches in the list with people interesting in looking into them, you should clearly clarify what is the gain of it, what is the use case (and I know you have one), and why it is better than other approaches. You know, advertise it a bit in the marketing way :).
Hi Lukas,
Thank you for pointing out the marketing aspect.
I must admit that my user-case rather speaks for itself. CTERA develops a NAS device which is specialized for backing up local networks and snapshots gives the NAS a time dimension without paying for it in disk space and performance.
Quoted 6 lines
The reason for not going with btrfs 3 years ago is clear. So why not go with it now instead of moving forward to ext4 with snapshots?
Part of the answer lies in the possibility to run fsck -x, which gets rid of the snapshots in the case of fs corruption and gets you back to good old stable and consistent ext4.Quoted 9 lines
But that is not even a real reason, is it ? When you need snapshots, well, then you just need it and do no want to get rid of it. When fs corruption appears, then it's bad in any case and the fsck should be able to more or less fix it.
So you're saying that when corruption appears, then you *have to* blast all snapshots ? I am not sure how btrfs is going to deal with it, but it does seem like an advantage at all, why are you presenting it as such ?
Hi Lukas,
Quoted 7 lines
First of all, thank you for being strict with me.
I admit to having lousy marketing skills...The market I am targeting are the sys admins who are very cautious about their 'data' and are reluctant therefor to migrate from ext3 to ext4, not to speak of btrfs.
Well, that's why I am concerned with merging the ext4 snapshots. This is exactly the reason why people will get nervous when you try to push a huge change like ext4 snapshots into the stable code base. Yes, when you do not compile it in, it does not affect the fs very much, but try to tell people that ext4 is not the old-good-stable-ext4 when you enable this feature. And I do not believe that snapshot code does not interfere with the old ext4 code paths, so there is a place for horrible bugs waiting for us.
Quoted 8 lines
To this market I say, you can have snapshots of your 'data' on ext4 without risking the proven stability of ext4. The snapshots of the 'data' are not guarantied to be as stable (being a new feature), but because the snapshots are second to 'data' in ext4 snapshots, corrupted snapshots will not risk the 'data'.
Quoted 6 lines
During 1 year of next3 in production systems, we found bugs. But none of the bugs corrupted 'data'. All of the bugs which caused file system to contain errors, the errors were restricted to snapshot files and in those worst cases, we could always go to emergency plan B (plan A being fsck -p) and run fsck -x which always solved the problem.
Quoted 3 lines
It does not matter that much how long or how much your embedded production systems are out there. The fact is that it is really very limited work load variation, hence very limited testing.
for the record, the embedded systems are x86_64 dual core, but yes, it's true that the load variation is limited. I am not saying there are no bugs, I'm just saying the 'fail safe' always worked.
Quoted 8 lines
Quoted 5 lines
The customer was always consulted before resorting to 'plan B' and was given the chance to copy out 'data' from the snapshots (it was always possible) before we discard them.
So it is true, when you have an fs problem (corruption) you have to blast off all your snapshots ?
No, most of the time the problem could be solved by fsck -p without discarding snapshots.
Only for the really hard cases, we had to discard the snapshots.
Quoted 90 lines
Quoted 90 lines
Needless to say, the said bugs were fixed and ext4 snapshots will enjoy the stability of next3 and the 'fail safe' nature of the solution, which was proven several times on the field.
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
There is some confusion among developers on what actually are benefits of ext4 snapshots in comparison to btrfs, or in comparison to the new
dm_multisnapcode. I know that you have done quite a lot of testing to assure that it does not actually change old ext4 behavior when snapshot disabled, and that it works well when enabled, but have you done any performance related benchmarks ? Do you have any expectations on how it should behave in different work loads ?Quoted 5 lines
It would be great to see and be able to confirm that ext4 snapshots are really a win, not only on the feature side, but on the performance side as well. I know that there are people out there still undecided or having a strange feeling about your snapshot work. But who can blame them, when we have not seen any hard data on this matter ?
Ehm.. I did present this benchmark on LSF:
http://global.phoronix-test-suite.com/index.php?k=profile&u=amir73il-4632-11284-26560Quoted 6 lines
Quoted 3 lines
unless you snoozed ;-)
it shows performance vs. ext4 w/o snapshots and with snapshots and while taking snapshots.I believe that you just missed the fact that not everyone has attended LSF and your lightning talk, but that's ok.
That's not really OK. I should have posted the results and analysis on my wiki (the results are there).
Quoted 4 lines
It seems to me that random writes are usually faster with you snapshot code regardless whether you use snapshots or not. Is that because of non snapshot related changes you've made ?
Not that I know of.
I can explain why random write onesnap is faster than nosnap and why 1snappermin is faster than onesnap, but I am not sure about nosnap vs. plain ext4.Quoted 5 lines
Also random reads seems to be slower with snapshots, is suspect that this is because of read through, so the reason for the slowdown that it was CPU bound ? I do not see any CPU utilization data.
Only the 1snappermin is slower.
I suspect it has to do with the fs freezes, but I admin I have not looked into it.Quoted 4 lines
The postmark results seems quite odd, it is actually a lot faster with one snapshot and a lot slower with multiple snapshots, do you have an idea what is going on ?
The name onesnap is misleading. It should have been existingsnaps.
The important factor is whether or not snapshots are taken during the test. In the 1snappermin case, postmark is the only test that exposes the weak spot of ext4 snapshots performance - deletes/truncates. create file+delete file with existing snapshots has no overhead (no COW). create file+take snapshot+delete file has the overhead of moving the deleted blocks to snapshot.
With regards to speed up of onesnap, postmark is randomizing the file creates/write so it may be a similar effect to random write.
I did not investigate this.Quoted 16 lines
Quoted 5 lines
I did not compare with btrfs, but I bet there are ext4 vs. btrfs benchmarks out there.
dm-multisnap is better than dm-snap only when it comes to overhead per snapshot. it still copies every written block, which is far from being the case in ext4 snapshots.Nevertheless, I still have not seen any comparison with other snapshotting possibilities we have. Note that ext4 to btrfs comparison is not enough, because we do not know what is the difference between the difference of ext4 with/without snapshots and btrfs with/without snapshots. The reason for this is that btrfs performance is very likely to scale up, but ext4 is pretty much done in that matter and I do not expect any huge performance leaps in the future.
Also, rejecting dm-multisnap based on this statement is not enough, show us some numbers.
Quoted 8 lines
Quoted 3 lines
Well, if you come to understand the difference between fs level an dm level snapshots, you will see why i am rejecting dm-multisnap (performance wise only!).
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Nope.
Quoted 21 lines
Quoted 5 lines
Anyway #1: I have already answered this questions 2 years ago and I think the answers are still valid both for LVM and btrfs:
http://sourceforge.net/apps/mediawiki/next3/index.php?title=FAQ#Why_use_Next3_snapshots_and_not_LVM_snapshots.3FBut again, it was two years ago and even back then you have not had any numbers proving your statements.
Quoted 2 lines
Anyway #2: I need to give you some numbers ;-)
That would be great. Thanks!
Quoted 7 lines
Quoted 6 lines
I believe that it is not very convenient for you, because this feature support your business case and you do not necessarily want to find out that there might be a better way, especially after the work you have done already.
Quoted 7 lines
Quoted 3 lines
Your analysis of my motives is correct :-)
The use of the term 'better way' I reject.
I think that ext4/btrfs/LVM snapshots are apples and oranges and hamburgers.But they are really not, because otherwise it would complement each other, but they are all trying to do the same thing, except btrfs has it for free.
apples and oranges don't complement each other.
they are (non-equal) alternatives.
Quoted 9 lines
Quoted 5 lines
The question of whether the world needs ext4 snapshots is perfectly valid, but going back to the food analogy, I think it's a case of "the proof of the pudding is in the eating".
I have no doubt that if ext4 snapshots are merged, many people will use it.Well, I would like to have your confidence. Why do you think so ? They will use it for what ? Doing backups ? We can do this easily with LVM without any risk of compromising existing filesystem at all. On desktop
LVM snapshots are not meant to be long lived snapshots. As temporary snapshots they are fine, but with ext4 snapshots you can easily retain monthly/weekly snapshots without the need to allocate the space for it in advance and without the 'vanish' quality of LVM snapshots.
Quoted 2 lines
? I very much doubt that since you can not do per directory (or per file) snapshots, can you ?
No, I can't.
Quoted 6 lines
Quoted 3 lines
And I think that is a good enough (if not the best) reason for inclusion.
It would be of course, except you're the only one saying that.
I had several people approaching me that found the feature interesting for their application. Some are developers I met on LSF, some are users that found next3 interesting. One distro (OpenNode) has even announced support for next3.
The incremental filesystem backup (ala ZFS send/recv) is a 'killer app' in my opinion (and in the opinion of sys admins that use ZFS). Ext4 snapshots enables that technology.
Amir.
Quoted 12 lines · Amir G.
Quoted 10 lines · Lukas Czerner
Quoted 4 lines · Amir
The question of whether the world needs ext4 snapshots is perfectly valid, but going back to the food analogy, I think it's a case of "the proof of the pudding is in the eating".
I have no doubt that if ext4 snapshots are merged, many people will use it.Well, I would like to have your confidence. Why do you think so ? They will use it for what ? Doing backups ? We can do this easily with LVM without any risk of compromising existing filesystem at all. On desktop
Quoted 5 lines
LVM snapshots are not meant to be long lived snapshots. As temporary snapshots they are fine, but with ext4 snapshots you can easily retain monthly/weekly snapshots without the need to allocate the space for it in advance and without the 'vanish' quality of LVM snapshots.
In that old sf.net wiki you say:
Why use Next3 snapshots and not LVM snapshots?
* Performance: only small overhead to write performance with snapshots
Fair claim against current LVM snapshot (but not multisnap).
In this thread you're being very terse on the performance hit you assert multisnap has that ext4 snapshots does not. Can you please be more specific?
In your most recent post it seems you're focusing on "LVM snapshots" and attributing the deficiencies of old-style LVM snapshots (non-shared exception store causing N-way copy-out) to dm-multisnap?
Again, nobody will dispute that the existing dm-snapshot target has poor performance that requires snapshots be short-lived. But multisnap does _not_ suffer from those performance problems.
Mike
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I can give the question the answer that ext4 can snapshot per-file or per-directory, and can exclude some files or directories from being snapshotted.
Signature · 2 lines
Best Wishes Yongqiang Yang
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
Quoted 4 lines
can give the question the answer that ext4 can snapshot per-file or per-directory, and can exclude some files or directories from being snapshotted.
So the full answer is that ext4 snapshot CAN exclude
certain files/dirs from snapshot, but this feature is not fully implemented yet (I have it in a dev branch)
Quoted 4 lines
--
Best Wishes
Yongqiang Yang
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in should_snapshot() or should_move_data().
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Quoted 15 lines
Quoted 5 lines
can give the question the answer that ext4 can snapshot per-file or per-directory, and can exclude some files or directories from being snapshotted.
So the full answer is that ext4 snapshot CAN exclude
certain files/dirs from snapshot, but this feature is not fully implemented yet (I have it in a dev branch)Quoted 4 lines
--
Best Wishes
Yongqiang Yang
Signature · 6 lines
Best Wishes Yongqiang Yang -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Yongqiang Yang
Quoted 7 lines · Amir G.
Quoted 6 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
Thanks!
-Lukas
Quoted 20 lines
Quoted 16 lines
Quoted 6 lines
can give the question the answer that ext4 can snapshot per-file or per-directory, and can exclude some files or directories from being snapshotted.
So the full answer is that ext4 snapshot CAN exclude
certain files/dirs from snapshot, but this feature is not fully implemented yet (I have it in a dev branch)Quoted 4 lines
--
Best Wishes
Yongqiang Yang
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Yongqiang Yang
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().
Quoted 6 lines
Quoted 2 lines
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
The design is actually very simple and not as powerful as you probably desire.
I hate to get into the design of future features, when we haven't even ACKed the current feature yet, but since you're the only one did any review, I owe you that much ;-)
To exclude a file from snapshot it needs to have the NOCOW_FL flag. Ironically, btrfs have already added that flag in parallel to me (for the same purpose) so the flag it is already reserved in the code :-)
To avoid some transition issues and keep it really simple, I disallow changing the NOCOW_FL
for regular file and only allow to change it for directories. The NOCOW_FL is inherited from the parent directory,
so setting/clearing the flag on a directory means:
"All files/subdirs will be created excluded/not-excluded from now on".
Inside the snapshot image, excluded directories, which are not really excluded, show normally, but excluded files are shown with zero length, because making the files disappear is hard, but their blocks may have already been reused, so we cannot allow access to them.
Quoted 4 lines
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
So there is actually no inherent "rollback" feature, not for a file/dir and not for the entire fs.
It's a drawback of ext4 snapshots, but hey, cp/rsync from snapshot still works for file/dir ;-)
As for full "fs" rollback. A revert tool has been developed (by students), which requires an external storage to export the "revert patch". This tool is going to be enhanced to use LVM snapshot storage and LVM --merge option to implement ext4 "revert to snapshot" with Yum.
Quoted 6 lines
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
Quoted 7 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).
Quoted 4 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
In ANY snapshots implementation, you can get ENOSPC on operations, which traditionally could not produce this error.
This statement is also true for thin provisioning implementations. The question is how the implementation handles these situations.
What I came to realize on LSF, is that my implementation is the only one (of LVM and btrfs) that tries to deal with the ENOSPC issue and does a good job most of the time.
I deal with it by reserving space for metadata COW on snapshot take, so if a future ENOSPC during metadata COW is possible, snapshot take will fail with ENOSPC.
As for ENOSPC during regular file rewrite, that's not such a big problem. The application simply gets ENOSPC as if the file was sparse to begin with. It may not be pleasant if the application have fallocated the space and used mmap/close without msync...
The only way I see around this issue is reserving space on mmap time (and returning ENOSPC at that time), but again, this issue is shared with btrfs, but is easier to fix (I think) with ext4 snapshots.
Quoted 24 lines
Thanks!
-LukasQuoted 20 lines
Quoted 16 lines
Quoted 6 lines
can give the question the answer that ext4 can snapshot per-file or per-directory, and can exclude some files or directories from being snapshotted.
So the full answer is that ext4 snapshot CAN exclude
certain files/dirs from snapshot, but this feature is not fully implemented yet (I have it in a dev branch)Quoted 4 lines
--
Best Wishes
Yongqiang Yang
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Amir G.
Quoted 10 lines · Lukas Czerner
Quoted 2 lines · Yongqiang Yang
Quoted 1 line · Amir G.
On Thu, Jun 9, 2011 at 4:59 AM, Yongqiang Yang <[email protected]> wrote:
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
as a sysadmin, it's a _wonderful_ tool to have for any system that has people editing/saving files on directly.
Quoted 9 lines
Quoted 8 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Quoted 3 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).
that depends on the site policy.
sometimes it is better to loose snapshots than to run out of disk space and halt the system, sometimes you would rather halt the system.
the policy of what happens when you run out of space should not be a kernel decision, the desired behavior varies far too much.
this includes being able to say things like "I want to always have 10% of my disk allocated to snapshots, but if there's more free space, go ahead and use it, but always keep at least 10% of the disk free so that you don't have to halt new writes while you clear space"
or
"if you run out of space, try and keep the oldest snapshot and the newest snapshot, delete other snapshots in between before touching either of these"
Quoted 7 lines
Quoted 4 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
the worst case when you re-write a file is that it will take the full amount of space that the file currently takes (as if you wrote a new copy of the file and some process had a filehandle open on the old copy, preventing the space from being reclaimed, so it's far from being a new problem)
see the note above about the need to be able to remove snapshots when you are out of space.
since snapshots tend to be small compared to the filesystems they protect (not in all cases, but if you are covering the entire system with one snapshot that would be the way to bet), having the ability to put the snapshot metadata off on a smaller/faster disk would be helpful.
having the ability to snapshot just specific files/directories would be a killer feature IMHO
David Lang
Quoted 24 lines · Amir G.
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Yongqiang Yang
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().Quoted 6 lines
Quoted 2 lines
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
Quoted 5 lines
The design is actually very simple and not as powerful as you probably desire.
I hate to get into the design of future features, when we haven't even ACKed the current feature yet, but since you're the only one did any review, I owe you that much ;-)
Thanks Amir!
You have to understand that I am still not convinced that ext4 snapshot in its current state is really what we want to have in ext4. Especially given the very basic features it provides, without any knowledge on how it can be extended (but you're slowly providing that information, so thanks for that). And especially facing the new dm-multisnap, I really wonder if it is worth it.
If we want filesystem level snapshotting we can try to do it right with all the benefits that snapshots on that level brings. But what I see now, is not even remotely the case. And I have the feeling that all the features that might be interesting for snapshotting at file system level, are just a hack and not inherent from the design. But that is probably because your goal was to snapshot the whole filesystem for the backup purposes, but that's not what I would expect from fs level snapshots. I really hope you understand my point.
Quoted 22 lines
To exclude a file from snapshot it needs to have the
NOCOW_FLflag. Ironically, btrfs have already added that flag in parallel to me (for the same purpose) so the flag it is already reserved in the code :-)To avoid some transition issues and keep it really simple, I disallow changing the
NOCOW_FL
for regular file and only allow to change it for directories. TheNOCOW_FLis inherited from the parent directory,
so setting/clearing the flag on a directory means:
"All files/subdirs will be created excluded/not-excluded from now on".Inside the snapshot image, excluded directories, which are not really excluded, show normally, but excluded files are shown with zero length, because making the files disappear is hard, but their blocks may have already been reused, so we cannot allow access to them.
Quoted 4 lines
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
Quoted 8 lines
So there is actually no inherent "rollback" feature, not for a file/dir and not for the entire fs.
It's a drawback of ext4 snapshots, but hey, cp/rsync from snapshot still works for file/dir ;-)
As for full "fs" rollback. A revert tool has been developed (by students), which requires an external storage to export the "revert patch". This tool is going to be enhanced to use LVM snapshot storage and LVM --merge option to implement ext4 "revert to snapshot" with Yum.
And that is the problem. Because at this level you should be able to do it without very much trouble, because being at file system level you should have all the information. Do not get me wrong, I am not saying that this is easy, but is should be "from design". Exporting the "revert patch" to the external storage, or exporting snapshot to LVM format to be able to merge it...that is all just hacks, because the design itself does not count with that possibility.
Quoted 8 lines
Quoted 7 lines
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
Exactly, so if we want fs level snapshots, it should use that privilege no hack its way to do things like roll back, or excludes+includes. Ext4 was not meant to work that way, nor was your snapshots designed to work that way. If we are considering backups only, because that is what you ext4 snaphosts can provide now, I would prefer to use LVM. But yes, we all need to know how the new multisnap works out.
Quoted 10 lines
Quoted 9 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Quoted 3 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).
Oh, no you misunderstood. Even with your snapshots you'll have to delete old snapshots someday, because otherwise you'll run out of space. With LVM however, you have prereserved space for it, so even if your snapshot volume gets full, it does not affect your filesystem what so ever. And, as a administrator, you can decide whether to extend the snapshot volume to let it live longer, or just let it be and it will die eventually.
And, as far as I know, the new multisnap will notify the admin when the snapshot volume approaches the watermark the same way that for example thinly provisioned storage would do. But again, with your snapshots it will give you ENOSPC when the snapshot grow too big, and at the end of the day, you need to create data to be able to backup it:), so having snapshots separate from your fs volume makes sense.
Quoted 23 lines
Quoted 6 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
In ANY snapshots implementation, you can get ENOSPC on operations, which traditionally could not produce this error.
This statement is also true for thin provisioning implementations. The question is how the implementation handles these situations.What I came to realize on LSF, is that my implementation is the only one (of LVM and btrfs) that tries to deal with the ENOSPC issue and does a good job most of the time.
I deal with it by reserving space for metadata COW on snapshot take, so if a future ENOSPC during metadata COW is possible, snapshot take will fail with ENOSPC.
Quoted 7 lines
As for ENOSPC during regular file rewrite, that's not such a big problem. The application simply gets ENOSPC as if the file was sparse to begin with. It may not be pleasant if the application have fallocated the space and used mmap/close without msync...
The only way I see around this issue is reserving space on mmap time (and returning ENOSPC at that time), but again, this issue is shared with btrfs, but is easier to fix (I think) with ext4 snapshots.
Yes, I do understand that ext4 snaphosts are doing well in that aspect, but as I said, having snapshots separate from your file system gives you advantage of not running into ENOSPC on your file system until you really fill it with data.
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
Thanks!
-Lukas
Quoted 28 lines · On Thu, Jun 9, 2011 at 11:13 AM, <[email protected]> wrote:
Quoted 16 lines · Amir G.
Quoted 6 lines · Lukas Czerner
Quoted 3 lines · Yongqiang Yang
Quoted 1 line · Amir G.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
On Thu, Jun 9, 2011 at 4:59 AM, Yongqiang Yang <[email protected]> wrote:
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
Quoted 2 lines
as a sysadmin, it's a _wonderful_ tool to have for any system that has people editing/saving files on directly.
Thank you david. Finally some positive feedback from the people for whom the feature is intended for :-)
Quoted 29 lines
Quoted 11 lines
Quoted 10 lines
Also, I do not buy the whole argument of "not have to create separate disk
space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.Quoted 4 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots
implementation can do (for long lived snapshots).that depends on the site policy.
sometimes it is better to loose snapshots than to run out of disk space and halt the system, sometimes you would rather halt the system.
the policy of what happens when you run out of space should not be a kernel decision, the desired behavior varies far too much.
this includes being able to say things like "I want to always have 10% of my disk allocated to snapshots, but if there's more free space, go ahead and use it, but always keep at least 10% of the disk free so that you don't have to halt new writes while you clear space"
Quoted 5 lines
or
"if you run out of space, try and keep the oldest snapshot and the newest snapshot, delete other snapshots in between before touching either of these"
I fully agree.
AFAIK, there is no user space tool to manage snapshots to this level for Linux. The only snapshot manager I know about is snapper:
http://en.opensuse.org/Portal:Snapper, which we are working on adding ext4 snapshots support to.
Snapper does not have the free space based policy to the best of my knowledge, but it could be improved to monitor free disk space.
A tool like that does not need any further kernel changes from
ext4 and btrfs to implement the policies suggested above.
However, with LVM snapshots, some of these policies (like use whatever space you have free in the filesystem) are simply not possible.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root).
You need a bit of scripting to gather the disk space used by snapshots (du).
Quoted 4 lines
the worst case when you re-write a file is that it will take the full amount of space that the file currently takes (as if you wrote a new copy of the file and some process had a filehandle open on the old copy, preventing the space from being reclaimed, so it's far from being a new problem)
No. it's a new problem.
When you have a large db, which does random writes to an exiting db file, it does not expect ENOSPC, when updating an existing record or index. Only by keeping enough free disk space in the system at all times, can you avoid this kind of problems.
Quoted 8 lines
see the note above about the need to be able to remove snapshots when you are out of space.
since snapshots tend to be small compared to the filesystems they protect (not in all cases, but if you are covering the entire system with one snapshot that would be the way to bet), having the ability to put the snapshot metadata off on a smaller/faster disk would be helpful.
Helpful for which workload?
For reading from snapshots? Yes, that would be faster. For writing to the filesystem? I demonstrated that the performance overhead is near zero.
Quoted 3 lines
having the ability to snapshot just specific files/directories would be a killer feature IMHO
I agree to that, but I don't think the ext4 will be able to provide that to the full extent.
Quoted 7 lines
David Lang
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 29 lines · Amir G.
Quoted 28 lines · On Thu, Jun 9, 2011 at 11:13 AM, <[email protected]> wrote:
Quoted 25 lines · Amir G.
Quoted 6 lines · Lukas Czerner
Quoted 3 lines · Yongqiang Yang
Quoted 1 line · Amir G.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
On Thu, Jun 9, 2011 at 4:59 AM, Yongqiang Yang <[email protected]> wrote:
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
Quoted 5 lines
Quoted 2 lines
as a sysadmin, it's a _wonderful_ tool to have for any system that has people editing/saving files on directly.
Thank you david. Finally some positive feedback from the people for whom the feature is intended for :-)
No one is arguing about the advantages of snapshots. I think that we are all clear on this. Snapshots are useful.
Quoted 44 lines
Quoted 30 lines
Quoted 12 lines
Quoted 11 lines
Also, I do not buy the whole argument of "not have to create separate disk
space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.Quoted 4 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots
implementation can do (for long lived snapshots).that depends on the site policy.
sometimes it is better to loose snapshots than to run out of disk space and halt the system, sometimes you would rather halt the system.
the policy of what happens when you run out of space should not be a kernel decision, the desired behavior varies far too much.
this includes being able to say things like "I want to always have 10% of my disk allocated to snapshots, but if there's more free space, go ahead and use it, but always keep at least 10% of the disk free so that you don't have to halt new writes while you clear space"
Quoted 5 lines
or
"if you run out of space, try and keep the oldest snapshot and the newest snapshot, delete other snapshots in between before touching either of these"
I fully agree.
AFAIK, there is no user space tool to manage snapshots to this level for Linux. The only snapshot manager I know about is snapper:
http://en.opensuse.org/Portal:Snapper, which we are working on adding ext4 snapshots support to.
Snapper does not have the free space based policy to the best of my knowledge, but it could be improved to monitor free disk space.
Quoted 4 lines
A tool like that does not need any further kernel changes from
ext4 and btrfs to implement the policies suggested above.
However, with LVM snapshots, some of these policies (like use whatever space you have free in the filesystem) are simply not possible.
And why is that ? With LVM you can shrink or extent volumes at will, I do not think this is a problem at all, moreover, you can always add more drives to resize your existing volumes to.
Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root).
You need a bit of scripting to gather the disk space used by snapshots (du).Quoted 4 lines
the worst case when you re-write a file is that it will take the full amount of space that the file currently takes (as if you wrote a new copy of the file and some process had a filehandle open on the old copy, preventing the space from being reclaimed, so it's far from being a new problem)
Quoted 5 lines
No. it's a new problem.
When you have a large db, which does random writes to an exiting db file, it does not expect ENOSPC, when updating an existing record or index. Only by keeping enough free disk space in the system at all times, can you avoid this kind of problems.
You can very well avoid this kind of problems when you separate filesystem and snapshots, that is what LVM can do easily.
Quoted 9 lines
Quoted 9 lines
see the note above about the need to be able to remove snapshots when you are out of space.
since snapshots tend to be small compared to the filesystems they protect (not in all cases, but if you are covering the entire system with one snapshot that would be the way to bet), having the ability to put the snapshot metadata off on a smaller/faster disk would be helpful.
Very easy to do with dm-multisnap.
Quoted 7 lines
Helpful for which workload?
For reading from snapshots? Yes, that would be faster. For writing to the filesystem? I demonstrated that the performance overhead is near zero.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
having the ability to snapshot just specific files/directories would be a killer feature IMHO
I agree to that, but I don't think the ext4 will be able to provide that to the full extent.
And that is for being fs level snapshots a huge drawback.
Quoted 9 lines
Quoted 8 lines
David Lang
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Lukas Czerner
Quoted 24 lines · Amir G.
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Yongqiang Yang
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().Quoted 6 lines
Quoted 2 lines
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
Quoted 5 lines
The design is actually very simple and not as powerful as you probably desire.
I hate to get into the design of future features, when we haven't even ACKed the current feature yet, but since you're the only one did any review, I owe you that much ;-)
Quoted 8 lines
Thanks Amir!
You have to understand that I am still not convinced that ext4 snapshot in its current state is really what we want to have in ext4. Especially given the very basic features it provides, without any knowledge on how it can be extended (but you're slowly providing that information, so thanks for that). And especially facing the new dm-multisnap, I really wonder if it is worth it.
Did you not see my post on LVM vs. Ext4 snapshots?
https://lkml.org/lkml/2011/6/8/296
dm-multisnap is much better than dm-snap, but it's not perfect. And ext4 snapshots aren't perfect either, but they do bring some new interesting options for sys admins.
Quoted 10 lines
If we want filesystem level snapshotting we can try to do it right with all the benefits that snapshots on that level brings. But what I see now, is not even remotely the case. And I have the feeling that all the features that might be interesting for snapshotting at file system level, are just a hack and not inherent from the design. But that is probably because your goal was to snapshot the whole filesystem for the backup purposes, but that's not what I would expect from fs level snapshots. I really hope you understand my point.
I think I understand the point. The reason that ext4 snapshots are less powerful then, say, btrfs snapshots, is not because of my design, it is because I was building on top a 20 year old on-disk format (ext2), which was extended 2 times already, but remained mostly backwards compatible. There is only so much you can do without block reference counts and this is all that I was trying to do.
Quoted 31 lines
Quoted 22 lines
To exclude a file from snapshot it needs to have the
NOCOW_FLflag. Ironically, btrfs have already added that flag in parallel to me (for the same purpose) so the flag it is already reserved in the code :-)To avoid some transition issues and keep it really simple, I disallow changing the
NOCOW_FL
for regular file and only allow to change it for directories. TheNOCOW_FLis inherited from the parent directory,
so setting/clearing the flag on a directory means:
"All files/subdirs will be created excluded/not-excluded from now on".Inside the snapshot image, excluded directories, which are not really excluded, show normally, but excluded files are shown with zero length, because making the files disappear is hard, but their blocks may have already been reused, so we cannot allow access to them.
Quoted 4 lines
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
Quoted 8 lines
So there is actually no inherent "rollback" feature, not for a file/dir and not for the entire fs.
It's a drawback of ext4 snapshots, but hey, cp/rsync from snapshot still works for file/dir ;-)
As for full "fs" rollback. A revert tool has been developed (by students), which requires an external storage to export the "revert patch". This tool is going to be enhanced to use LVM snapshot storage and LVM --merge option to implement ext4 "revert to snapshot" with Yum.
Quoted 8 lines
And that is the problem. Because at this level you should be able to do it without very much trouble, because being at file system level you should have all the information. Do not get me wrong, I am not saying that this is easy, but is should be "from design". Exporting the "revert patch" to the external storage, or exporting snapshot to LVM format to be able to merge it...that is all just hacks, because the design itself does not count with that possibility.
The design makes a conscious choice to keep snapshots *inside*
the filesystem.
This is both an advantage (no need to change on-disk format and checking tools) and disadvantage (you cannot mount a snapshot without mounting the fs first).
Quoted 18 lines
Quoted 8 lines
Quoted 7 lines
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.
Quoted 8 lines
Exactly, so if we want fs level snapshots, it should use that privilege no hack its way to do things like roll back, or excludes+includes. Ext4 was not meant to work that way, nor was your snapshots designed to work that way. If we are considering backups only, because that is what you ext4 snaphosts can provide now, I would prefer to use LVM. But yes, we all need to know how the new multisnap works out.
Why do you keep saying 'backup only'?
There is a huge difference between having long lived snapshots, like CTERA products have, and temporary snapshot for backup purpose (for which LVM is adequate).
Quoted 21 lines
Quoted 10 lines
Quoted 9 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Quoted 3 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).Oh, no you misunderstood. Even with your snapshots you'll have to delete old snapshots someday, because otherwise you'll run out of space. With LVM however, you have prereserved space for it, so even if your snapshot volume gets full, it does not affect your filesystem what so ever. And, as a administrator, you can decide whether to extend the snapshot volume to let it live longer, or just let it be and it will die eventually.
Quoted 7 lines
And, as far as I know, the new multisnap will notify the admin when the snapshot volume approaches the watermark the same way that for example thinly provisioned storage would do. But again, with your snapshots it will give you ENOSPC when the snapshot grow too big, and at the end of the day, you need to create data to be able to backup it:), so having snapshots separate from your fs volume makes sense.
Yes, one day you will run out of space and will be getting a warning before that, if you are using a CTERA product.
You won't be getting the warning from the kernel snapshots code, but from disk space monitoring daemon.
And when you get the warning (or ENOSPC if you ignored the warnings) you will have 2 options:
1. add disks and resize the fs
2. delete some snapshots
When using a CTERA product, you not have to pre-partition your disk space between fs and snapshots - they are thinly provisioned, which is a big advantage for a product which does not require being an IT expert to operate it.
Quoted 31 lines
Quoted 23 lines
Quoted 6 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
In ANY snapshots implementation, you can get ENOSPC on operations, which traditionally could not produce this error.
This statement is also true for thin provisioning implementations. The question is how the implementation handles these situations.What I came to realize on LSF, is that my implementation is the only one (of LVM and btrfs) that tries to deal with the ENOSPC issue and does a good job most of the time.
I deal with it by reserving space for metadata COW on snapshot take, so if a future ENOSPC during metadata COW is possible, snapshot take will fail with ENOSPC.
Quoted 7 lines
As for ENOSPC during regular file rewrite, that's not such a big problem. The application simply gets ENOSPC as if the file was sparse to begin with. It may not be pleasant if the application have fallocated the space and used mmap/close without msync...
The only way I see around this issue is reserving space on mmap time (and returning ENOSPC at that time), but again, this issue is shared with btrfs, but is easier to fix (I think) with ext4 snapshots.
Quoted 4 lines
Yes, I do understand that ext4 snaphosts are doing well in that aspect, but as I said, having snapshots separate from your file system gives you advantage of not running into ENOSPC on your file system until you really fill it with data.
It should be, as David wrote, a choice to the sys admin. Because ext4 snapshots are thinly provisioned, you can always say "use 10% for snapshots and 90% for data" (like you would with LVM), But you cannot say "reserve 10% for snapshots 50% for data and the rest to either" when you administer LVM snapshots.
You are confusing user functionality with functionality provided by the kernel. LVM happens to check water marks in the kernel because of it's design. That doesn't mean that the same thing cannot be accomplished for ext4 snapshots by user tools.
Quoted 7 lines
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
I don't know how you intend to determine if dm-multisnap is 'good enough'. I don't claim to have the capability myself to determine if ext4 snapshots are 'good enough'.
I just try to present the technical differences between the 3 solutions (LVM,ext4,btrfs) and claim that each have their advantages and disadvantages over others.
I wish more sys admins and end users would provide feedback, though I don't know how many of them are following LKML.
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 59 lines · Amir G.
Quoted 32 lines · Lukas Czerner
Quoted 24 lines · Amir G.
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Yongqiang Yang
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().Quoted 6 lines
Quoted 2 lines
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
Quoted 5 lines
The design is actually very simple and not as powerful as you probably desire.
I hate to get into the design of future features, when we haven't even ACKed the current feature yet, but since you're the only one did any review, I owe you that much ;-)Quoted 8 lines
Thanks Amir!
You have to understand that I am still not convinced that ext4 snapshot in its current state is really what we want to have in ext4. Especially given the very basic features it provides, without any knowledge on how it can be extended (but you're slowly providing that information, so thanks for that). And especially facing the new dm-multisnap, I really wonder if it is worth it.
Did you not see my post on LVM vs. Ext4 snapshots?
https://lkml.org/lkml/2011/6/8/296
dm-multisnap is much better than dm-snap, but it's not perfect. And ext4 snapshots aren't perfect either, but they do bring some new interesting options for sys admins.Quoted 10 lines
If we want filesystem level snapshotting we can try to do it right with all the benefits that snapshots on that level brings. But what I see now, is not even remotely the case. And I have the feeling that all the features that might be interesting for snapshotting at file system level, are just a hack and not inherent from the design. But that is probably because your goal was to snapshot the whole filesystem for the backup purposes, but that's not what I would expect from fs level snapshots. I really hope you understand my point.
Quoted 6 lines
I think I understand the point. The reason that ext4 snapshots are less powerful then, say, btrfs snapshots, is not because of my design, it is because I was building on top a 20 year old on-disk format (ext2), which was extended 2 times already, but remained mostly backwards compatible. There is only so much you can do without block reference counts and this is all that I was trying to do.
And I can imagine it works well enough. But given that we have better, more generic solution, which does not require hacking stable filesystem I am becoming more and more against ext4 snapshots to be merged. And if anyone wishes to have some fancy fs level snapshoting features (which ext4 snapshots can no provide from the resons you have pointed out), you can always turn to btrfs, which has been designed that way unlike ext4.
Quoted 42 lines
Quoted 33 lines
Quoted 24 lines
To exclude a file from snapshot it needs to have the
NOCOW_FLflag. Ironically, btrfs have already added that flag in parallel to me (for the same purpose) so the flag it is already reserved in the code :-)To avoid some transition issues and keep it really simple, I disallow changing the
NOCOW_FL
for regular file and only allow to change it for directories. TheNOCOW_FLis inherited from the parent directory,
so setting/clearing the flag on a directory means:
"All files/subdirs will be created excluded/not-excluded from now on".Inside the snapshot image, excluded directories, which are not really excluded, show normally, but excluded files are shown with zero length, because making the files disappear is hard, but their blocks may have already been reused, so we cannot allow access to them.
Quoted 4 lines
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
Quoted 8 lines
So there is actually no inherent "rollback" feature, not for a file/dir and not for the entire fs.
It's a drawback of ext4 snapshots, but hey, cp/rsync from snapshot still works for file/dir ;-)
As for full "fs" rollback. A revert tool has been developed (by students), which requires an external storage to export the "revert patch". This tool is going to be enhanced to use LVM snapshot storage and LVM --merge option to implement ext4 "revert to snapshot" with Yum.Quoted 8 lines
And that is the problem. Because at this level you should be able to do it without very much trouble, because being at file system level you should have all the information. Do not get me wrong, I am not saying that this is easy, but is should be "from design". Exporting the "revert patch" to the external storage, or exporting snapshot to LVM format to be able to merge it...that is all just hacks, because the design itself does not count with that possibility.
Quoted 4 lines
The design makes a conscious choice to keep snapshots *inside*
the filesystem.
This is both an advantage (no need to change on-disk format and checking tools) and disadvantage (you cannot mount a snapshot without mounting the fs first).
And thats where ext4 snapshots loose. With dm you do not need to change on-disk format, tools or filesystem itself, and you can mount the snapshot without also mounting the origin.
Quoted 29 lines
Quoted 20 lines
Quoted 10 lines
Quoted 9 lines
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.Quoted 8 lines
Exactly, so if we want fs level snapshots, it should use that privilege no hack its way to do things like roll back, or excludes+includes. Ext4 was not meant to work that way, nor was your snapshots designed to work that way. If we are considering backups only, because that is what you ext4 snaphosts can provide now, I would prefer to use LVM. But yes, we all need to know how the new multisnap works out.
Quoted 4 lines
Why do you keep saying 'backup only'?
There is a huge difference between having long lived snapshots, like CTERA products have, and temporary snapshot for backup purpose (for which LVM is adequate).
dm's multisnapshots are designed to be long lived and can be used as such.
Quoted 39 lines
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Quoted 3 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).Oh, no you misunderstood. Even with your snapshots you'll have to delete old snapshots someday, because otherwise you'll run out of space. With LVM however, you have prereserved space for it, so even if your snapshot volume gets full, it does not affect your filesystem what so ever. And, as a administrator, you can decide whether to extend the snapshot volume to let it live longer, or just let it be and it will die eventually.
Quoted 7 lines
And, as far as I know, the new multisnap will notify the admin when the snapshot volume approaches the watermark the same way that for example thinly provisioned storage would do. But again, with your snapshots it will give you ENOSPC when the snapshot grow too big, and at the end of the day, you need to create data to be able to backup it:), so having snapshots separate from your fs volume makes sense.
Yes, one day you will run out of space and will be getting a warning before that, if you are using a CTERA product.
You won't be getting the warning from the kernel snapshots code, but from disk space monitoring daemon.
And when you get the warning (or ENOSPC if you ignored the warnings) you will have 2 options:
1. add disks and resize the fs
2. delete some snapshots
Quoted 4 lines
When using a CTERA product, you not have to pre-partition your disk space between fs and snapshots - they are thinly provisioned, which is a big advantage for a product which does not require being an IT expert to operate it.
dm multisnapshot code is using thin provisioning, you just have to pick the volume and that's it.
Quoted 38 lines
Quoted 33 lines
Quoted 25 lines
Quoted 8 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
In ANY snapshots implementation, you can get ENOSPC on operations, which traditionally could not produce this error.
This statement is also true for thin provisioning implementations. The question is how the implementation handles these situations.What I came to realize on LSF, is that my implementation is the only one (of LVM and btrfs) that tries to deal with the ENOSPC issue and does a good job most of the time.
I deal with it by reserving space for metadata COW on snapshot take, so if a future ENOSPC during metadata COW is possible, snapshot take will fail with ENOSPC.
Quoted 7 lines
As for ENOSPC during regular file rewrite, that's not such a big problem. The application simply gets ENOSPC as if the file was sparse to begin with. It may not be pleasant if the application have fallocated the space and used mmap/close without msync...
The only way I see around this issue is reserving space on mmap time (and returning ENOSPC at that time), but again, this issue is shared with btrfs, but is easier to fix (I think) with ext4 snapshots.Quoted 4 lines
Yes, I do understand that ext4 snaphosts are doing well in that aspect, but as I said, having snapshots separate from your file system gives you advantage of not running into ENOSPC on your file system until you really fill it with data.
Quoted 5 lines
It should be, as David wrote, a choice to the sys admin. Because ext4 snapshots are thinly provisioned, you can always say "use 10% for snapshots and 90% for data" (like you would with LVM), But you cannot say "reserve 10% for snapshots 50% for data and the rest to either" when you administer LVM snapshots.
I am not sure how can this be managed with multisnap target, but I do not see a reason why it can not be done, given that both data and snapshots can be allocated from within the same pool.
Quoted 5 lines
You are confusing user functionality with functionality provided by the kernel. LVM happens to check water marks in the kernel because of it's design. That doesn't mean that the same thing cannot be accomplished for ext4 snapshots by user tools.
That was not my point, I was simply saying that it is not ext4 snapshots advantage.
Quoted 10 lines
Quoted 9 lines
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
Quoted 8 lines
I don't know how you intend to determine if dm-multisnap is 'good enough'. I don't claim to have the capability myself to determine if ext4 snapshots are 'good enough'.
I just try to present the technical differences between the 3 solutions (LVM,ext4,btrfs) and claim that each have their advantages and disadvantages over others.
I wish more sys admins and end users would provide feedback, though I don't know how many of them are following LKML.
I do. When it can do long lived snapshots without any obvious headaches it is good enough. Your only contra argument was that lvm snapshotting is slow, which is not that big argument now when we have multisnap almost ready. I am not even talking about features, because clearly mutlisnap has superset of the features that ext4 does - no I am not counting per-file or per-directory snapshotting because clearly those are just hacks and it was not designed that way.
-Lukas
Quoted 286 lines · Lukas Czerner
Quoted 59 lines · Amir G.
Quoted 32 lines · Lukas Czerner
Quoted 24 lines · Amir G.
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Yongqiang Yang
Quoted 10 lines · Amir G.
Quoted 7 lines · Yongqiang Yang
Quoted 4 lines
But I do understand the difference. And also, when it comes to fs level snapshotting I would suspect that it would do something we can not do with the current solutions, for example per-file or per-directory snapshots, cat ext4 snapshots do that ?
Hi Lukas,
I noticed that there is no answer to this question in the thread. I
I think I answered this question with No it can't ;-)
I think this can be implemented easily by chattr and adding check in
should_snapshot()orshould_move_data().Quoted 6 lines
Quoted 2 lines
And I thought Lukas are focusing on if ext4-snapshots can do this easily. So i said YES:-)
Cool, finally something interesting :). So, how it'll work ? Does that require any format changes again:) ? Can you exclude the whole root and then selectively pick the directories or files you are interested in ?
Quoted 5 lines
The design is actually very simple and not as powerful as you probably desire.
I hate to get into the design of future features, when we haven't even ACKed the current feature yet, but since you're the only one did any review, I owe you that much ;-)Quoted 8 lines
Thanks Amir!
You have to understand that I am still not convinced that ext4 snapshot in its current state is really what we want to have in ext4. Especially given the very basic features it provides, without any knowledge on how it can be extended (but you're slowly providing that information, so thanks for that). And especially facing the new dm-multisnap, I really wonder if it is worth it.
Did you not see my post on LVM vs. Ext4 snapshots?
https://lkml.org/lkml/2011/6/8/296
dm-multisnap is much better than dm-snap, but it's not perfect. And ext4 snapshots aren't perfect either, but they do bring some new interesting options for sys admins.Quoted 10 lines
If we want filesystem level snapshotting we can try to do it right with all the benefits that snapshots on that level brings. But what I see now, is not even remotely the case. And I have the feeling that all the features that might be interesting for snapshotting at file system level, are just a hack and not inherent from the design. But that is probably because your goal was to snapshot the whole filesystem for the backup purposes, but that's not what I would expect from fs level snapshots. I really hope you understand my point.
Quoted 6 lines
I think I understand the point. The reason that ext4 snapshots are less powerful then, say, btrfs snapshots, is not because of my design, it is because I was building on top a 20 year old on-disk format (ext2), which was extended 2 times already, but remained mostly backwards compatible. There is only so much you can do without block reference counts and this is all that I was trying to do.
And I can imagine it works well enough. But given that we have better, more generic solution, which does not require hacking stable filesystem I am becoming more and more against ext4 snapshots to be merged. And if anyone wishes to have some fancy fs level snapshoting features (which ext4 snapshots can no provide from the resons you have pointed out), you can always turn to btrfs, which has been designed that way unlike ext4.
Quoted 42 lines
Quoted 33 lines
Quoted 24 lines
To exclude a file from snapshot it needs to have the
NOCOW_FLflag. Ironically, btrfs have already added that flag in parallel to me (for the same purpose) so the flag it is already reserved in the code :-)To avoid some transition issues and keep it really simple, I disallow changing the
NOCOW_FL
for regular file and only allow to change it for directories. TheNOCOW_FLis inherited from the parent directory,
so setting/clearing the flag on a directory means:
"All files/subdirs will be created excluded/not-excluded from now on".Inside the snapshot image, excluded directories, which are not really excluded, show normally, but excluded files are shown with zero length, because making the files disappear is hard, but their blocks may have already been reused, so we cannot allow access to them.
Quoted 4 lines
How does rollback work with ext4 snapshots ? Can you selectively roll back one file, or the whole directory subtree even when you're snapshotting more ?
Quoted 8 lines
So there is actually no inherent "rollback" feature, not for a file/dir and not for the entire fs.
It's a drawback of ext4 snapshots, but hey, cp/rsync from snapshot still works for file/dir ;-)
As for full "fs" rollback. A revert tool has been developed (by students), which requires an external storage to export the "revert patch". This tool is going to be enhanced to use LVM snapshot storage and LVM --merge option to implement ext4 "revert to snapshot" with Yum.Quoted 8 lines
And that is the problem. Because at this level you should be able to do it without very much trouble, because being at file system level you should have all the information. Do not get me wrong, I am not saying that this is easy, but is should be "from design". Exporting the "revert patch" to the external storage, or exporting snapshot to LVM format to be able to merge it...that is all just hacks, because the design itself does not count with that possibility.
Quoted 4 lines
The design makes a conscious choice to keep snapshots *inside*
the filesystem.
This is both an advantage (no need to change on-disk format and checking tools) and disadvantage (you cannot mount a snapshot without mounting the fs first).And thats where ext4 snapshots loose. With dm you do not need to change on-disk format, tools or filesystem itself, and you can mount the snapshot without also mounting the origin.
Quoted 29 lines
Quoted 20 lines
Quoted 10 lines
Quoted 9 lines
You see, when it comes to the full fs snapshots I am not convinced that it is *very* useful, yes it might have some users, but you can alway take the safe way and do lvm snapshots (or better use the new multisnap) for backup, without need to modify stable filesystem code.
Quoted 9 lines
You think like a developer. Try talking to some sys admins. Especially ones that worked with Solaris/ZFS or NetApp.
See what they think about snapshots and about the LVM alternative... Snapshots have addictive qualities. Ones you've used them, you can't go back to not having them.
Imagine how people used to live before the 'Undo' button and imagine that your employer forced you to use an editor without an Undo button. This is the kind of feedback I got from sys admins that moved from Solaris to Linux.Quoted 8 lines
Exactly, so if we want fs level snapshots, it should use that privilege no hack its way to do things like roll back, or excludes+includes. Ext4 was not meant to work that way, nor was your snapshots designed to work that way. If we are considering backups only, because that is what you ext4 snaphosts can provide now, I would prefer to use LVM. But yes, we all need to know how the new multisnap works out.
Quoted 4 lines
Why do you keep saying 'backup only'?
There is a huge difference between having long lived snapshots, like CTERA products have, and temporary snapshot for backup purpose (for which LVM is adequate).dm's multisnapshots are designed to be long lived and can be used as such.
Quoted 39 lines
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines
Also, I do not buy the whole argument of "not have to create separate disk space for snapshot". It is actually better for sysadmins, because you have perfect control on what is going on, how much space is used for your snapshots and how much is used by your data. You can always easily extend the snapshot volume, or let it die silently when it is too old and too big.
Quoted 3 lines
Seriously, Lukas, talk to sys admins.
Letting the snapshot die silently is the worst possible thing that a snapshots implementation can do (for long lived snapshots).Oh, no you misunderstood. Even with your snapshots you'll have to delete old snapshots someday, because otherwise you'll run out of space. With LVM however, you have prereserved space for it, so even if your snapshot volume gets full, it does not affect your filesystem what so ever. And, as a administrator, you can decide whether to extend the snapshot volume to let it live longer, or just let it be and it will die eventually.
Quoted 7 lines
And, as far as I know, the new multisnap will notify the admin when the snapshot volume approaches the watermark the same way that for example thinly provisioned storage would do. But again, with your snapshots it will give you ENOSPC when the snapshot grow too big, and at the end of the day, you need to create data to be able to backup it:), so having snapshots separate from your fs volume makes sense.
Yes, one day you will run out of space and will be getting a warning before that, if you are using a CTERA product.
You won't be getting the warning from the kernel snapshots code, but from disk space monitoring daemon.
And when you get the warning (or ENOSPC if you ignored the warnings) you will have 2 options:
1. add disks and resize the fs
2. delete some snapshotsQuoted 4 lines
When using a CTERA product, you not have to pre-partition your disk space between fs and snapshots - they are thinly provisioned, which is a big advantage for a product which does not require being an IT expert to operate it.
dm multisnapshot code is using thin provisioning, you just have to pick the volume and that's it.
Quoted 38 lines
Quoted 33 lines
Quoted 25 lines
Quoted 8 lines
How does it actually work on ext4 snapshots ? When you're going to rewrite a file, you will never know how much disk space it'll take in advance, am I right ? Is the filesystem accounting for the snapshot size as well ? or is it hidden ?
It's not hidden, it's accounted for as a regular file (usually owned by root). You need a bit of scripting to gather the disk space used by snapshots (du).
In ANY snapshots implementation, you can get ENOSPC on operations, which traditionally could not produce this error.
This statement is also true for thin provisioning implementations. The question is how the implementation handles these situations.What I came to realize on LSF, is that my implementation is the only one (of LVM and btrfs) that tries to deal with the ENOSPC issue and does a good job most of the time.
I deal with it by reserving space for metadata COW on snapshot take, so if a future ENOSPC during metadata COW is possible, snapshot take will fail with ENOSPC.
Quoted 7 lines
As for ENOSPC during regular file rewrite, that's not such a big problem. The application simply gets ENOSPC as if the file was sparse to begin with. It may not be pleasant if the application have fallocated the space and used mmap/close without msync...
The only way I see around this issue is reserving space on mmap time (and returning ENOSPC at that time), but again, this issue is shared with btrfs, but is easier to fix (I think) with ext4 snapshots.Quoted 4 lines
Yes, I do understand that ext4 snaphosts are doing well in that aspect, but as I said, having snapshots separate from your file system gives you advantage of not running into ENOSPC on your file system until you really fill it with data.
Quoted 5 lines
It should be, as David wrote, a choice to the sys admin. Because ext4 snapshots are thinly provisioned, you can always say "use 10% for snapshots and 90% for data" (like you would with LVM), But you cannot say "reserve 10% for snapshots 50% for data and the rest to either" when you administer LVM snapshots.
I am not sure how can this be managed with multisnap target, but I do not see a reason why it can not be done, given that both data and snapshots can be allocated from within the same pool.
Quoted 5 lines
You are confusing user functionality with functionality provided by the kernel. LVM happens to check water marks in the kernel because of it's design. That doesn't mean that the same thing cannot be accomplished for ext4 snapshots by user tools.
That was not my point, I was simply saying that it is not ext4 snapshots advantage.
Quoted 10 lines
Quoted 9 lines
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
Quoted 8 lines
I don't know how you intend to determine if dm-multisnap is 'good enough'. I don't claim to have the capability myself to determine if ext4 snapshots are 'good enough'.
I just try to present the technical differences between the 3 solutions (LVM,ext4,btrfs) and claim that each have their advantages and disadvantages over others.
I wish more sys admins and end users would provide feedback, though I don't know how many of them are following LKML.
Quoted 8 lines
I do. When it can do long lived snapshots without any obvious headaches it is good enough. Your only contra argument was that lvm snapshotting is slow, which is not that big argument now when we have multisnap almost ready. I am not even talking about features, because clearly mutlisnap has superset of the features that ext4 does - no I am not counting per-file or per-directory snapshotting because clearly those are just hacks and it was not designed that way.
Hi Lukas,
I am very glad to have you as my reviewer and critic :-)
I am saying that with all honesty, because I know that you are impartial and have no anti-ext4 agenda.
LVM multisnap does look like a big leap forward, but you should not be blinded by the promised feature, before you inspect the implementation, the same as you are doing to ext4 snapshots now...
I could suggest that you put your root fs on a QCOW2 file exported as NBD. That would give you both thin provisioning and snapshots, but you know perfectly well, that this is not a 'good enough' solution.
I'm not saying that LVM is comparable to QCOW2 virtual volume. I'm just saying we (included myself) should carefully examine the alternatives before make a ruling against one of them.
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, 10 Jun 2011, Amir G. wrote:
--snip--
Quoted 39 lines
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
Quoted 8 lines
I don't know how you intend to determine if dm-multisnap is 'good enough'. I don't claim to have the capability myself to determine if ext4 snapshots are 'good enough'.
I just try to present the technical differences between the 3 solutions (LVM,ext4,btrfs) and claim that each have their advantages and disadvantages over others.
I wish more sys admins and end users would provide feedback, though I don't know how many of them are following LKML.Quoted 8 lines
I do. When it can do long lived snapshots without any obvious headaches it is good enough. Your only contra argument was that lvm snapshotting is slow, which is not that big argument now when we have multisnap almost ready. I am not even talking about features, because clearly mutlisnap has superset of the features that ext4 does - no I am not counting per-file or per-directory snapshotting because clearly those are just hacks and it was not designed that way.
Hi Lukas,
I am very glad to have you as my reviewer and critic :-)
I am saying that with all honesty, because I know that you are impartial and have no anti-ext4 agenda.LVM multisnap does look like a big leap forward, but you should not be blinded by the promised feature, before you inspect the implementation, the same as you are doing to ext4 snapshots now...
Quoted 9 lines
I could suggest that you put your root fs on a QCOW2 file exported as NBD. That would give you both thin provisioning and snapshots, but you know perfectly well, that this is not a 'good enough' solution.
I'm not saying that LVM is comparable to QCOW2 virtual volume. I'm just saying we (included myself) should carefully examine the alternatives before make a ruling against one of them.Amir.
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
Thanks!
-Lukas
Quoted 58 lines · Lukas Czerner
On Fri, 10 Jun 2011, Amir G. wrote:
--snip--
Quoted 39 lines
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
Granted, I have to take a look at the multisnap code, to see what it can do and compare it with ext4 snapshots, because really, if it is good enough and you will be able to do snapshotting backups as you do with your approach, I do not see the reason why to complicate our life in ext4.
Quoted 8 lines
I don't know how you intend to determine if dm-multisnap is 'good enough'. I don't claim to have the capability myself to determine if ext4 snapshots are 'good enough'.
I just try to present the technical differences between the 3 solutions (LVM,ext4,btrfs) and claim that each have their advantages and disadvantages over others.
I wish more sys admins and end users would provide feedback, though I don't know how many of them are following LKML.Quoted 8 lines
I do. When it can do long lived snapshots without any obvious headaches it is good enough. Your only contra argument was that lvm snapshotting is slow, which is not that big argument now when we have multisnap almost ready. I am not even talking about features, because clearly mutlisnap has superset of the features that ext4 does - no I am not counting per-file or per-directory snapshotting because clearly those are just hacks and it was not designed that way.
Hi Lukas,
I am very glad to have you as my reviewer and critic :-)
I am saying that with all honesty, because I know that you are impartial and have no anti-ext4 agenda.LVM multisnap does look like a big leap forward, but you should not be blinded by the promised feature, before you inspect the implementation, the same as you are doing to ext4 snapshots now...
Quoted 9 lines
I could suggest that you put your root fs on a QCOW2 file exported as NBD. That would give you both thin provisioning and snapshots, but you know perfectly well, that this is not a 'good enough' solution.
I'm not saying that LVM is comparable to QCOW2 virtual volume. I'm just saying we (included myself) should carefully examine the alternatives before make a ruling against one of them.Amir.
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
Quoted 9 lines
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
Thanks!
-Lukas
Wow, if you can provide numbers that would be great!
If you can also run the same tests on the same machine with my ext4dev module that would be awesome!
the module on next3.sf.net is for kernel 2.6.38, but I can send you a module for kernel 2.6.39 or 3.0-rc1 if you like.
Thanks!
Amir.
Quoted 4 lines · Amir G.
Why do you keep saying 'backup only'?
There is a huge difference between having long lived snapshots, like CTERA products have, and temporary snapshot for backup purpose (for which LVM is adequate).
I must have blinked somewhere - I'm not convinced LVM is even "adequate" for backup purposes. In particular, how does an LVM-level snapshot deal with the "metadata in memory" problem (basically the exact same problem as running fsck on a disk partition that is already mounted)?
Quoted 7 lines · On Sat, Jun 11, 2011 at 1:51 AM, <[email protected]> wrote:
Quoted 4 lines · Amir G.
Why do you keep saying 'backup only'?
There is a huge difference between having long lived snapshots, like CTERA products have, and temporary snapshot for backup purpose (for which LVM is adequate).
Quoted 6 lines
I must have blinked somewhere - I'm not convinced LVM is even "adequate" for backup purposes. In particular, how does an LVM-level snapshot deal with the "metadata in memory" problem (basically the exact same problem as running fsck on a disk partition that is already mounted)?
It uses the filesystem freeze API.
Same as ext4 snapshots.
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Lukas Czerner
--snip--
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
Quoted 6 lines
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
(Dropping LKML - had enough of that attention for 1 week...)
Hi Lukas,
So did you get any numbers? Joe said you were not able to get good results.
Did you come to understand the drawbacks of multisnap (physical fragmentation)?
Did it make you change your mind about ext4 snapshots?
I am planning to join the ext4 weekly call today and ask if people think that we still have open issues with ext4 snapshots, which must be resolved before the merge.
I have 2 questions that should be answered before the merge:
1. Should 32bit ext4 move to 48bit snapshot file format after the format is implemented for 64bit ext4?
2. Should exclude bitmap be allocated only on mkfs time or should it also be possible to allocate it with tune2fs?
Allocating it later will enable snapshots on existing fs, but will have sub-optimal on-disk layout.
If anyone has opinions on these 2 questions, please make them heard here or on the call today.
Thanks,
Amir.
Quoted 17 lines · Amir G.
Quoted 9 lines · Lukas Czerner
--snip--
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
Quoted 6 lines
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
Quoted 5 lines
(Dropping LKML - had enough of that attention for 1 week...)
Hi Lukas,
So did you get any numbers? Joe said you were not able to get good results.
Hi, yes I did had some bad numbers, but it was due to stupid setup I have created :) metadata and data volume on the same drive, but in the different partition. In the postmark test the performance drop was about 100% and that is quite expected as it probably caused a LOT of seeks.
But when I separated data and metadata I have very good results. Results differs with the data block size used by dm.
Filesystem on bare device.
113 76 657.89 661.60 2000.00 325.80 328.61 329.28 661.60 1980.88 332.09 24363052.00 76242168.00
dm-multisnap
bs=128
146 118 423.73 512.06 1923.08 209.84 211.64 212.08 512.06 1904.69 213.89 18856334.00 59009348.00
bs=256
151 96 520.83 495.11 943.40 257.93 260.15 260.68 495.11 934.38 262.91 18231952.00 57055396.00
bs=512
134 96 520.83 557.92 1515.15 257.93 260.15 260.68 557.92 1500.67 262.91 20544960.00 64293764.00
bs=1024
119 70 714.29 628.24 1470.59 353.73 356.77 357.50 628.24 1456.53 360.56 23134662.00 72398024.00
bs=2048
128 76 657.89 584.07 1190.48 325.80 328.61 329.28 584.07 1179.10 332.09 21508006.00 67307536.00
bs=4096
131 84 595.24 570.69 1851.85 294.77 297.31 297.92 570.69 1834.15 300.46 21015456.00 65766144.00
Legend:
-----------------------------------------------------------------------Total_duration Duration_of_transactions Transactions/s Files_created/s Creation_alone/s Creation_mixed_with_transaction/s Read/s Append/s Deleted/s Deletion_alone/s Deletion_mixed_with_transaction/s Read_B/s Write_B/s
-----------------------------------------------------------------------
I choosed postmark because it is doing a lot of operation on the file and it is quite metadata intensive. Although it is still very simple and limited test. However you can see that with data block size 1024B I received almost the same results as in the case of bare device. It means that there was almost none performance drop and I suspect that if I put metadata on the SSD it would not be noticeable at all.
We can see that results are dropping to the bs of 1024B and rising afterwards. I suspect that we are dealing with two variables with opposite outcome. Thinp target works better with bigger block sizes as it has less metadata to work with, but in the other hand snapshots are then more expensive, because we have to deal with COW rather than simple write when we are changing the whole block. But 1024 seems quite reasonable and I also think that putting metadata on SSD (which is easily doable) we can very well address the first one.
Quoted 2 lines
Did you come to understand the drawbacks of multisnap (physical fragmentation)?
Yes I did, but the fragmentation is problem for any thinly provisioned storage. I also understand that your snapshot files has also proble with fragmentation.
Quoted 4 lines
Did it make you change your mind about ext4 snapshots?
From the first time I was interested in ext4 snapshgots, however as I
came to understand how it works (I must admit not *very* deeply) it all seems like a hack to solve your problem at the time (several years ago).
And now, when I see how the new dm-multisnap target works, what features it has, how it performs (more-or-less) it seems to me that it is a lot more flexible and desirable way of doing this.
On the other hand your snapshots disrupts a quite calm water of stable filesystem with a very poor set of features and very limited possibilities of improvements. Not talking about maintaining burden. But yes, it might perform a bit better.
So to sum it up I see that dm-multisnap has superset of features your ext4 snapshots has, in performs well enough, it is more generic solution for all filesystems, it is also more flexibile, it does not require intrusive change into stable fs code, and it has better possibilities of future improvements.
Do even if the final decision does not belong to me, I think that we do not need this code in ext4. If your snapshots were a *real* filesystem level snapshots with all the cool features it provides, the situation would be quite different, however even then I would be thinking if it is worth it, when we have btrfs here and now, ready to use, and improving every day to get at enterprise level (it will, hopefully, be a default filesystem in Fedora 16, which is huge step forward to enterprise environment).
And here I would very much like to see other ext4 developers opinions, because they were really quiet on this matter and it is time to reveal the cards on the table, so ?...
Quoted 23 lines
I am planning to join the ext4 weekly call today and ask if people think that we still have open issues with ext4 snapshots, which must be resolved before the merge.
I have 2 questions that should be answered before the merge:
1. Should 32bit ext4 move to 48bit snapshot file format after the format is implemented for 64bit ext4?
2. Should exclude bitmap be allocated only on mkfs time or should it also be possible to allocate it with tune2fs?
Allocating it later will enable snapshots on existing fs, but will have sub-optimal on-disk layout.If anyone has opinions on these 2 questions, please make them heard here or on the call today.
Thanks,
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 77 lines · Lukas Czerner
Quoted 17 lines · Amir G.
Quoted 9 lines · Lukas Czerner
--snip--
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
Quoted 6 lines
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
Quoted 5 lines
(Dropping LKML - had enough of that attention for 1 week...)
Hi Lukas,
So did you get any numbers? Joe said you were not able to get good results.
Hi, yes I did had some bad numbers, but it was due to stupid setup I have created :) metadata and data volume on the same drive, but in the different partition. In the postmark test the performance drop was about 100% and that is quite expected as it probably caused a LOT of seeks.
But when I separated data and metadata I have very good results. Results differs with the data block size used by dm.
Filesystem on bare device.
113 76 657.89 661.60 2000.00 325.80 328.61 329.28 661.60 1980.88 332.09 24363052.00 76242168.00dm-multisnap
bs=128
146 118 423.73 512.06 1923.08 209.84 211.64 212.08 512.06 1904.69 213.89 18856334.00 59009348.00bs=256
151 96 520.83 495.11 943.40 257.93 260.15 260.68 495.11 934.38 262.91 18231952.00 57055396.00bs=512
134 96 520.83 557.92 1515.15 257.93 260.15 260.68 557.92 1500.67 262.91 20544960.00 64293764.00bs=1024
119 70 714.29 628.24 1470.59 353.73 356.77 357.50 628.24 1456.53 360.56 23134662.00 72398024.00bs=2048
128 76 657.89 584.07 1190.48 325.80 328.61 329.28 584.07 1179.10 332.09 21508006.00 67307536.00bs=4096
131 84 595.24 570.69 1851.85 294.77 297.31 297.92 570.69 1834.15 300.46 21015456.00 65766144.00Legend:
-----------------------------------------------------------------------Total_durationDuration_of_transactionsTransactions/s Files_created/s Creation_alone/s Creation_mixed_with_transaction/s Read/s Append/s Deleted/s Deletion_alone/s Deletion_mixed_with_transaction/s Read_B/s Write_B/s
-----------------------------------------------------------------------I choosed postmark because it is doing a lot of operation on the file and it is quite metadata intensive. Although it is still very simple and limited test. However you can see that with data block size 1024B I received almost the same results as in the case of bare device. It means that there was almost none performance drop and I suspect that if I put metadata on the SSD it would not be noticeable at all.
Quoted 9 lines
We can see that results are dropping to the bs of 1024B and rising afterwards. I suspect that we are dealing with two variables with opposite outcome. Thinp target works better with bigger block sizes as it has less metadata to work with, but in the other hand snapshots are then more expensive, because we have to deal with COW rather than simple write when we are changing the whole block. But 1024 seems quite reasonable and I also think that putting metadata on SSD (which is easily doable) we can very well address the first one.
SSD may be doable for enterprise servers, but I don't have one in my laptop :-(
I think that Joe will agree with me that this is not the benchmark he is concerned about.
It is clear to me that any operations applied to a new thin provisioned file system, will
perform well, sometimes even better than on bare device.
Did you use subdirs in postmark?
If you do, ext3 will try to spread subdirs under root all over the disk (not sure about ext4) and postmark will be slower on bare device.
The benchmark which is relevant to the drawbacks of multisnap is aging a filesystem
to the point that it's metadata is physically layed out very differently than was intended.
Here is a suggested real life test:
1. DATE=START_DATE; take snapshot $DATE
2. git checkout <mainline daily git tag>
3. time -o LOGFILE --append make
4. DATE+=DAY; goto 1
Repeat this test until the volume fills up to several orders of magnitude more than the size
of RAM on your system and observe how build time changes over time.
Quoted 7 lines
Quoted 2 lines
Did you come to understand the drawbacks of multisnap (physical fragmentation)?
Yes I did, but the fragmentation is problem for any thinly provisioned storage. I also understand that your snapshot files has also proble with fragmentation.
It's true. ext4 snapshots generates fragmented *files*, but it does not fragment the filesystem metadata. And only on specific workloads of in-place writes, like large db or virtual image.
One difference is that ext4 snapshots can do effective auto defrag by using the inode context, which is not available for multisnap.
The other big difference is that ext4 snapshots gives precedence to main fs performance, while multisnap hasn't even the notion of a main fs. All thinp and snapshot targets are writable and get equal treatment.
Quoted 7 lines
Quoted 2 lines
Did it make you change your mind about ext4 snapshots?
From the first time I was interested in ext4 snapshgots, however as I came to understand how it works (I must admit not *very* deeply) it all seems like a hack to solve your problem at the time (several years ago).
The problem was not mine, it's was for all Linux users who wanted snapshots. The future does look brighter for them, but CTERA customers don't have to wait for the future...
Quoted 60 lines
And now, when I see how the new dm-multisnap target works, what features it has, how it performs (more-or-less) it seems to me that it is a lot more flexible and desirable way of doing this.
On the other hand your snapshots disrupts a quite calm water of stable filesystem with a very poor set of features and very limited possibilities of improvements. Not talking about maintaining burden. But yes, it might perform a bit better.
So to sum it up I see that dm-multisnap has superset of features your ext4 snapshots has, in performs well enough, it is more generic solution for all filesystems, it is also more flexibile, it does not require intrusive change into stable fs code, and it has better possibilities of future improvements.
Do even if the final decision does not belong to me, I think that we do not need this code in ext4. If your snapshots were a *real* filesystem level snapshots with all the cool features it provides, the situation would be quite different, however even then I would be thinking if it is worth it, when we have btrfs here and now, ready to use, and improving every day to get at enterprise level (it will, hopefully, be a default filesystem in Fedora 16, which is huge step forward to enterprise environment).
And here I would very much like to see other ext4 developers opinions, because they were really quiet on this matter and it is time to reveal the cards on the table, so ?...
Quoted 16 lines
I am planning to join the ext4 weekly call today and ask if people think that we still have open issues with ext4 snapshots, which must be resolved before the merge.
I have 2 questions that should be answered before the merge:
1. Should 32bit ext4 move to 48bit snapshot file format after the format is implemented for 64bit ext4?
2. Should exclude bitmap be allocated only on mkfs time or should it also be possible to allocate it with tune2fs?
Allocating it later will enable snapshots on existing fs, but will have sub-optimal on-disk layout.If anyone has opinions on these 2 questions, please make them heard here or on the call today.
Quoted 7 lines
Thanks,
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html--
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html
Quoted 107 lines · Amir G.
Quoted 77 lines · Lukas Czerner
Quoted 17 lines · Amir G.
Quoted 9 lines · Lukas Czerner
--snip--
Hi Amir,
that is why I spoke with several dm people and all of them had the same opinion. When you are not using the advantage of being at fs level, there is no reason to have shapshoting at this level.
Quoted 6 lines
And no, I am not blinded. I am trying to understand why is multisnap a huge win everyone is saying, so I already asked ejt to step in and give us an overview on how dm-multisnap works and why is it better than the old implementation. Also I am trying it myslef, and so far it works quite well. I might have some numbers later.
Quoted 5 lines
(Dropping LKML - had enough of that attention for 1 week...)
Hi Lukas,
So did you get any numbers? Joe said you were not able to get good results.
Hi, yes I did had some bad numbers, but it was due to stupid setup I have created :) metadata and data volume on the same drive, but in the different partition. In the postmark test the performance drop was about 100% and that is quite expected as it probably caused a LOT of seeks.
But when I separated data and metadata I have very good results. Results differs with the data block size used by dm.
Filesystem on bare device.
113 76 657.89 661.60 2000.00 325.80 328.61 329.28 661.60 1980.88 332.09 24363052.00 76242168.00dm-multisnap
bs=128
146 118 423.73 512.06 1923.08 209.84 211.64 212.08 512.06 1904.69 213.89 18856334.00 59009348.00bs=256
151 96 520.83 495.11 943.40 257.93 260.15 260.68 495.11 934.38 262.91 18231952.00 57055396.00bs=512
134 96 520.83 557.92 1515.15 257.93 260.15 260.68 557.92 1500.67 262.91 20544960.00 64293764.00bs=1024
119 70 714.29 628.24 1470.59 353.73 356.77 357.50 628.24 1456.53 360.56 23134662.00 72398024.00bs=2048
128 76 657.89 584.07 1190.48 325.80 328.61 329.28 584.07 1179.10 332.09 21508006.00 67307536.00bs=4096
131 84 595.24 570.69 1851.85 294.77 297.31 297.92 570.69 1834.15 300.46 21015456.00 65766144.00Legend:
-----------------------------------------------------------------------Total_durationDuration_of_transactionsTransactions/s Files_created/s Creation_alone/s Creation_mixed_with_transaction/s Read/s Append/s Deleted/s Deletion_alone/s Deletion_mixed_with_transaction/s Read_B/s Write_B/s
-----------------------------------------------------------------------I choosed postmark because it is doing a lot of operation on the file and it is quite metadata intensive. Although it is still very simple and limited test. However you can see that with data block size 1024B I received almost the same results as in the case of bare device. It means that there was almost none performance drop and I suspect that if I put metadata on the SSD it would not be noticeable at all.
Quoted 9 lines
We can see that results are dropping to the bs of 1024B and rising afterwards. I suspect that we are dealing with two variables with opposite outcome. Thinp target works better with bigger block sizes as it has less metadata to work with, but in the other hand snapshots are then more expensive, because we have to deal with COW rather than simple write when we are changing the whole block. But 1024 seems quite reasonable and I also think that putting metadata on SSD (which is easily doable) we can very well address the first one.
SSD may be doable for enterprise servers, but I don't have one in my laptop :-(
I think that Joe will agree with me that this is not the benchmark he is concerned about.
It is clear to me that any operations applied to a new thin provisioned file system, will
perform well, sometimes even better than on bare device.Did you use subdirs in postmark?
If you do, ext3 will try to spread subdirs under root all over the disk (not sure about ext4) and postmark will be slower on bare device.The benchmark which is relevant to the drawbacks of multisnap is aging a filesystem
to the point that it's metadata is physically layed out very differently than was intended.Here is a suggested real life test:
Quoted 8 lines
1. DATE=START_DATE; take snapshot $DATE
2. git checkout <mainline daily git tag>
3. time -o LOGFILE --append make
4. DATE+=DAY; goto 1Repeat this test until the volume fills up to several orders of magnitude more than the size
of RAM on your system and observe how build time changes over time.
I am very much aware of the fact that this benchmark is not ideal, but it gives us _some_ numbers - since you did not :). And you specifically asked for it. Hopefully I'll have some time to do better benchmarks but it'll take a while as I have some other stuff to do now.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Did you come to understand the drawbacks of multisnap (physical fragmentation)?
Yes I did, but the fragmentation is problem for any thinly provisioned storage. I also understand that your snapshot files has also proble with fragmentation.
Quoted 6 lines
It's true. ext4 snapshots generates fragmented *files*, but it does not fragment the filesystem metadata. And only on specific workloads of in-place writes, like large db or virtual image.
One difference is that ext4 snapshots can do effective auto defrag by using the inode context, which is not available for multisnap.
No it is not, but from top of my head .. we can use time locality to pack frequently accessed blocks together. Definitely there is a place for improvements.
Quoted 3 lines
The other big difference is that ext4 snapshots gives precedence to main fs performance, while multisnap hasn't even the notion of a main fs. All thinp and snapshot targets are writable and get equal treatment.
I am sorry, what do you mean by that ? Is it that when you mount the snapshot, the reads will actually have lower importance ?
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Did it make you change your mind about ext4 snapshots?
Quoted 8 lines
Quoted 4 lines
From the first time I was interested in ext4 snapshgots, however as I came to understand how it works (I must admit not *very* deeply) it all seems like a hack to solve your problem at the time (several years ago).
The problem was not mine, it's was for all Linux users who wanted snapshots. The future does look brighter for them, but CTERA customers don't have to wait for the future...
I do understand, but as Eric said, your business case is not reason to push this hack into kernel.
Quoted 62 lines
Quoted 61 lines
And now, when I see how the new dm-multisnap target works, what features it has, how it performs (more-or-less) it seems to me that it is a lot more flexible and desirable way of doing this.
On the other hand your snapshots disrupts a quite calm water of stable filesystem with a very poor set of features and very limited possibilities of improvements. Not talking about maintaining burden. But yes, it might perform a bit better.
So to sum it up I see that dm-multisnap has superset of features your ext4 snapshots has, in performs well enough, it is more generic solution for all filesystems, it is also more flexibile, it does not require intrusive change into stable fs code, and it has better possibilities of future improvements.
Do even if the final decision does not belong to me, I think that we do not need this code in ext4. If your snapshots were a *real* filesystem level snapshots with all the cool features it provides, the situation would be quite different, however even then I would be thinking if it is worth it, when we have btrfs here and now, ready to use, and improving every day to get at enterprise level (it will, hopefully, be a default filesystem in Fedora 16, which is huge step forward to enterprise environment).
And here I would very much like to see other ext4 developers opinions, because they were really quiet on this matter and it is time to reveal the cards on the table, so ?...
Quoted 16 lines
I am planning to join the ext4 weekly call today and ask if people think that we still have open issues with ext4 snapshots, which must be resolved before the merge.
I have 2 questions that should be answered before the merge:
1. Should 32bit ext4 move to 48bit snapshot file format after the format is implemented for 64bit ext4?
2. Should exclude bitmap be allocated only on mkfs time or should it also be possible to allocate it with tune2fs?
Allocating it later will enable snapshots on existing fs, but will have sub-optimal on-disk layout.If anyone has opinions on these 2 questions, please make them heard here or on the call today.
Quoted 7 lines
Thanks,
Amir.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html--
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Lukas Czerner
On Mon, 13 Jun 2011, Amir G. wrote:
-snip-
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Did you come to understand the drawbacks of multisnap (physical fragmentation)?
Yes I did, but the fragmentation is problem for any thinly provisioned storage. I also understand that your snapshot files has also proble with fragmentation.
Quoted 6 lines
It's true. ext4 snapshots generates fragmented *files*, but it does not fragment the filesystem metadata. And only on specific workloads of in-place writes, like large db or virtual image.
One difference is that ext4 snapshots can do effective auto defrag by using the inode context, which is not available for multisnap.
No it is not, but from top of my head .. we can use time locality to pack frequently accessed blocks together. Definitely there is a place for improvements.
Quoted 7 lines
Quoted 3 lines
The other big difference is that ext4 snapshots gives precedence to main fs performance, while multisnap hasn't even the notion of a main fs. All thinp and snapshot targets are writable and get equal treatment.
I am sorry, what do you mean by that ? Is it that when you mount the snapshot, the reads will actually have lower importance ?
with ext4, snapshots reads may cause extra seeks, but main fs will stay optimized for reads.
with thinp and multisnap, there is no optimization for read from one specific target, but I admit that can change in the future when auto defrag heuristics are applies to multisnap.
Amir.
Quoted 5 lines · Amir G.
with ext4, snapshots reads may cause extra seeks, but main fs will stay optimized for reads.
with thinp and multisnap, there is no optimization for read from one specific target, but I admit that can change in the future when auto defrag heuristics are applies to multisnap.
I'm going to keep things symmetrical. A lot of use cases involve pointing at an arbitrary snapshot and saying "that's now my master". This is connected to why I support arbitrary depth of recursive snapshots too.
- Joe
--
lvm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/lvm-devel
Quoted 10 lines · On Tue, Jun 7, 2011 at 6:07 PM, <[email protected]> wrote:
Hi All,
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
Quoted 7 lines
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.Thanks,
Amir.
Hi Ted,
To answer your question about possible diet to snapshot patches, following are some diffstat on groups of patches (by functionality). The diffsstat includes only ext4 core file (excluding new snapshot* files).
As you can see, removing the shrink/merge functionality for multiple snapshots, will remove the need for exclude bitmap and reduce the changes to core files by ~300 insertions.
There is some advantage of not having to add the exclude bitmap to existing fs, but I think the win is not so big, assuming that we will want to have the shrink/merge functionality eventually.
Cheers,
Amir.
Quoted 2 lines
[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental) [PATCH v1 02/36] ext4: snapshot debugging support
Generic stuff.
15 files changed, 122 insertions(+), 1 deletions(-)
Quoted 6 lines
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks [PATCH v1 04/36] ext4: snapshot hooks - block bitmap access [PATCH v1 05/36] ext4: snapshot hooks - delete blocks [PATCH v1 06/36] ext4: snapshot hooks - move data blocks [PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocks
Most of the code in this group handles MOW.
7 files changed, 550 insertions(+), 68 deletions(-)
Quoted 5 lines
[PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TB
Implementation of special snapshot file.
7 files changed, 220 insertions(+), 14 deletions(-)
Quoted 4 lines
[PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshot
Copy/move to snapshot file operations.
5 files changed, 126 insertions(+), 24 deletions(-)
Quoted 4 lines
[PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot [PATCH v1 20/36] ext4: snapshot control - fix new snapshot [PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshot
Mostly new code in ioctl.c.
6 files changed, 171 insertions(+), 3 deletions(-)
Quoted 4 lines
[PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implement
journal_release_buffer()[PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid injournal_head
Helper functions to handle extra COW credits.
7 files changed, 284 insertions(+), 31 deletions(-)
Quoted 1 line
[PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits
Trace/debug for extra COW credits.
3 files changed, 108 insertions(+), 0 deletions(-)
Quoted 2 lines
[PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshot
Not much to gain from dropping snapshot list support...
2 files changed, 2 insertions(+), 0 deletions(-)
Quoted 3 lines
[PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads
We must handle race conditions.
2 files changed, 32 insertions(+), 0 deletions(-)
Quoted 1 line
[PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
We do not need the exclude bitmap if we do not shrink/merge snapshots.
5 files changed, 226 insertions(+), 3 deletions(-)
Quoted 3 lines
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshots
We could support multiple snapshots without shrinking/merging deleted snapshot, but that means that only disk space of oldest snapshot is reclaimed on delete.
2 files changed, 74 insertions(+), 22 deletions(-)
Quoted 21 lines
[PATCH v1 36/36] ext4: snapshot rocompat - enable rw mount
fs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++fs/ext4/ext4.h | 188 ++++-
fs/ext4/ext4_jbd2.c | 162 ++++-
fs/ext4/ext4_jbd2.h | 266 ++++++-
fs/ext4/extents.c | 157 ++++-
fs/ext4/file.c | 11 +-fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++fs/ext4/mballoc.c | 161 ++++-
fs/ext4/move_extent.c | 3 +-
fs/ext4/namei.c | 9 +
fs/ext4/resize.c | 19 +-
fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++fs/ext4/snapshot.h| 690 ++++++++++++++++fs/ext4/snapshot_buffer.c| 393 +++++++++
fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++
Quoted 8 lines
fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 20 lines · Amir G.
Quoted 5 lines · On Tue, Jun 7, 2011 at 6:07 PM, <[email protected]> wrote:
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
Quoted 9 lines
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.To answer your question about possible diet to snapshot patches, following are some diffstat on groups of patches (by functionality). The diffsstat includes only ext4 core file (excluding new snapshot* files).
Quoted 7 lines
As you can see, removing the shrink/merge functionality for multiple snapshots, will remove the need for exclude bitmap and reduce the changes to core files by ~300 insertions.
There is some advantage of not having to add the exclude bitmap to existing fs, but I think the win is not so big, assuming that we will want to have the shrink/merge functionality eventually.
Wouldn't that also mean if shrink/merge are added later it needs another feature flag and added complexity due to another row in the feature test matrix?
Quoted 125 lines
Quoted 3 lines
[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental) [PATCH v1 02/36] ext4: snapshot debugging support
Generic stuff.
15 files changed, 122 insertions(+), 1 deletions(-)Quoted 6 lines
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks [PATCH v1 04/36] ext4: snapshot hooks - block bitmap access [PATCH v1 05/36] ext4: snapshot hooks - delete blocks [PATCH v1 06/36] ext4: snapshot hooks - move data blocks [PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocksMost of the code in this group handles MOW.
7 files changed, 550 insertions(+), 68 deletions(-)Quoted 5 lines
[PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TBImplementation of special snapshot file.
7 files changed, 220 insertions(+), 14 deletions(-)Quoted 4 lines
[PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshotCopy/move to snapshot file operations.
5 files changed, 126 insertions(+), 24 deletions(-)Quoted 4 lines
[PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot [PATCH v1 20/36] ext4: snapshot control - fix new snapshot [PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshotMostly new code in
ioctl.c.6 files changed, 171 insertions(+), 3 deletions(-)Quoted 4 lines
[PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implement
journal_release_buffer()[PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid injournal_headHelper functions to handle extra COW credits.
7 files changed, 284 insertions(+), 31 deletions(-)Quoted 1 line
[PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits
Trace/debug for extra COW credits.
3 files changed, 108 insertions(+), 0 deletions(-)Quoted 2 lines
[PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshotNot much to gain from dropping snapshot list support...
2 files changed, 2 insertions(+), 0 deletions(-)Quoted 3 lines
[PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads
We must handle race conditions.
2 files changed, 32 insertions(+), 0 deletions(-)Quoted 1 line
[PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
We do not need the exclude bitmap if we do not shrink/merge snapshots.
5 files changed, 226 insertions(+), 3 deletions(-)Quoted 3 lines
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshotsWe could support multiple snapshots without shrinking/merging deleted snapshot, but that means that only disk space of oldest snapshot is reclaimed on delete.
2 files changed, 74 insertions(+), 22 deletions(-)Quoted 19 lines
[PATCH v1 36/36] ext4: snapshot rocompat - enable rw mount
fs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++ fs/ext4/ext4.h | 188 ++++- fs/ext4/ext4_jbd2.c | 162 ++++- fs/ext4/ext4_jbd2.h | 266 ++++++- fs/ext4/extents.c | 157 ++++- fs/ext4/file.c | 11 +- fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++ fs/ext4/mballoc.c | 161 ++++- fs/ext4/move_extent.c | 3 +- fs/ext4/namei.c | 9 + fs/ext4/resize.c | 19 +- fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++ fs/ext4/snapshot.h | 690 ++++++++++++++++Quoted 10 lines
fs/ext4/snapshot_buffer.c | 393 +++++++++ fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 25 lines · Andreas Dilger
Quoted 24 lines · Amir G.
Quoted 5 lines · On Tue, Jun 7, 2011 at 6:07 PM, <[email protected]> wrote:
I am resending the snapshots patch series as per Lukas's request. This time, the snapshot*.c files have not been omitted, as in the previous posting.
Quoted 9 lines
The series is still based on ext4 dev branch sometime in the preparation for 3.0 merge window. It was not yet rebased on 3.0-rc1, so punch holes changes have not been addressed yet.
As always, I advocate online review of the patches at:
https://github.com/amir73il/ext4-snapshots/commits/for-ext4-v1
but if you insist on doing it the old way, I won't complain.To answer your question about possible diet to snapshot patches, following are some diffstat on groups of patches (by functionality). The diffsstat includes only ext4 core file (excluding new snapshot* files).
As you can see, removing the shrink/merge functionality for multiple snapshots, will remove the need for exclude bitmap and reduce the changes to core files by ~300 insertions.
Quoted 6 lines
Quoted 3 lines
There is some advantage of not having to add the exclude bitmap to existing fs, but I think the win is not so big, assuming that we will want to have the shrink/merge functionality eventually.
Wouldn't that also mean if shrink/merge are added later it needs another feature flag and added complexity due to another row in the feature test matrix?
Sure, it would add another row in the matrix and we don't want that either. Shrink/merge capability could be derived from the exclude_bitmap (compatible) feature.
In fact, without exclude bitmap, shrink/merge can still be done, but the shrink will
not be as efficient as with exclude_bitmap, but the shrink code works just the same
(i.e. it doesn't have to check for exclude_bitmap feature).
BTW, I have just learned that ZFS disk space is not reclaimed at all unless deleting
a complete part of the snapshots history (including the oldest). This is essentially how ext4 snapshots would work without the shrink/merge patches
and exclude_bitmap, but it is not very useful for long snapshot retention policies
(i.e. 1 yearly, 3 monthly, 4 weekly,...).
Quoted 122 lines
Quoted 122 lines
Quoted 4 lines
[PATCH v1 01/36] ext4: EXT4 snapshots (Experimental) [PATCH v1 02/36] ext4: snapshot debugging support
Generic stuff.
15 files changed, 122 insertions(+), 1 deletions(-)Quoted 6 lines
[PATCH v1 03/36] ext4: snapshot hooks - inside JBD hooks [PATCH v1 04/36] ext4: snapshot hooks - block bitmap access [PATCH v1 05/36] ext4: snapshot hooks - delete blocks [PATCH v1 06/36] ext4: snapshot hooks - move data blocks [PATCH v1 07/36] ext4: snapshot hooks - direct I/O
[PATCH v1 08/36] ext4: snapshot hooks - move extent file data blocksMost of the code in this group handles MOW.
7 files changed, 550 insertions(+), 68 deletions(-)Quoted 5 lines
[PATCH v1 09/36] ext4: snapshot file
[PATCH v1 10/36] ext4: snapshot file - read through to block device [PATCH v1 11/36] ext4: snapshot file - permissions
[PATCH v1 12/36] ext4: snapshot file - store on disk
[PATCH v1 13/36] ext4: snapshot file - increase maximum file size limit to 16TBImplementation of special snapshot file.
7 files changed, 220 insertions(+), 14 deletions(-)Quoted 4 lines
[PATCH v1 14/36] ext4: snapshot block operations
[PATCH v1 15/36] ext4: snapshot block operation - copy blocks to snapshot [PATCH v1 16/36] ext4: snapshot block operation - move blocks to snapshot [PATCH v1 17/36] ext4: snapshot block operation - copy block bitmap to snapshotCopy/move to snapshot file operations.
5 files changed, 126 insertions(+), 24 deletions(-)Quoted 4 lines
[PATCH v1 18/36] ext4: snapshot control
[PATCH v1 19/36] ext4: snapshot control - init new snapshot [PATCH v1 20/36] ext4: snapshot control - fix new snapshot [PATCH v1 21/36] ext4: snapshot control - reserve disk space for snapshotMostly new code in
ioctl.c.6 files changed, 171 insertions(+), 3 deletions(-)Quoted 4 lines
[PATCH v1 22/36] ext4: snapshot journaled - increase transaction credits [PATCH v1 23/36] ext4: snapshot journaled - implement
journal_release_buffer()[PATCH v1 24/36] ext4: snapshot journaled - bypass to save credits [PATCH v1 25/36] ext4: snapshot journaled - cache last COW tid injournal_headHelper functions to handle extra COW credits.
7 files changed, 284 insertions(+), 31 deletions(-)Quoted 1 line
[PATCH v1 26/36] ext4: snapshot journaled - trace COW/buffer credits
Trace/debug for extra COW credits.
3 files changed, 108 insertions(+), 0 deletions(-)Quoted 2 lines
[PATCH v1 27/36] ext4: snapshot list support
[PATCH v1 28/36] ext4: snapshot list - read through to previous snapshotNot much to gain from dropping snapshot list support...
2 files changed, 2 insertions(+), 0 deletions(-)Quoted 3 lines
[PATCH v1 29/36] ext4: snapshot race conditions - concurrent COW bitmap operations [PATCH v1 30/36] ext4: snapshot race conditions - concurrent COW operations [PATCH v1 31/36] ext4: snapshot race conditions - tracked reads
We must handle race conditions.
2 files changed, 32 insertions(+), 0 deletions(-)Quoted 1 line
[PATCH v1 32/36] ext4: snapshot exclude - the exclude bitmap
We do not need the exclude bitmap if we do not shrink/merge snapshots.
5 files changed, 226 insertions(+), 3 deletions(-)Quoted 3 lines
[PATCH v1 33/36] ext4: snapshot cleanup
[PATCH v1 34/36] ext4: snapshot cleanup - shrink deleted snapshots [PATCH v1 35/36] ext4: snapshot cleanup - merge shrunk snapshotsWe could support multiple snapshots without shrinking/merging deleted snapshot, but that means that only disk space of oldest snapshot is reclaimed on delete.
2 files changed, 74 insertions(+), 22 deletions(-)Quoted 29 lines
[PATCH v1 36/36] ext4: snapshot rocompat - enable rw mount
fs/ext4/Kconfig | 11 + fs/ext4/Makefile | 3 + fs/ext4/balloc.c | 132 +++fs/ext4/ext4.h | 188 ++++-
fs/ext4/ext4_jbd2.c | 162 ++++-
fs/ext4/ext4_jbd2.h | 266 ++++++-
fs/ext4/extents.c | 157 ++++-
fs/ext4/file.c | 11 +-fs/ext4/ialloc.c | 19 +- fs/ext4/inode.c | 668 +++++++++++++-- fs/ext4/ioctl.c | 120 +++fs/ext4/mballoc.c | 161 ++++-
fs/ext4/move_extent.c | 3 +-
fs/ext4/namei.c | 9 +
fs/ext4/resize.c | 19 +-
fs/ext4/snapshot.c | 1000 ++++++++++++++++++++++fs/ext4/snapshot.h| 690 ++++++++++++++++fs/ext4/snapshot_buffer.c| 393 +++++++++
fs/ext4/snapshot_ctl.c | 2002 +++++++++++++++++++++++++++++++++++++++++++++fs/ext4/snapshot_debug.c | 107 +++ fs/ext4/snapshot_debug.h | 105 +++ fs/ext4/snapshot_inode.c | 960 ++++++++++++++++++++++ fs/ext4/super.c | 157 ++++- fs/ext4/xattr.c | 4 +- 24 files changed, 7182 insertions(+), 165 deletions(-)
Quoted 9 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html