aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse
diff options
context:
space:
mode:
authorKirill Tkhai <ktkhai@virtuozzo.com>2018-08-27 11:29:46 -0400
committerMiklos Szeredi <mszeredi@redhat.com>2018-09-28 10:43:22 -0400
commitae2dffa39485c6fd4f22321814c7287c274b473a (patch)
treeae65ad5f3ac4f02fb9f7ba8b7fce89cac5d565bf /fs/fuse
parent2b30a533148af4f3865c0dcd619ad93ab3f4ba52 (diff)
fuse: introduce fc->bg_lock
To reduce contention of fc->lock, this patch introduces bg_lock for protection of fields related to background queue. These are: max_background, congestion_threshold, num_background, active_background, bg_queue and blocked. This allows next patch to make async reads not requiring fc->lock, so async reads and writes will have better performance executed in parallel. Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/fuse')
-rw-r--r--fs/fuse/control.c8
-rw-r--r--fs/fuse/dev.c20
-rw-r--r--fs/fuse/file.c2
-rw-r--r--fs/fuse/fuse_i.h8
-rw-r--r--fs/fuse/inode.c3
5 files changed, 26 insertions, 15 deletions
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index eaa0e2b21623..989df5accaee 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -125,12 +125,12 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
125 if (ret > 0) { 125 if (ret > 0) {
126 struct fuse_conn *fc = fuse_ctl_file_conn_get(file); 126 struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
127 if (fc) { 127 if (fc) {
128 spin_lock(&fc->lock); 128 spin_lock(&fc->bg_lock);
129 fc->max_background = val; 129 fc->max_background = val;
130 fc->blocked = fc->num_background >= fc->max_background; 130 fc->blocked = fc->num_background >= fc->max_background;
131 if (!fc->blocked) 131 if (!fc->blocked)
132 wake_up(&fc->blocked_waitq); 132 wake_up(&fc->blocked_waitq);
133 spin_unlock(&fc->lock); 133 spin_unlock(&fc->bg_lock);
134 fuse_conn_put(fc); 134 fuse_conn_put(fc);
135 } 135 }
136 } 136 }
@@ -171,7 +171,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
171 if (!fc) 171 if (!fc)
172 goto out; 172 goto out;
173 173
174 spin_lock(&fc->lock); 174 spin_lock(&fc->bg_lock);
175 fc->congestion_threshold = val; 175 fc->congestion_threshold = val;
176 if (fc->sb) { 176 if (fc->sb) {
177 if (fc->num_background < fc->congestion_threshold) { 177 if (fc->num_background < fc->congestion_threshold) {
@@ -182,7 +182,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
182 set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); 182 set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC);
183 } 183 }
184 } 184 }
185 spin_unlock(&fc->lock); 185 spin_unlock(&fc->bg_lock);
186 fuse_conn_put(fc); 186 fuse_conn_put(fc);
187out: 187out:
188 return ret; 188 return ret;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 6a7d3b4424e1..d4b9ffc6544d 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -287,10 +287,10 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
287 * We get here in the unlikely case that a background 287 * We get here in the unlikely case that a background
288 * request was allocated but not sent 288 * request was allocated but not sent
289 */ 289 */
290 spin_lock(&fc->lock); 290 spin_lock(&fc->bg_lock);
291 if (!fc->blocked) 291 if (!fc->blocked)
292 wake_up(&fc->blocked_waitq); 292 wake_up(&fc->blocked_waitq);
293 spin_unlock(&fc->lock); 293 spin_unlock(&fc->bg_lock);
294 } 294 }
295 295
296 if (test_bit(FR_WAITING, &req->flags)) { 296 if (test_bit(FR_WAITING, &req->flags)) {
@@ -390,7 +390,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
390 WARN_ON(test_bit(FR_PENDING, &req->flags)); 390 WARN_ON(test_bit(FR_PENDING, &req->flags));
391 WARN_ON(test_bit(FR_SENT, &req->flags)); 391 WARN_ON(test_bit(FR_SENT, &req->flags));
392 if (test_bit(FR_BACKGROUND, &req->flags)) { 392 if (test_bit(FR_BACKGROUND, &req->flags)) {
393 spin_lock(&fc->lock); 393 spin_lock(&fc->bg_lock);
394 clear_bit(FR_BACKGROUND, &req->flags); 394 clear_bit(FR_BACKGROUND, &req->flags);
395 if (fc->num_background == fc->max_background) { 395 if (fc->num_background == fc->max_background) {
396 fc->blocked = 0; 396 fc->blocked = 0;
@@ -413,7 +413,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
413 fc->num_background--; 413 fc->num_background--;
414 fc->active_background--; 414 fc->active_background--;
415 flush_bg_queue(fc); 415 flush_bg_queue(fc);
416 spin_unlock(&fc->lock); 416 spin_unlock(&fc->bg_lock);
417 } 417 }
418 wake_up(&req->waitq); 418 wake_up(&req->waitq);
419 if (req->end) 419 if (req->end)
@@ -586,8 +586,8 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
586 * 586 *
587 * fc->connected must have been checked previously 587 * fc->connected must have been checked previously
588 */ 588 */
589void fuse_request_send_background_locked(struct fuse_conn *fc, 589void fuse_request_send_background_nocheck(struct fuse_conn *fc,
590 struct fuse_req *req) 590 struct fuse_req *req)
591{ 591{
592 BUG_ON(!test_bit(FR_BACKGROUND, &req->flags)); 592 BUG_ON(!test_bit(FR_BACKGROUND, &req->flags));
593 if (!test_bit(FR_WAITING, &req->flags)) { 593 if (!test_bit(FR_WAITING, &req->flags)) {
@@ -595,6 +595,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc,
595 atomic_inc(&fc->num_waiting); 595 atomic_inc(&fc->num_waiting);
596 } 596 }
597 __set_bit(FR_ISREPLY, &req->flags); 597 __set_bit(FR_ISREPLY, &req->flags);
598 spin_lock(&fc->bg_lock);
598 fc->num_background++; 599 fc->num_background++;
599 if (fc->num_background == fc->max_background) 600 if (fc->num_background == fc->max_background)
600 fc->blocked = 1; 601 fc->blocked = 1;
@@ -604,6 +605,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc,
604 } 605 }
605 list_add_tail(&req->list, &fc->bg_queue); 606 list_add_tail(&req->list, &fc->bg_queue);
606 flush_bg_queue(fc); 607 flush_bg_queue(fc);
608 spin_unlock(&fc->bg_lock);
607} 609}
608 610
609void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req) 611void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
@@ -611,7 +613,7 @@ void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
611 BUG_ON(!req->end); 613 BUG_ON(!req->end);
612 spin_lock(&fc->lock); 614 spin_lock(&fc->lock);
613 if (fc->connected) { 615 if (fc->connected) {
614 fuse_request_send_background_locked(fc, req); 616 fuse_request_send_background_nocheck(fc, req);
615 spin_unlock(&fc->lock); 617 spin_unlock(&fc->lock);
616 } else { 618 } else {
617 spin_unlock(&fc->lock); 619 spin_unlock(&fc->lock);
@@ -2118,7 +2120,6 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
2118 LIST_HEAD(to_end); 2120 LIST_HEAD(to_end);
2119 2121
2120 fc->connected = 0; 2122 fc->connected = 0;
2121 fc->blocked = 0;
2122 fc->aborted = is_abort; 2123 fc->aborted = is_abort;
2123 fuse_set_initialized(fc); 2124 fuse_set_initialized(fc);
2124 list_for_each_entry(fud, &fc->devices, entry) { 2125 list_for_each_entry(fud, &fc->devices, entry) {
@@ -2140,8 +2141,11 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
2140 list_splice_tail_init(&fpq->processing, &to_end); 2141 list_splice_tail_init(&fpq->processing, &to_end);
2141 spin_unlock(&fpq->lock); 2142 spin_unlock(&fpq->lock);
2142 } 2143 }
2144 spin_lock(&fc->bg_lock);
2145 fc->blocked = 0;
2143 fc->max_background = UINT_MAX; 2146 fc->max_background = UINT_MAX;
2144 flush_bg_queue(fc); 2147 flush_bg_queue(fc);
2148 spin_unlock(&fc->bg_lock);
2145 2149
2146 spin_lock(&fiq->waitq.lock); 2150 spin_lock(&fiq->waitq.lock);
2147 fiq->connected = 0; 2151 fiq->connected = 0;
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 63136a2c23ab..65351d43c2b6 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1502,7 +1502,7 @@ __acquires(fc->lock)
1502 1502
1503 req->in.args[1].size = inarg->size; 1503 req->in.args[1].size = inarg->size;
1504 fi->writectr++; 1504 fi->writectr++;
1505 fuse_request_send_background_locked(fc, req); 1505 fuse_request_send_background_nocheck(fc, req);
1506 return; 1506 return;
1507 1507
1508 out_free: 1508 out_free:
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 3e45d408a644..d6d55641a5a6 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -500,6 +500,10 @@ struct fuse_conn {
500 /** The list of background requests set aside for later queuing */ 500 /** The list of background requests set aside for later queuing */
501 struct list_head bg_queue; 501 struct list_head bg_queue;
502 502
503 /** Protects: max_background, congestion_threshold, num_background,
504 * active_background, bg_queue, blocked */
505 spinlock_t bg_lock;
506
503 /** Flag indicating that INIT reply has been received. Allocating 507 /** Flag indicating that INIT reply has been received. Allocating
504 * any fuse request will be suspended until the flag is set */ 508 * any fuse request will be suspended until the flag is set */
505 int initialized; 509 int initialized;
@@ -860,8 +864,8 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
860 */ 864 */
861void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 865void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
862 866
863void fuse_request_send_background_locked(struct fuse_conn *fc, 867void fuse_request_send_background_nocheck(struct fuse_conn *fc,
864 struct fuse_req *req); 868 struct fuse_req *req);
865 869
866/* Abort all requests */ 870/* Abort all requests */
867void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 871void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index db9e60b7eb69..ed3f49628ce2 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -605,6 +605,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns)
605{ 605{
606 memset(fc, 0, sizeof(*fc)); 606 memset(fc, 0, sizeof(*fc));
607 spin_lock_init(&fc->lock); 607 spin_lock_init(&fc->lock);
608 spin_lock_init(&fc->bg_lock);
608 init_rwsem(&fc->killsb); 609 init_rwsem(&fc->killsb);
609 refcount_set(&fc->count, 1); 610 refcount_set(&fc->count, 1);
610 atomic_set(&fc->dev_count, 1); 611 atomic_set(&fc->dev_count, 1);
@@ -852,6 +853,7 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
852 sanitize_global_limit(&max_user_bgreq); 853 sanitize_global_limit(&max_user_bgreq);
853 sanitize_global_limit(&max_user_congthresh); 854 sanitize_global_limit(&max_user_congthresh);
854 855
856 spin_lock(&fc->bg_lock);
855 if (arg->max_background) { 857 if (arg->max_background) {
856 fc->max_background = arg->max_background; 858 fc->max_background = arg->max_background;
857 859
@@ -865,6 +867,7 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
865 fc->congestion_threshold > max_user_congthresh) 867 fc->congestion_threshold > max_user_congthresh)
866 fc->congestion_threshold = max_user_congthresh; 868 fc->congestion_threshold = max_user_congthresh;
867 } 869 }
870 spin_unlock(&fc->bg_lock);
868} 871}
869 872
870static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) 873static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)