linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: put delayed iput tracking list inside in-memory inode
@ 2012-11-30 11:24 Liu Bo
  2012-12-11 14:57 ` Josef Bacik
  0 siblings, 1 reply; 5+ messages in thread
From: Liu Bo @ 2012-11-30 11:24 UTC (permalink / raw)
  To: linux-btrfs

This can save us a dynamic memory allocation/free.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/btrfs_inode.h |    3 +++
 fs/btrfs/inode.c       |   36 +++++++++++++-----------------------
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index ed8ca7c..446ce73 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -79,6 +79,9 @@ struct btrfs_inode {
 	 */
 	struct list_head delalloc_inodes;
 
+	/* for delayed iput */
+	struct list_head iput_list;
+
 	/*
 	 * list for tracking inodes that must be sent to disk before a
 	 * rename or truncate commit
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 95542a1..0c7161d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2070,34 +2070,23 @@ zeroit:
 	return -EIO;
 }
 
-struct delayed_iput {
-	struct list_head list;
-	struct inode *inode;
-};
-
-/* JDM: If this is fs-wide, why can't we add a pointer to
- * btrfs_inode instead and avoid the allocation? */
 void btrfs_add_delayed_iput(struct inode *inode)
 {
-	struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
-	struct delayed_iput *delayed;
-
-	if (atomic_add_unless(&inode->i_count, -1, 1))
-		return;
-
-	delayed = kmalloc(sizeof(*delayed), GFP_NOFS | __GFP_NOFAIL);
-	delayed->inode = inode;
+	if (atomic_add_unless(&inode->i_count, -1, 1) == 0) {
+		struct btrfs_inode *bi = BTRFS_I(inode);
+		struct btrfs_fs_info *fs_info = bi->root->fs_info;
 
-	spin_lock(&fs_info->delayed_iput_lock);
-	list_add_tail(&delayed->list, &fs_info->delayed_iputs);
-	spin_unlock(&fs_info->delayed_iput_lock);
+		spin_lock(&fs_info->delayed_iput_lock);
+		list_add_tail(&bi->iput_list, &fs_info->delayed_iputs);
+		spin_unlock(&fs_info->delayed_iput_lock);
+	}
 }
 
 void btrfs_run_delayed_iputs(struct btrfs_root *root)
 {
 	LIST_HEAD(list);
 	struct btrfs_fs_info *fs_info = root->fs_info;
-	struct delayed_iput *delayed;
+	struct btrfs_inode *bi = NULL;
 	int empty;
 
 	spin_lock(&fs_info->delayed_iput_lock);
@@ -2111,10 +2100,9 @@ void btrfs_run_delayed_iputs(struct btrfs_root *root)
 	spin_unlock(&fs_info->delayed_iput_lock);
 
 	while (!list_empty(&list)) {
-		delayed = list_entry(list.next, struct delayed_iput, list);
-		list_del(&delayed->list);
-		iput(delayed->inode);
-		kfree(delayed);
+		bi = list_entry(list.next, struct btrfs_inode, iput_list);
+		list_del_init(&bi->iput_list);
+		iput(&bi->vfs_inode);
 	}
 }
 
@@ -7097,6 +7085,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
 	mutex_init(&ei->delalloc_mutex);
 	btrfs_ordered_inode_tree_init(&ei->ordered_tree);
 	INIT_LIST_HEAD(&ei->delalloc_inodes);
+	INIT_LIST_HEAD(&ei->iput_list);
 	INIT_LIST_HEAD(&ei->ordered_operations);
 	RB_CLEAR_NODE(&ei->rb_node);
 
@@ -7120,6 +7109,7 @@ void btrfs_destroy_inode(struct inode *inode)
 	WARN_ON(BTRFS_I(inode)->reserved_extents);
 	WARN_ON(BTRFS_I(inode)->delalloc_bytes);
 	WARN_ON(BTRFS_I(inode)->csum_bytes);
+	WARN_ON(!list_empty(&BTRFS_I(inode)->iput_list));
 
 	/*
 	 * This can happen where we create an inode, but somebody else also
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-12-12 16:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-30 11:24 [PATCH] Btrfs: put delayed iput tracking list inside in-memory inode Liu Bo
2012-12-11 14:57 ` Josef Bacik
2012-12-12  1:50   ` Liu Bo
2012-12-12 14:47     ` Josef Bacik
2012-12-12 16:05       ` Liu Bo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).