Browse Source

Btrfs: only log the inode item if we can get away with it

Currently we copy all the file information into the log, inode item, the
refs, xattrs etc.  Except most of this doesn't change from fsync to fsync,
just the inode item changes.  So set a flag if an xattr changes or a link is
added, and otherwise only log the inode item.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Josef Bacik 12 years ago
parent
commit
e997615149
4 changed files with 11 additions and 2 deletions
  1. 1 0
      fs/btrfs/btrfs_inode.h
  2. 1 0
      fs/btrfs/inode.c
  3. 8 2
      fs/btrfs/tree-log.c
  4. 1 0
      fs/btrfs/xattr.c

+ 1 - 0
fs/btrfs/btrfs_inode.h

@@ -39,6 +39,7 @@
 #define BTRFS_INODE_HAS_ORPHAN_ITEM		5
 #define BTRFS_INODE_HAS_ASYNC_EXTENT		6
 #define BTRFS_INODE_NEEDS_FULL_SYNC		7
+#define BTRFS_INODE_COPY_EVERYTHING		8
 
 /* in memory btrfs inode */
 struct btrfs_inode {

+ 1 - 0
fs/btrfs/inode.c

@@ -5083,6 +5083,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
 	inode_inc_iversion(inode);
 	inode->i_ctime = CURRENT_TIME;
 	ihold(inode);
+	set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
 
 	err = btrfs_add_nondir(trans, dir, dentry, inode, 1, index);
 

+ 8 - 2
fs/btrfs/tree-log.c

@@ -3429,14 +3429,20 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
 	} else {
 		if (test_and_clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
 				       &BTRFS_I(inode)->runtime_flags)) {
+			clear_bit(BTRFS_INODE_COPY_EVERYTHING,
+				  &BTRFS_I(inode)->runtime_flags);
 			ret = btrfs_truncate_inode_items(trans, log,
 							 inode, 0, 0);
 		} else {
 			if (inode_only == LOG_INODE_ALL)
 				fast_search = true;
-			max_key.type = BTRFS_XATTR_ITEM_KEY;
+			if (test_and_clear_bit(BTRFS_INODE_COPY_EVERYTHING,
+					       &BTRFS_I(inode)->runtime_flags))
+				max_key.type = BTRFS_XATTR_ITEM_KEY;
+			else
+				max_key.type = BTRFS_INODE_ITEM_KEY;
 			ret = drop_objectid_items(trans, log, path, ino,
-						  BTRFS_XATTR_ITEM_KEY);
+						  max_key.type);
 		}
 	}
 	if (ret) {

+ 1 - 0
fs/btrfs/xattr.c

@@ -208,6 +208,7 @@ int __btrfs_setxattr(struct btrfs_trans_handle *trans,
 
 	inode_inc_iversion(inode);
 	inode->i_ctime = CURRENT_TIME;
+	set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
 	ret = btrfs_update_inode(trans, root, inode);
 	BUG_ON(ret);
 out: