Skip to content

Commit be2ff42

Browse files
Kirill TkhaiMiklos Szeredi
authored andcommitted
fuse: Use hash table to link processing request
We noticed the performance bottleneck in FUSE running our Virtuozzo storage over rdma. On some types of workload we observe 20% of times spent in request_find() in profiler. This function is iterating over long requests list, and it scales bad. The patch introduces hash table to reduce the number of iterations, we do in this function. Hash generating algorithm is taken from hash_add() function, while 256 lines table is used to store pending requests. This fixes problem and improves the performance. Reported-by: Alexey Kuznetsov <kuznet@virtuozzo.com> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 3a5358d commit be2ff42

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

‎fs/fuse/dev.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ static u64 fuse_get_unique(struct fuse_iqueue *fiq)
327327
return fiq->reqctr;
328328
}
329329

330+
static unsigned int fuse_req_hash(u64 unique)
331+
{
332+
return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
333+
}
334+
330335
static void queue_request(struct fuse_iqueue *fiq, struct fuse_req *req)
331336
{
332337
req->in.h.len = sizeof(struct fuse_in_header) +
@@ -1248,6 +1253,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
12481253
struct fuse_req *req;
12491254
struct fuse_in *in;
12501255
unsigned reqsize;
1256+
unsigned int hash;
12511257

12521258
restart:
12531259
spin_lock(&fiq->waitq.lock);
@@ -1320,7 +1326,8 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
13201326
err = reqsize;
13211327
goto out_end;
13221328
}
1323-
list_move_tail(&req->list, &fpq->processing);
1329+
hash = fuse_req_hash(req->in.h.unique);
1330+
list_move_tail(&req->list, &fpq->processing[hash]);
13241331
__fuse_get_request(req);
13251332
set_bit(FR_SENT, &req->flags);
13261333
spin_unlock(&fpq->lock);
@@ -1804,9 +1811,10 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
18041811
/* Look up request on processing list by unique ID */
18051812
static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique)
18061813
{
1814+
unsigned int hash = fuse_req_hash(unique);
18071815
struct fuse_req *req;
18081816

1809-
list_for_each_entry(req, &fpq->processing, list) {
1817+
list_for_each_entry(req, &fpq->processing[hash], list) {
18101818
if (req->in.h.unique == unique)
18111819
return req;
18121820
}
@@ -2118,6 +2126,7 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
21182126
struct fuse_dev *fud;
21192127
struct fuse_req *req, *next;
21202128
LIST_HEAD(to_end);
2129+
unsigned int i;
21212130

21222131
/* Background queuing checks fc->connected under bg_lock */
21232132
spin_lock(&fc->bg_lock);
@@ -2142,7 +2151,9 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
21422151
}
21432152
spin_unlock(&req->waitq.lock);
21442153
}
2145-
list_splice_tail_init(&fpq->processing, &to_end);
2154+
for (i = 0; i < FUSE_PQ_HASH_SIZE; i++)
2155+
list_splice_tail_init(&fpq->processing[i],
2156+
&to_end);
21462157
spin_unlock(&fpq->lock);
21472158
}
21482159
spin_lock(&fc->bg_lock);
@@ -2185,10 +2196,12 @@ int fuse_dev_release(struct inode *inode, struct file *file)
21852196
struct fuse_conn *fc = fud->fc;
21862197
struct fuse_pqueue *fpq = &fud->pq;
21872198
LIST_HEAD(to_end);
2199+
unsigned int i;
21882200

21892201
spin_lock(&fpq->lock);
21902202
WARN_ON(!list_empty(&fpq->io));
2191-
list_splice_init(&fpq->processing, &to_end);
2203+
for (i = 0; i < FUSE_PQ_HASH_SIZE; i++)
2204+
list_splice_init(&fpq->processing[i], &to_end);
21922205
spin_unlock(&fpq->lock);
21932206

21942207
end_requests(fc, &to_end);

‎fs/fuse/fuse_i.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,18 @@ struct fuse_iqueue {
408408
struct fasync_struct *fasync;
409409
};
410410

411+
#define FUSE_PQ_HASH_BITS 8
412+
#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
413+
411414
struct fuse_pqueue {
412415
/** Connection established */
413416
unsigned connected;
414417

415418
/** Lock protecting accessess to members of this structure */
416419
spinlock_t lock;
417420

418-
/** The list of requests being processed */
419-
struct list_head processing;
421+
/** Hash table of requests being processed */
422+
struct list_head *processing;
420423

421424
/** The list of requests under I/O */
422425
struct list_head io;

‎fs/fuse/inode.c‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,11 @@ static void fuse_iqueue_init(struct fuse_iqueue *fiq)
594594

595595
static void fuse_pqueue_init(struct fuse_pqueue *fpq)
596596
{
597-
memset(fpq, 0, sizeof(struct fuse_pqueue));
597+
unsigned int i;
598+
598599
spin_lock_init(&fpq->lock);
599-
INIT_LIST_HEAD(&fpq->processing);
600+
for (i = 0; i < FUSE_PQ_HASH_SIZE; i++)
601+
INIT_LIST_HEAD(&fpq->processing[i]);
600602
INIT_LIST_HEAD(&fpq->io);
601603
fpq->connected = 1;
602604
}
@@ -1025,17 +1027,26 @@ static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb)
10251027
struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc)
10261028
{
10271029
struct fuse_dev *fud;
1030+
struct list_head *pq;
10281031

10291032
fud = kzalloc(sizeof(struct fuse_dev), GFP_KERNEL);
1030-
if (fud) {
1031-
fud->fc = fuse_conn_get(fc);
1032-
fuse_pqueue_init(&fud->pq);
1033+
if (!fud)
1034+
return NULL;
10331035

1034-
spin_lock(&fc->lock);
1035-
list_add_tail(&fud->entry, &fc->devices);
1036-
spin_unlock(&fc->lock);
1036+
pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);
1037+
if (!pq) {
1038+
kfree(fud);
1039+
return NULL;
10371040
}
10381041

1042+
fud->pq.processing = pq;
1043+
fud->fc = fuse_conn_get(fc);
1044+
fuse_pqueue_init(&fud->pq);
1045+
1046+
spin_lock(&fc->lock);
1047+
list_add_tail(&fud->entry, &fc->devices);
1048+
spin_unlock(&fc->lock);
1049+
10391050
return fud;
10401051
}
10411052
EXPORT_SYMBOL_GPL(fuse_dev_alloc);

0 commit comments

Comments
 (0)