mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
fuse: move background queuing related members to fuse_chan
Move: - max_background - num_background - active_background - bg_queue - bg_lock Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
parent
4e0de84063
commit
2b07cbc4e4
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_dev_i.h"
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
|
|
@ -111,7 +112,7 @@ static ssize_t fuse_conn_max_background_read(struct file *file,
|
|||
if (!fc)
|
||||
return 0;
|
||||
|
||||
val = READ_ONCE(fc->max_background);
|
||||
val = READ_ONCE(fc->chan->max_background);
|
||||
fuse_conn_put(fc);
|
||||
|
||||
return fuse_conn_limit_read(file, buf, len, ppos, val);
|
||||
|
|
@ -129,12 +130,12 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
|
|||
if (ret > 0) {
|
||||
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
|
||||
if (fc) {
|
||||
spin_lock(&fc->bg_lock);
|
||||
fc->max_background = val;
|
||||
fc->blocked = fc->num_background >= fc->max_background;
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fc->chan->max_background = val;
|
||||
fc->blocked = fc->chan->num_background >= fc->chan->max_background;
|
||||
if (!fc->blocked)
|
||||
wake_up(&fc->blocked_waitq);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
fuse_conn_put(fc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,10 +181,10 @@ static void fuse_put_request(struct fuse_req *req)
|
|||
* We get here in the unlikely case that a background
|
||||
* request was allocated but not sent
|
||||
*/
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
if (!fc->blocked)
|
||||
wake_up(&fc->blocked_waitq);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
}
|
||||
|
||||
if (test_bit(FR_WAITING, &req->flags)) {
|
||||
|
|
@ -355,6 +355,9 @@ struct fuse_chan *fuse_chan_new(void)
|
|||
return NULL;
|
||||
|
||||
INIT_LIST_HEAD(&fch->devices);
|
||||
spin_lock_init(&fch->bg_lock);
|
||||
INIT_LIST_HEAD(&fch->bg_queue);
|
||||
fch->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
|
||||
|
||||
return fch;
|
||||
}
|
||||
|
|
@ -489,23 +492,23 @@ static void flush_bg_queue(struct fuse_conn *fc)
|
|||
{
|
||||
struct fuse_iqueue *fiq = &fc->chan->iq;
|
||||
|
||||
while (fc->active_background < fc->max_background &&
|
||||
!list_empty(&fc->bg_queue)) {
|
||||
while (fc->chan->active_background < fc->chan->max_background &&
|
||||
!list_empty(&fc->chan->bg_queue)) {
|
||||
struct fuse_req *req;
|
||||
|
||||
req = list_first_entry(&fc->bg_queue, struct fuse_req, list);
|
||||
req = list_first_entry(&fc->chan->bg_queue, struct fuse_req, list);
|
||||
list_del(&req->list);
|
||||
fc->active_background++;
|
||||
fc->chan->active_background++;
|
||||
fuse_send_one(fiq, req);
|
||||
}
|
||||
}
|
||||
|
||||
void fuse_request_bg_finish(struct fuse_conn *fc, struct fuse_req *req)
|
||||
{
|
||||
lockdep_assert_held(&fc->bg_lock);
|
||||
lockdep_assert_held(&fc->chan->bg_lock);
|
||||
|
||||
clear_bit(FR_BACKGROUND, &req->flags);
|
||||
if (fc->num_background == fc->max_background) {
|
||||
if (fc->chan->num_background == fc->chan->max_background) {
|
||||
fc->blocked = 0;
|
||||
wake_up(&fc->blocked_waitq);
|
||||
} else if (!fc->blocked) {
|
||||
|
|
@ -519,8 +522,8 @@ void fuse_request_bg_finish(struct fuse_conn *fc, struct fuse_req *req)
|
|||
wake_up(&fc->blocked_waitq);
|
||||
}
|
||||
|
||||
fc->num_background--;
|
||||
fc->active_background--;
|
||||
fc->chan->num_background--;
|
||||
fc->chan->active_background--;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -554,10 +557,10 @@ void fuse_request_end(struct fuse_req *req)
|
|||
WARN_ON(test_bit(FR_PENDING, &req->flags));
|
||||
WARN_ON(test_bit(FR_SENT, &req->flags));
|
||||
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fuse_request_bg_finish(fc, req);
|
||||
flush_bg_queue(fc);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
} else {
|
||||
/* Wake up waiter sleeping in request_wait_answer() */
|
||||
wake_up(&req->waitq);
|
||||
|
|
@ -803,16 +806,16 @@ static int fuse_request_queue_background(struct fuse_req *req)
|
|||
return fuse_request_queue_background_uring(fc, req);
|
||||
#endif
|
||||
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
if (likely(fc->connected)) {
|
||||
fc->num_background++;
|
||||
if (fc->num_background == fc->max_background)
|
||||
fc->chan->num_background++;
|
||||
if (fc->chan->num_background == fc->chan->max_background)
|
||||
fc->blocked = 1;
|
||||
list_add_tail(&req->list, &fc->bg_queue);
|
||||
list_add_tail(&req->list, &fc->chan->bg_queue);
|
||||
flush_bg_queue(fc);
|
||||
queued = true;
|
||||
}
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
|
||||
return queued;
|
||||
}
|
||||
|
|
@ -2534,9 +2537,9 @@ void fuse_abort_conn(struct fuse_conn *fc)
|
|||
cancel_delayed_work(&fc->timeout.work);
|
||||
|
||||
/* Background queuing checks fc->connected under bg_lock */
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fc->connected = 0;
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
|
||||
fuse_set_initialized(fc);
|
||||
list_for_each_entry(fud, &fc->chan->devices, entry) {
|
||||
|
|
@ -2560,11 +2563,11 @@ void fuse_abort_conn(struct fuse_conn *fc)
|
|||
&to_end);
|
||||
spin_unlock(&fpq->lock);
|
||||
}
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fc->blocked = 0;
|
||||
fc->max_background = UINT_MAX;
|
||||
fc->chan->max_background = UINT_MAX;
|
||||
flush_bg_queue(fc);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
|
||||
spin_lock(&fiq->lock);
|
||||
fiq->connected = 0;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include <linux/cleanup.h>
|
||||
|
||||
/** Maximum number of outstanding background requests */
|
||||
#define FUSE_DEFAULT_MAX_BACKGROUND 12
|
||||
|
||||
struct fuse_conn;
|
||||
struct fuse_chan;
|
||||
struct fuse_dev;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ static void fuse_uring_flush_bg(struct fuse_ring_queue *queue)
|
|||
struct fuse_conn *fc = ring->fc;
|
||||
|
||||
lockdep_assert_held(&queue->lock);
|
||||
lockdep_assert_held(&fc->bg_lock);
|
||||
lockdep_assert_held(&fc->chan->bg_lock);
|
||||
|
||||
/*
|
||||
* Allow one bg request per queue, ignoring global fc limits.
|
||||
|
|
@ -62,14 +62,14 @@ static void fuse_uring_flush_bg(struct fuse_ring_queue *queue)
|
|||
* eliminates the need for remote queue wake-ups when global
|
||||
* limits are met but this queue has no more waiting requests.
|
||||
*/
|
||||
while ((fc->active_background < fc->max_background ||
|
||||
while ((fc->chan->active_background < fc->chan->max_background ||
|
||||
!queue->active_background) &&
|
||||
(!list_empty(&queue->fuse_req_bg_queue))) {
|
||||
struct fuse_req *req;
|
||||
|
||||
req = list_first_entry(&queue->fuse_req_bg_queue,
|
||||
struct fuse_req, list);
|
||||
fc->active_background++;
|
||||
fc->chan->active_background++;
|
||||
queue->active_background++;
|
||||
|
||||
list_move_tail(&req->list, &queue->fuse_req_queue);
|
||||
|
|
@ -89,10 +89,10 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, struct fuse_req *req,
|
|||
list_del_init(&req->list);
|
||||
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
||||
queue->active_background--;
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fuse_request_bg_finish(fc, req);
|
||||
fuse_uring_flush_bg(queue);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
}
|
||||
|
||||
spin_unlock(&queue->lock);
|
||||
|
|
@ -131,12 +131,12 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring)
|
|||
if (!queue)
|
||||
continue;
|
||||
|
||||
WARN_ON_ONCE(ring->fc->max_background != UINT_MAX);
|
||||
WARN_ON_ONCE(ring->fc->chan->max_background != UINT_MAX);
|
||||
spin_lock(&queue->lock);
|
||||
queue->stopped = true;
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fuse_uring_flush_bg(queue);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
spin_unlock(&queue->lock);
|
||||
fuse_uring_abort_end_queue_requests(queue);
|
||||
}
|
||||
|
|
@ -1370,12 +1370,12 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req)
|
|||
|
||||
ent = list_first_entry_or_null(&queue->ent_avail_queue,
|
||||
struct fuse_ring_ent, list);
|
||||
spin_lock(&fc->bg_lock);
|
||||
fc->num_background++;
|
||||
if (fc->num_background == fc->max_background)
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
fc->chan->num_background++;
|
||||
if (fc->chan->num_background == fc->chan->max_background)
|
||||
fc->blocked = 1;
|
||||
fuse_uring_flush_bg(queue);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
|
||||
/*
|
||||
* Due to bg_queue flush limits there might be other bg requests
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_dev_i.h"
|
||||
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/slab.h>
|
||||
|
|
@ -908,7 +909,7 @@ static int fuse_handle_readahead(struct folio *folio,
|
|||
ia = NULL;
|
||||
}
|
||||
if (!ia) {
|
||||
if (fc->num_background >= fc->congestion_threshold &&
|
||||
if (fc->chan->num_background >= fc->congestion_threshold &&
|
||||
rac->ra->async_size >= readahead_count(rac))
|
||||
/*
|
||||
* Congested and only async pages left, so skip the
|
||||
|
|
@ -2300,7 +2301,7 @@ static int fuse_writepages(struct address_space *mapping,
|
|||
return -EIO;
|
||||
|
||||
if (wbc->sync_mode == WB_SYNC_NONE &&
|
||||
fc->num_background >= fc->congestion_threshold)
|
||||
fc->chan->num_background >= fc->congestion_threshold)
|
||||
return 0;
|
||||
|
||||
return iomap_writepages(&wpc);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,21 @@ struct fuse_chan {
|
|||
|
||||
/** List of device instances belonging to this connection */
|
||||
struct list_head devices;
|
||||
|
||||
/** Maximum number of outstanding background requests */
|
||||
unsigned max_background;
|
||||
|
||||
/** Number of requests currently in the background */
|
||||
unsigned num_background;
|
||||
|
||||
/** Number of background requests currently queued for userspace */
|
||||
unsigned active_background;
|
||||
|
||||
/** The list of background requests set aside for later queuing */
|
||||
struct list_head bg_queue;
|
||||
|
||||
/** Protects: max_background, num_background, active_background, bg_queue, blocked */
|
||||
spinlock_t bg_lock;
|
||||
};
|
||||
|
||||
#define FUSE_PQ_HASH_BITS 8
|
||||
|
|
|
|||
|
|
@ -566,25 +566,9 @@ struct fuse_conn {
|
|||
/** rbtree of fuse_files waiting for poll events indexed by ph */
|
||||
struct rb_root polled_files;
|
||||
|
||||
/** Maximum number of outstanding background requests */
|
||||
unsigned max_background;
|
||||
|
||||
/** Number of background requests at which congestion starts */
|
||||
unsigned congestion_threshold;
|
||||
|
||||
/** Number of requests currently in the background */
|
||||
unsigned num_background;
|
||||
|
||||
/** Number of background requests currently queued for userspace */
|
||||
unsigned active_background;
|
||||
|
||||
/** The list of background requests set aside for later queuing */
|
||||
struct list_head bg_queue;
|
||||
|
||||
/** Protects: max_background, congestion_threshold, num_background,
|
||||
* active_background, bg_queue, blocked */
|
||||
spinlock_t bg_lock;
|
||||
|
||||
/** Flag indicating that INIT reply has been received. Allocating
|
||||
* any fuse request will be suspended until the flag is set */
|
||||
int initialized;
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@ MODULE_PARM_DESC(max_user_congthresh,
|
|||
|
||||
#define FUSE_DEFAULT_BLKSIZE 512
|
||||
|
||||
/** Maximum number of outstanding background requests */
|
||||
#define FUSE_DEFAULT_MAX_BACKGROUND 12
|
||||
|
||||
/** Congestion starts at 75% of maximum */
|
||||
#define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
|
||||
|
||||
|
|
@ -974,16 +971,13 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
|
|||
{
|
||||
memset(fc, 0, sizeof(*fc));
|
||||
spin_lock_init(&fc->lock);
|
||||
spin_lock_init(&fc->bg_lock);
|
||||
init_rwsem(&fc->killsb);
|
||||
refcount_set(&fc->count, 1);
|
||||
atomic_set(&fc->epoch, 1);
|
||||
INIT_WORK(&fc->epoch_work, fuse_epoch_work);
|
||||
init_waitqueue_head(&fc->blocked_waitq);
|
||||
INIT_LIST_HEAD(&fc->bg_queue);
|
||||
INIT_LIST_HEAD(&fc->entry);
|
||||
atomic_set(&fc->num_waiting, 0);
|
||||
fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
|
||||
fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
|
||||
atomic64_set(&fc->khctr, 0);
|
||||
fc->polled_files = RB_ROOT;
|
||||
|
|
@ -1264,12 +1258,12 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
|
|||
sanitize_global_limit(&max_user_bgreq);
|
||||
sanitize_global_limit(&max_user_congthresh);
|
||||
|
||||
spin_lock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
if (arg->max_background) {
|
||||
fc->max_background = arg->max_background;
|
||||
fc->chan->max_background = arg->max_background;
|
||||
|
||||
if (!cap_sys_admin && fc->max_background > max_user_bgreq)
|
||||
fc->max_background = max_user_bgreq;
|
||||
if (!cap_sys_admin && fc->chan->max_background > max_user_bgreq)
|
||||
fc->chan->max_background = max_user_bgreq;
|
||||
}
|
||||
if (arg->congestion_threshold) {
|
||||
fc->congestion_threshold = arg->congestion_threshold;
|
||||
|
|
@ -1278,7 +1272,7 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
|
|||
fc->congestion_threshold > max_user_congthresh)
|
||||
fc->congestion_threshold = max_user_congthresh;
|
||||
}
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
}
|
||||
|
||||
struct fuse_init_args {
|
||||
|
|
|
|||
|
|
@ -83,9 +83,9 @@ static void fuse_check_timeout(struct work_struct *work)
|
|||
if (expired)
|
||||
goto abort_conn;
|
||||
|
||||
spin_lock(&fc->bg_lock);
|
||||
expired = fuse_request_expired(fc, &fc->bg_queue);
|
||||
spin_unlock(&fc->bg_lock);
|
||||
spin_lock(&fc->chan->bg_lock);
|
||||
expired = fuse_request_expired(fc, &fc->chan->bg_queue);
|
||||
spin_unlock(&fc->chan->bg_lock);
|
||||
if (expired)
|
||||
goto abort_conn;
|
||||
|
||||
|
|
|
|||
|
|
@ -1520,7 +1520,7 @@ static void virtio_fs_send_req(struct fuse_iqueue *fiq, struct fuse_req *req)
|
|||
if (ret == -ENOSPC) {
|
||||
/*
|
||||
* Virtqueue full. Retry submission from worker
|
||||
* context as we might be holding fc->bg_lock.
|
||||
* context as we might be holding fc->chan->bg_lock.
|
||||
*/
|
||||
spin_lock(&fsvq->lock);
|
||||
list_add_tail(&req->list, &fsvq->queued_reqs);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user