Skip to contentSkip to conversation

cifs: convert tlink_tree to a rbtree

PATCH In review Jeff Layton 2 participants 7 messages Oct 28, 2010 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cifs: convert tlink_tree to a rbtree

The new multiuser mount code in CIFS uses a radix tree to track tcon_link entries. The main reason for this is historical. The initial implementation that I did used a radix tree with pointers to cifsTconInfo structs.

I chose that because it was possible that a tcon could be in more than one tree at a time. It became evident in later versions however that I needed a separate tracking struct to handle the refcounting. Thus, the tcon_link was born, but I kept the initial design of a radix tree.

We recently had a bit of a kerfuffle surrounding the use of radix trees with IMA to track inodes. While we'll likely have considerably fewer radix tree entries, it's not really the best choice here either. The tcon_link struct will only ever be in one tlink_tree, so we can embed a tracking structure inside it.

This patchset converts that code to use a rbtree instead. This should be as fast or faster than using a radix tree. It also has the benefit of not requiring memory allocations on insertion which simplifies the error handling in those codepaths.

Jeff Layton (2):
cifs: store pointer to master tlink in superblock
cifs: convert tlink_tree to a rbtree

 fs/cifs/cifs_fs_sb.h |    6 +-
 fs/cifs/cifsfs.c     |    2 +-
 fs/cifs/cifsglob.h   |    3 +-
 fs/cifs/connect.c    |  191 +++++++++++++++++++++++++------------------------
 4 files changed, 103 insertions(+), 99 deletions(-)
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288265619-20616-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/2 cifs: store pointer to master tlink in superblock

Instead of keeping a tag on the master tlink in the tree, just keep a pointer to the master in the superblock. That eliminates the need for using the radix tree to look up a tagged entry.

---
 fs/cifs/cifs_fs_sb.h |    2 +-
 fs/cifs/connect.c    |   18 +++---------------
 2 files changed, 4 insertions(+), 16 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -1
index 525ba59..79576da 100644
@@ -43,8 +43,8 @@
 
 struct cifs_sb_info {
 	struct radix_tree_root tlink_tree;
-#define CIFS_TLINK_MASTER_TAG		0	/* is "master" (mount) tcon */
 	spinlock_t tlink_tree_lock;
+	struct tcon_link *master_tlink;
 	struct nls_table *local_nls;
 	unsigned int rsize;
 	unsigned int wsize;
fs/cifs/connect.c +3 -15
index 469c3dd..364eb96 100644
@@ -2917,11 +2917,11 @@ remote_path_check:
 
 	spin_lock(&cifs_sb->tlink_tree_lock);
 	radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink);
-	radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
-			   CIFS_TLINK_MASTER_TAG);
 	spin_unlock(&cifs_sb->tlink_tree_lock);
 	radix_tree_preload_end();
 
+	cifs_sb->master_tlink = tlink;
+
 	queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
 				TLINK_IDLE_EXPIRE);
 
@@ -3275,19 +3275,7 @@ out:
 static struct tcon_link *
 cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
 {
-	struct tcon_link *tlink;
-	unsigned int ret;
-
-	spin_lock(&cifs_sb->tlink_tree_lock);
-	ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
-					0, 1, CIFS_TLINK_MASTER_TAG);
-	spin_unlock(&cifs_sb->tlink_tree_lock);
-
-	/* the master tcon should always be present */
-	if (ret == 0)
-		BUG();
-
-	return tlink;
+	return cifs_sb->master_tlink;
 }
 
 struct cifsTconInfo *
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288265619-20616-2-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#4 lore raw

Re: [PATCH 1/2] cifs: store pointer to master tlink in superblock

Quoted 50 lines · Jeff Layton

Instead of keeping a tag on the master tlink in the tree, just keep a pointer to the master in the superblock. That eliminates the need for using the radix tree to look up a tagged entry.

---
 fs/cifs/cifs_fs_sb.h |    2 +-
 fs/cifs/connect.c    |   18 +++---------------

 2 files changed, 4 insertions(+), 16 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -1
index 525ba59..79576da 100644
@@ -43,8 +43,8 @@
 
  struct cifs_sb_info {
        struct radix_tree_root tlink_tree;
-#define CIFS_TLINK_MASTER_TAG          0       /* is "master" (mount) tcon */
        spinlock_t tlink_tree_lock;
+       struct tcon_link *master_tlink;
        struct nls_table *local_nls;
        unsigned int rsize;
        unsigned int wsize;
fs/cifs/connect.c +2 -2
index 469c3dd..364eb96 100644
@@ -2917,11 +2917,11 @@ remote_path_check:
 
        spin_lock(&cifs_sb->tlink_tree_lock);
        radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink);
-       radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
-                          CIFS_TLINK_MASTER_TAG);
        spin_unlock(&cifs_sb->tlink_tree_lock);
        radix_tree_preload_end();
 
+       cifs_sb->master_tlink = tlink;
+
        queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
                                TLINK_IDLE_EXPIRE);
 
@@ -3275,19 +3275,7 @@ out:

 static struct tcon_link * cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) {
-       struct tcon_link *tlink;
-       unsigned int ret;

fs/cifs/connect.c +0 -2
-
-       spin_lock(&cifs_sb->tlink_tree_lock);

fs/cifs/connect.c out: · line 3278

Quoted 10 lines
fs/cifs/connect.c +1 -9
-       ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
-                                       0, 1, CIFS_TLINK_MASTER_TAG);
-       spin_unlock(&cifs_sb->tlink_tree_lock);
-
-       /* the master tcon should always be present */
-       if (ret == 0)
-               BUG();
-
-       return tlink;
+       return cifs_sb->master_tlink;

Wondering whether we need a function just to return master_tlink within a cifs_sb.
Could the caller(s) of cifs_sb_master_tlink() access master_tlink directly?

Quoted 11 lines

 }

 struct cifsTconInfo *
--
1.7.2.3

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

A message that is not in the archive (sent off-list or not yet received): AANLkTik1mS3hH75GH6cW4Zz8FNv6P1brqvh1ggNG--xw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [PATCH 1/2] cifs: store pointer to master tlink in superblock

Quoted 57 lines · On Thu, 28 Oct 2010 10:06:05 -0500 Shirish Pargaonkar…
Quoted 56 lines · Jeff Layton

Instead of keeping a tag on the master tlink in the tree, just keep a pointer to the master in the superblock. That eliminates the need for using the radix tree to look up a tagged entry.

---
 fs/cifs/cifs_fs_sb.h |    2 +-
 fs/cifs/connect.c    |   18 +++---------------

 2 files changed, 4 insertions(+), 16 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -1
index 525ba59..79576da 100644
@@ -43,8 +43,8 @@
 
  struct cifs_sb_info {
        struct radix_tree_root tlink_tree;
-#define CIFS_TLINK_MASTER_TAG          0       /* is "master" (mount) tcon */
        spinlock_t tlink_tree_lock;
+       struct tcon_link *master_tlink;
        struct nls_table *local_nls;
        unsigned int rsize;
        unsigned int wsize;
fs/cifs/connect.c +2 -2
index 469c3dd..364eb96 100644
@@ -2917,11 +2917,11 @@ remote_path_check:
 
        spin_lock(&cifs_sb->tlink_tree_lock);
        radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink);
-       radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
-                          CIFS_TLINK_MASTER_TAG);
        spin_unlock(&cifs_sb->tlink_tree_lock);
        radix_tree_preload_end();
 
+       cifs_sb->master_tlink = tlink;
+
        queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
                                TLINK_IDLE_EXPIRE);
 
@@ -3275,19 +3275,7 @@ out:

 static struct tcon_link * cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) {
-       struct tcon_link *tlink;
-       unsigned int ret;

fs/cifs/connect.c +0 -8
-
-       spin_lock(&cifs_sb->tlink_tree_lock);
-       ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
-                                       0, 1, CIFS_TLINK_MASTER_TAG);
-       spin_unlock(&cifs_sb->tlink_tree_lock);
-
-       /* the master tcon should always be present */
-       if (ret == 0)
Quoted 9 lines
Quoted 4 lines

-               BUG();
-
-       return tlink;
+       return cifs_sb->master_tlink;

Wondering whether we need a function just to return master_tlink within a cifs_sb.
Could the caller(s) of cifs_sb_master_tlink() access master_tlink directly?

Sure, but accessor functions are generally a good thing. It insulates the callers from needing to know anything about the underlying data structure.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20101028122325.31997c58-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#8 lore raw

Re: [PATCH 1/2] cifs: store pointer to master tlink in superblock

Quoted 70 lines · On Thu, 28 Oct 2010 12:23:25 -0400 Jeff Layton…
Quoted 57 lines · On Thu, 28 Oct 2010 10:06:05 -0500 Shirish Pargaonkar…
Quoted 56 lines · Jeff Layton

Instead of keeping a tag on the master tlink in the tree, just keep a pointer to the master in the superblock. That eliminates the need for using the radix tree to look up a tagged entry.

---
 fs/cifs/cifs_fs_sb.h |    2 +-
 fs/cifs/connect.c    |   18 +++---------------

 2 files changed, 4 insertions(+), 16 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -1
index 525ba59..79576da 100644
@@ -43,8 +43,8 @@
 
  struct cifs_sb_info {
        struct radix_tree_root tlink_tree;
-#define CIFS_TLINK_MASTER_TAG          0       /* is "master" (mount) tcon */
        spinlock_t tlink_tree_lock;
+       struct tcon_link *master_tlink;
        struct nls_table *local_nls;
        unsigned int rsize;
        unsigned int wsize;
fs/cifs/connect.c +2 -2
index 469c3dd..364eb96 100644
@@ -2917,11 +2917,11 @@ remote_path_check:
 
        spin_lock(&cifs_sb->tlink_tree_lock);
        radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink);
-       radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
-                          CIFS_TLINK_MASTER_TAG);
        spin_unlock(&cifs_sb->tlink_tree_lock);
        radix_tree_preload_end();
 
+       cifs_sb->master_tlink = tlink;
+
        queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
                                TLINK_IDLE_EXPIRE);
 
@@ -3275,19 +3275,7 @@ out:

 static struct tcon_link * cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) {
-       struct tcon_link *tlink;
-       unsigned int ret;

fs/cifs/connect.c +0 -8
-
-       spin_lock(&cifs_sb->tlink_tree_lock);
-       ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
-                                       0, 1, CIFS_TLINK_MASTER_TAG);
-       spin_unlock(&cifs_sb->tlink_tree_lock);
-
-       /* the master tcon should always be present */
-       if (ret == 0)
Quoted 9 lines
Quoted 4 lines

-               BUG();
-
-       return tlink;
+       return cifs_sb->master_tlink;

Wondering whether we need a function just to return master_tlink within a cifs_sb.
Could the caller(s) of cifs_sb_master_tlink() access master_tlink directly?

Quoted 4 lines

Sure, but accessor functions are generally a good thing. It insulates the callers from needing to know anything about the underlying data structure.

What may make some sense however is turning this function into a static inline or macro. Thoughts?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20101028125007.734e0b27-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#10 lore raw

Re: [PATCH 1/2] cifs: store pointer to master tlink in superblock

Quoted 78 lines · Jeff Layton
Quoted 70 lines · On Thu, 28 Oct 2010 12:23:25 -0400 Jeff Layton…
Quoted 57 lines · On Thu, 28 Oct 2010 10:06:05 -0500 Shirish Pargaonkar…
Quoted 56 lines · Jeff Layton

Instead of keeping a tag on the master tlink in the tree, just keep a pointer to the master in the superblock. That eliminates the need for using the radix tree to look up a tagged entry.

---
 fs/cifs/cifs_fs_sb.h |    2 +-
 fs/cifs/connect.c    |   18 +++---------------

 2 files changed, 4 insertions(+), 16 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -1
index 525ba59..79576da 100644
@@ -43,8 +43,8 @@
 
  struct cifs_sb_info {
        struct radix_tree_root tlink_tree;
-#define CIFS_TLINK_MASTER_TAG          0       /* is "master" (mount) tcon */
        spinlock_t tlink_tree_lock;
+       struct tcon_link *master_tlink;
        struct nls_table *local_nls;
        unsigned int rsize;
        unsigned int wsize;
fs/cifs/connect.c +2 -2
index 469c3dd..364eb96 100644
@@ -2917,11 +2917,11 @@ remote_path_check:
 
        spin_lock(&cifs_sb->tlink_tree_lock);
        radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink);
-       radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
-                          CIFS_TLINK_MASTER_TAG);
        spin_unlock(&cifs_sb->tlink_tree_lock);
        radix_tree_preload_end();
 
+       cifs_sb->master_tlink = tlink;
+
        queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
                                TLINK_IDLE_EXPIRE);
 
@@ -3275,19 +3275,7 @@ out:

 static struct tcon_link * cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) {
-       struct tcon_link *tlink;
-       unsigned int ret;

fs/cifs/connect.c +0 -8
-
-       spin_lock(&cifs_sb->tlink_tree_lock);
-       ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
-                                       0, 1, CIFS_TLINK_MASTER_TAG);
-       spin_unlock(&cifs_sb->tlink_tree_lock);
-
-       /* the master tcon should always be present */
-       if (ret == 0)
Quoted 9 lines
Quoted 4 lines

-               BUG();
-
-       return tlink;
+       return cifs_sb->master_tlink;

Wondering whether we need a function just to return master_tlink within a cifs_sb.
Could the caller(s) of cifs_sb_master_tlink() access master_tlink directly?

Quoted 4 lines

Sure, but accessor functions are generally a good thing. It insulates the callers from needing to know anything about the underlying data structure.

Quoted 6 lines

What may make some sense however is turning this function into a static inline or macro. Thoughts?

--
Jeff Layton <[email protected]>

I think inline function would be my preferred choice.

#11 lore raw

PATCH 2/2 cifs: convert tlink_tree to a rbtree

In reply to a message not in the archive

Radix trees are ideal when you want to track a bunch of pointers and can't embed a tracking structure within the target of those pointers. The tradeoff is an increase in memory, particularly if the tree is sparse.

In CIFS, we use the tlink_tree to track tcon_link structs. A tcon_link can never be in more than one tlink_tree, so there's no impediment to using a rb_tree here instead of a radix tree.

Convert the new multiuser mount code to use a rb_tree instead. This should reduce the memory required to manage the tlink_tree.

---
 fs/cifs/cifs_fs_sb.h |    4 +-
 fs/cifs/cifsfs.c     |    2 +-
 fs/cifs/cifsglob.h   |    3 +-
 fs/cifs/connect.c    |  177 +++++++++++++++++++++++++++-----------------------
 4 files changed, 101 insertions(+), 85 deletions(-)
fs/cifs/cifs_fs_sb.h +2 -2
index 79576da..e9a393c 100644
@@ -15,7 +15,7 @@
  *   the GNU Lesser General Public License for more details.
  *
  */
-#include <linux/radix-tree.h>
+#include <linux/rbtree.h>
 
 #ifndef _CIFS_FS_SB_H
 #define _CIFS_FS_SB_H
@@ -42,7 +42,7 @@
 #define CIFS_MOUNT_MULTIUSER	0x20000 /* multiuser mount */
 
 struct cifs_sb_info {
-	struct radix_tree_root tlink_tree;
+	struct rb_root tlink_tree;
 	spinlock_t tlink_tree_lock;
 	struct tcon_link *master_tlink;
 	struct nls_table *local_nls;
fs/cifs/cifsfs.c +1 -1
index 17baeab..c5f136c 100644
@@ -116,7 +116,7 @@ cifs_read_super(struct super_block *sb, void *data,
 		return -ENOMEM;
 
 	spin_lock_init(&cifs_sb->tlink_tree_lock);
-	INIT_RADIX_TREE(&cifs_sb->tlink_tree, GFP_KERNEL);
+	cifs_sb->tlink_tree = RB_ROOT;
 
 	rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY);
 	if (rc) {
fs/cifs/cifsglob.h +2 -1
index ab94982..4434d5d 100644
@@ -338,7 +338,8 @@ struct cifsTconInfo {
  * "get" on the container.
  */
 struct tcon_link {
-	unsigned long		tl_index;
+	struct rb_node		tl_rbnode;
+	uid_t			tl_uid;
 	unsigned long		tl_flags;
 #define TCON_LINK_MASTER	0
 #define TCON_LINK_PENDING	1
fs/cifs/connect.c +96 -81

253 lines not on this page · raw message

Signature · 1 line
1.7.2.3