Skip to contentSkip to conversation

btrfs ulist use rbtree instead

PATCH In review Rock Lee 3 participants 4 messages Oct 4, 2012 Btrfs file system

lore
Share & tools
lore

Rock Lee

author
#0 lore raw

PATCH 1/1 btrfs ulist use rbtree instead

From: Rock <[email protected]>

---
 fs/btrfs/backref.c |   10 ++--
 fs/btrfs/qgroup.c  |   16 +++---
 fs/btrfs/send.c    |    2 +-
 fs/btrfs/ulist.c   |  154 +++++++++++++++++++++++++++++++++++++---------------
 fs/btrfs/ulist.h   |   45 ++++++++++++---
 5 files changed, 161 insertions(+), 66 deletions(-)
fs/btrfs/backref.c +5 -5
index ff6475f..a5bebc8 100644
@@ -360,7 +360,7 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
 		}
 
 		/* we put the first parent into the ref at hand */
-		ULIST_ITER_INIT(&uiter);
+		ULIST_ITER_INIT(parents, &uiter);
 		node = ulist_next(parents, &uiter);
 		ref->parent = node ? node->val : 0;
 		ref->inode_list =
@@ -955,7 +955,7 @@ static void free_leaf_list(struct ulist *blocks)
 	struct extent_inode_elem *eie_next;
 	struct ulist_iterator uiter;
 
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(blocks, &uiter);
 	while ((node = ulist_next(blocks, &uiter))) {
 		if (!node->aux)
 			continue;
@@ -1038,7 +1038,7 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
 		return -ENOMEM;
 	}
 
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(tmp, &uiter);
 	while (1) {
 		ret = find_parent_nodes(trans, fs_info, bytenr,
 					time_seq, tmp, *roots, NULL);
@@ -1395,13 +1395,13 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
 	if (ret)
 		goto out;
 
-	ULIST_ITER_INIT(&ref_uiter);
+	ULIST_ITER_INIT(refs, &ref_uiter);
 	while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
 		ret = btrfs_find_all_roots(trans, fs_info, ref_node->val,
 					   tree_mod_seq_elem.seq, &roots);
 		if (ret)
 			break;
-		ULIST_ITER_INIT(&root_uiter);
+		ULIST_ITER_INIT(roots, &root_uiter);
 		while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
 			pr_debug("root %llu references leaf %llu, data list "
 				 "%#lx\n", root_node->val, ref_node->val,
fs/btrfs/qgroup.c +8 -8
index b650155..a0aad87 100644
@@ -1133,7 +1133,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
 	seq = fs_info->qgroup_seq;
 	fs_info->qgroup_seq += roots->nnodes + 1; /* max refcnt */
 
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(roots, &uiter);
 	while ((unode = ulist_next(roots, &uiter))) {
 		struct ulist_node *tmp_unode;
 		struct ulist_iterator tmp_uiter;
@@ -1146,7 +1146,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
 		ulist_reinit(tmp);
 						/* XXX id not needed */
 		ulist_add(tmp, qg->qgroupid, (unsigned long)qg, GFP_ATOMIC);
-		ULIST_ITER_INIT(&tmp_uiter);
+		ULIST_ITER_INIT(tmp, &tmp_uiter);
 		while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) {
 			struct btrfs_qgroup_list *glist;
 
@@ -1169,7 +1169,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
 	 */
 	ulist_reinit(tmp);
 	ulist_add(tmp, qgroup->qgroupid, (unsigned long)qgroup, GFP_ATOMIC);
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(tmp, &uiter);
 	while ((unode = ulist_next(tmp, &uiter))) {
 		struct btrfs_qgroup *qg;
 		struct btrfs_qgroup_list *glist;
@@ -1197,7 +1197,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
 	/*
 	 * step 3: walk again from old refs
 	 */
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(roots, &uiter);
 	while ((unode = ulist_next(roots, &uiter))) {
 		struct btrfs_qgroup *qg;
 		struct ulist_node *tmp_unode;
@@ -1209,7 +1209,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
 
 		ulist_reinit(tmp);
 		ulist_add(tmp, qg->qgroupid, (unsigned long)qg, GFP_ATOMIC);
-		ULIST_ITER_INIT(&tmp_uiter);
+		ULIST_ITER_INIT(tmp, &tmp_uiter);
 		while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) {
 			struct btrfs_qgroup_list *glist;
 
@@ -1470,7 +1470,7 @@ int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes)
 	 */
 	ulist = ulist_alloc(GFP_ATOMIC);
 	ulist_add(ulist, qgroup->qgroupid, (unsigned long)qgroup, GFP_ATOMIC);
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(ulist, &uiter);
 	while ((unode = ulist_next(ulist, &uiter))) {
 		struct btrfs_qgroup *qg;
 		struct btrfs_qgroup_list *glist;
@@ -1498,7 +1498,7 @@ int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes)
 	/*
 	 * no limits exceeded, now record the reservation into all qgroups
 	 */
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(ulist, &uiter);
 	while ((unode = ulist_next(ulist, &uiter))) {
 		struct btrfs_qgroup *qg;
 
@@ -1542,7 +1542,7 @@ void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes)
 
 	ulist = ulist_alloc(GFP_ATOMIC);
 	ulist_add(ulist, qgroup->qgroupid, (unsigned long)qgroup, GFP_ATOMIC);
-	ULIST_ITER_INIT(&uiter);
+	ULIST_ITER_INIT(ulist, &uiter);
 	while ((unode = ulist_next(ulist, &uiter))) {
 		struct btrfs_qgroup *qg;
 		struct btrfs_qgroup_list *glist;
fs/btrfs/send.c +1 -1
index fb5ffe9..d4a2254 100644
@@ -2898,7 +2898,7 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
 	 * deletion and if it's finally possible to perform the rmdir now.
 	 * We also update the inode stats of the parent dirs here.
 	 */
-	ULIST_ITER_INIT(&uit);
+	ULIST_ITER_INIT(check_dirs, &uit);
 	while ((un = ulist_next(check_dirs, &uit))) {
 		if (un->val > sctx->cur_ino)
 			continue;
fs/btrfs/ulist.c +110 -44

211 lines not on this page · raw message

fs/btrfs/ulist.h +37 -8

89 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

fs/btrfs/ulist.c EXPORT_SYMBOL(ulist_add); · line 270

Quoted 8 lines
fs/btrfs/ulist.c +0 -2
@@ -207,16 +266,23 @@ EXPORT_SYMBOL(ulist_add);
  * end is reached. No guarantee is made with respect to the order in which
  * the elements are returned. They might neither be returned in order of
  * addition nor in ascending order.
- * It is allowed to call ulist_add during an enumeration. Newly added items
- * are guaranteed to show up in the running enumeration.
  */
 struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_iterator *uiter)

Quick observation:

If there's code relying on the behaviour stated in the removed part of the comment, it will break. Have you verified this is not the case?

david

#2 lore raw
Quoted 11 lines · David Sterba

fs/btrfs/ulist.c EXPORT_SYMBOL(ulist_add); · line 270

Quoted 8 lines
fs/btrfs/ulist.c +0 -2
@@ -207,16 +266,23 @@ EXPORT_SYMBOL(ulist_add);
  * end is reached. No guarantee is made with respect to the order in which
  * the elements are returned. They might neither be returned in order of
  * addition nor in ascending order.
- * It is allowed to call ulist_add during an enumeration. Newly added items
- * are guaranteed to show up in the running enumeration.
  */
 struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_iterator *uiter)

Quick observation:

Quoted 2 lines

If there's code relying on the behaviour stated in the removed part of the comment, it will break. Have you verified this is not the case?

It's a good thing to use rb-trees when the small inline cache is exhausted, but of course it should keep the semantics. We heavily rely on the removed part.
It should be possible to keep the semantics if the elements are also kept in a linked list. As it inflates the size of struct ulist_node even more, it might make sense to use a smaller struct for the inline cache to keep the footprint low.

Also, a commit message might be good that explains the motivation for the change. Have you done any measurements?

Thanks for working on this.

-Arne

Quoted 7 lines

david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw

Detailed explanations for the patch:

When the small inline cache is exhausted, created a new rbtree,

and the new rbtree uses original spaces the inline nodes placed for saving memory.

By using the rbtree can gain a better performance when nnodes gets larger.

Sorry for I doest't did much more measurements, but the average lookup time increases slower then the original linear policy when nnodes goes larger.

For this is my first patch I submitted, I'm too excited to find something I can hack the kernel, however I didn't consider the whole thing.

I will continue to dive into the btrfs implementation, and work harder.

:-)

- Rock

Quoted 43 lines · Arne Jansen
Quoted 11 lines · David Sterba

fs/btrfs/ulist.c EXPORT_SYMBOL(ulist_add); · line 270

Quoted 8 lines
fs/btrfs/ulist.c +0 -2
@@ -207,16 +266,23 @@ EXPORT_SYMBOL(ulist_add);
 * end is reached. No guarantee is made with respect to the order in which
 * the elements are returned. They might neither be returned in order of
 * addition nor in ascending order.
- * It is allowed to call ulist_add during an enumeration. Newly added items
- * are guaranteed to show up in the running enumeration.
 */
 struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_iterator *uiter)

Quick observation:

Quoted 2 lines

If there's code relying on the behaviour stated in the removed part of the comment, it will break. Have you verified this is not the case?

It's a good thing to use rb-trees when the small inline cache is exhausted, but of course it should keep the semantics. We heavily rely on the removed part.
It should be possible to keep the semantics if the elements are also kept in a linked list. As it inflates the size of struct ulist_node even more, it might make sense to use a smaller struct for the inline cache to keep the footprint low.

Also, a commit message might be good that explains the motivation for the change. Have you done any measurements?

Thanks for working on this.

-Arne

Quoted 7 lines

david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" 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-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/