Skip to content

Commit 85ff03f

Browse files
committed
ceph: use rbtree for mon statfs requests
An rbtree is lighter weight, particularly given we will generally have very few in-flight statfs requests. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent a105f00 commit 85ff03f

3 files changed

Lines changed: 54 additions & 32 deletions

File tree

‎fs/ceph/debugfs.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ static int monc_show(struct seq_file *s, void *p)
112112
{
113113
struct ceph_client *client = s->private;
114114
struct ceph_mon_statfs_request *req;
115-
u64 nexttid = 0;
116-
int got;
117115
struct ceph_mon_client *monc = &client->monc;
116+
struct rb_node *rp;
118117

119118
mutex_lock(&monc->mutex);
120119

@@ -125,17 +124,12 @@ static int monc_show(struct seq_file *s, void *p)
125124
if (monc->want_next_osdmap)
126125
seq_printf(s, "want next osdmap\n");
127126

128-
while (nexttid < monc->last_tid) {
129-
got = radix_tree_gang_lookup(&monc->statfs_request_tree,
130-
(void **)&req, nexttid, 1);
131-
if (got == 0)
132-
break;
133-
nexttid = req->tid + 1;
134-
127+
for (rp = rb_first(&monc->statfs_request_tree); rp; rp = rb_next(rp)) {
128+
req = rb_entry(rp, struct ceph_mon_statfs_request, node);
135129
seq_printf(s, "%lld statfs\n", req->tid);
136130
}
137-
mutex_unlock(&monc->mutex);
138131

132+
mutex_unlock(&monc->mutex);
139133
return 0;
140134
}
141135

‎fs/ceph/mon_client.c‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,46 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc,
343343
/*
344344
* statfs
345345
*/
346+
static struct ceph_mon_statfs_request *__lookup_statfs(
347+
struct ceph_mon_client *monc, u64 tid)
348+
{
349+
struct ceph_mon_statfs_request *req;
350+
struct rb_node *n = monc->statfs_request_tree.rb_node;
351+
352+
while (n) {
353+
req = rb_entry(n, struct ceph_mon_statfs_request, node);
354+
if (tid < req->tid)
355+
n = n->rb_left;
356+
else if (tid > req->tid)
357+
n = n->rb_right;
358+
else
359+
return req;
360+
}
361+
return NULL;
362+
}
363+
364+
static void __insert_statfs(struct ceph_mon_client *monc,
365+
struct ceph_mon_statfs_request *new)
366+
{
367+
struct rb_node **p = &monc->statfs_request_tree.rb_node;
368+
struct rb_node *parent = NULL;
369+
struct ceph_mon_statfs_request *req = NULL;
370+
371+
while (*p) {
372+
parent = *p;
373+
req = rb_entry(parent, struct ceph_mon_statfs_request, node);
374+
if (new->tid < req->tid)
375+
p = &(*p)->rb_left;
376+
else if (new->tid > req->tid)
377+
p = &(*p)->rb_right;
378+
else
379+
BUG();
380+
}
381+
382+
rb_link_node(&new->node, parent, p);
383+
rb_insert_color(&new->node, &monc->statfs_request_tree);
384+
}
385+
346386
static void handle_statfs_reply(struct ceph_mon_client *monc,
347387
struct ceph_msg *msg)
348388
{
@@ -356,7 +396,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc,
356396
dout("handle_statfs_reply %p tid %llu\n", msg, tid);
357397

358398
mutex_lock(&monc->mutex);
359-
req = radix_tree_lookup(&monc->statfs_request_tree, tid);
399+
req = __lookup_statfs(monc, tid);
360400
if (req) {
361401
*req->buf = reply->st;
362402
req->result = 0;
@@ -416,11 +456,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
416456
req.tid = ++monc->last_tid;
417457
req.last_attempt = jiffies;
418458
req.delay = BASE_DELAY_INTERVAL;
419-
if (radix_tree_insert(&monc->statfs_request_tree, req.tid, &req) < 0) {
420-
mutex_unlock(&monc->mutex);
421-
pr_err("ENOMEM in do_statfs\n");
422-
return -ENOMEM;
423-
}
459+
__insert_statfs(monc, &req);
424460
monc->num_statfs_requests++;
425461
mutex_unlock(&monc->mutex);
426462

@@ -430,7 +466,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
430466
err = wait_for_completion_interruptible(&req.completion);
431467

432468
mutex_lock(&monc->mutex);
433-
radix_tree_delete(&monc->statfs_request_tree, req.tid);
469+
rb_erase(&req.node, &monc->statfs_request_tree);
434470
monc->num_statfs_requests--;
435471
ceph_msgpool_resv(&monc->msgpool_statfs_reply, -1);
436472
mutex_unlock(&monc->mutex);
@@ -445,20 +481,11 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
445481
*/
446482
static void __resend_statfs(struct ceph_mon_client *monc)
447483
{
448-
u64 next_tid = 0;
449-
int got;
450-
int did = 0;
451484
struct ceph_mon_statfs_request *req;
485+
struct rb_node *p;
452486

453-
while (1) {
454-
got = radix_tree_gang_lookup(&monc->statfs_request_tree,
455-
(void **)&req,
456-
next_tid, 1);
457-
if (got == 0)
458-
break;
459-
did++;
460-
next_tid = req->tid + 1;
461-
487+
for (p = rb_first(&monc->statfs_request_tree); p; p = rb_next(p)) {
488+
req = rb_entry(p, struct ceph_mon_statfs_request, node);
462489
send_statfs(monc, req);
463490
}
464491
}
@@ -578,7 +605,7 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
578605
monc->sub_sent = 0;
579606

580607
INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
581-
INIT_RADIX_TREE(&monc->statfs_request_tree, GFP_NOFS);
608+
monc->statfs_request_tree = RB_ROOT;
582609
monc->num_statfs_requests = 0;
583610
monc->last_tid = 0;
584611

‎fs/ceph/mon_client.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _FS_CEPH_MON_CLIENT_H
33

44
#include <linux/completion.h>
5-
#include <linux/radix-tree.h>
5+
#include <linux/rbtree.h>
66

77
#include "messenger.h"
88
#include "msgpool.h"
@@ -45,6 +45,7 @@ struct ceph_mon_request {
4545
*/
4646
struct ceph_mon_statfs_request {
4747
u64 tid;
48+
struct rb_node node;
4849
int result;
4950
struct ceph_statfs *buf;
5051
struct completion completion;
@@ -75,7 +76,7 @@ struct ceph_mon_client {
7576
struct ceph_msgpool msgpool_auth_reply;
7677

7778
/* pending statfs requests */
78-
struct radix_tree_root statfs_request_tree;
79+
struct rb_root statfs_request_tree;
7980
int num_statfs_requests;
8081
u64 last_tid;
8182

0 commit comments

Comments
 (0)