CIFS: Introduce credit-based flow control
and send no more than credits value requests at once. For SMB/CIFS it's trivial: increment this value by receiving any message and decrement by sending one. Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
Родитель
fc40f9cf82
Коммит
2d86dbc970
|
@ -250,8 +250,9 @@ struct TCP_Server_Info {
|
||||||
bool noblocksnd; /* use blocking sendmsg */
|
bool noblocksnd; /* use blocking sendmsg */
|
||||||
bool noautotune; /* do not autotune send buf sizes */
|
bool noautotune; /* do not autotune send buf sizes */
|
||||||
bool tcp_nodelay;
|
bool tcp_nodelay;
|
||||||
|
int credits; /* send no more requests at once */
|
||||||
unsigned int in_flight; /* number of requests on the wire to server */
|
unsigned int in_flight; /* number of requests on the wire to server */
|
||||||
spinlock_t req_lock; /* protect the value above */
|
spinlock_t req_lock; /* protect the two values above */
|
||||||
struct mutex srv_mutex;
|
struct mutex srv_mutex;
|
||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
char server_GUID[16];
|
char server_GUID[16];
|
||||||
|
@ -314,12 +315,14 @@ in_flight(struct TCP_Server_Info *server)
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline bool
|
||||||
dec_in_flight(struct TCP_Server_Info *server)
|
has_credits(struct TCP_Server_Info *server)
|
||||||
{
|
{
|
||||||
|
int num;
|
||||||
spin_lock(&server->req_lock);
|
spin_lock(&server->req_lock);
|
||||||
server->in_flight--;
|
num = server->credits;
|
||||||
spin_unlock(&server->req_lock);
|
spin_unlock(&server->req_lock);
|
||||||
|
return num > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -88,6 +88,9 @@ extern int SendReceiveBlockingLock(const unsigned int xid,
|
||||||
struct smb_hdr *in_buf ,
|
struct smb_hdr *in_buf ,
|
||||||
struct smb_hdr *out_buf,
|
struct smb_hdr *out_buf,
|
||||||
int *bytes_returned);
|
int *bytes_returned);
|
||||||
|
extern void cifs_add_credits(struct TCP_Server_Info *server,
|
||||||
|
const unsigned int add);
|
||||||
|
extern void cifs_set_credits(struct TCP_Server_Info *server, const int val);
|
||||||
extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length);
|
extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length);
|
||||||
extern bool is_valid_oplock_break(struct smb_hdr *smb,
|
extern bool is_valid_oplock_break(struct smb_hdr *smb,
|
||||||
struct TCP_Server_Info *);
|
struct TCP_Server_Info *);
|
||||||
|
|
|
@ -461,7 +461,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses)
|
||||||
server->maxReq = min_t(unsigned int,
|
server->maxReq = min_t(unsigned int,
|
||||||
le16_to_cpu(rsp->MaxMpxCount),
|
le16_to_cpu(rsp->MaxMpxCount),
|
||||||
cifs_max_pending);
|
cifs_max_pending);
|
||||||
server->oplocks = server->maxReq > 1 ? enable_oplocks : false;
|
cifs_set_credits(server, server->maxReq);
|
||||||
server->maxBuf = le16_to_cpu(rsp->MaxBufSize);
|
server->maxBuf = le16_to_cpu(rsp->MaxBufSize);
|
||||||
server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs);
|
server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs);
|
||||||
/* even though we do not use raw we might as well set this
|
/* even though we do not use raw we might as well set this
|
||||||
|
@ -569,7 +569,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses)
|
||||||
little endian */
|
little endian */
|
||||||
server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount),
|
server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount),
|
||||||
cifs_max_pending);
|
cifs_max_pending);
|
||||||
server->oplocks = server->maxReq > 1 ? enable_oplocks : false;
|
cifs_set_credits(server, server->maxReq);
|
||||||
/* probably no need to store and check maxvcs */
|
/* probably no need to store and check maxvcs */
|
||||||
server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize);
|
server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize);
|
||||||
server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
|
server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
|
||||||
|
@ -721,8 +721,7 @@ cifs_echo_callback(struct mid_q_entry *mid)
|
||||||
struct TCP_Server_Info *server = mid->callback_data;
|
struct TCP_Server_Info *server = mid->callback_data;
|
||||||
|
|
||||||
DeleteMidQEntry(mid);
|
DeleteMidQEntry(mid);
|
||||||
dec_in_flight(server);
|
cifs_add_credits(server, 1);
|
||||||
wake_up(&server->request_q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1674,8 +1673,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
|
||||||
|
|
||||||
queue_work(system_nrt_wq, &rdata->work);
|
queue_work(system_nrt_wq, &rdata->work);
|
||||||
DeleteMidQEntry(mid);
|
DeleteMidQEntry(mid);
|
||||||
dec_in_flight(server);
|
cifs_add_credits(server, 1);
|
||||||
wake_up(&server->request_q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cifs_async_readv - send an async write, and set up mid to handle result */
|
/* cifs_async_readv - send an async write, and set up mid to handle result */
|
||||||
|
@ -2115,8 +2113,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
|
||||||
|
|
||||||
queue_work(system_nrt_wq, &wdata->work);
|
queue_work(system_nrt_wq, &wdata->work);
|
||||||
DeleteMidQEntry(mid);
|
DeleteMidQEntry(mid);
|
||||||
dec_in_flight(tcon->ses->server);
|
cifs_add_credits(tcon->ses->server, 1);
|
||||||
wake_up(&tcon->ses->server->request_q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cifs_async_writev - send an async write, and set up mid to handle result */
|
/* cifs_async_writev - send an async write, and set up mid to handle result */
|
||||||
|
|
|
@ -642,14 +642,10 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
|
||||||
spin_unlock(&GlobalMid_Lock);
|
spin_unlock(&GlobalMid_Lock);
|
||||||
wake_up_all(&server->response_q);
|
wake_up_all(&server->response_q);
|
||||||
|
|
||||||
/* Check if we have blocked requests that need to free. */
|
/* check if we have blocked requests that need to free */
|
||||||
spin_lock(&server->req_lock);
|
spin_lock(&server->req_lock);
|
||||||
if (server->in_flight >= server->maxReq)
|
if (server->credits <= 0)
|
||||||
server->in_flight = server->maxReq - 1;
|
server->credits = 1;
|
||||||
/*
|
|
||||||
* We do not want to set the max_pending too low or we could end up
|
|
||||||
* with the counter going negative.
|
|
||||||
*/
|
|
||||||
spin_unlock(&server->req_lock);
|
spin_unlock(&server->req_lock);
|
||||||
/*
|
/*
|
||||||
* Although there should not be any requests blocked on this queue it
|
* Although there should not be any requests blocked on this queue it
|
||||||
|
@ -1906,7 +1902,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
|
||||||
tcp_ses->noautotune = volume_info->noautotune;
|
tcp_ses->noautotune = volume_info->noautotune;
|
||||||
tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay;
|
tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay;
|
||||||
tcp_ses->in_flight = 0;
|
tcp_ses->in_flight = 0;
|
||||||
tcp_ses->maxReq = 1; /* enough to send negotiate request */
|
tcp_ses->credits = 1;
|
||||||
init_waitqueue_head(&tcp_ses->response_q);
|
init_waitqueue_head(&tcp_ses->response_q);
|
||||||
init_waitqueue_head(&tcp_ses->request_q);
|
init_waitqueue_head(&tcp_ses->request_q);
|
||||||
INIT_LIST_HEAD(&tcp_ses->pending_mid_q);
|
INIT_LIST_HEAD(&tcp_ses->pending_mid_q);
|
||||||
|
@ -3757,9 +3753,11 @@ int cifs_negotiate_protocol(unsigned int xid, struct cifs_ses *ses)
|
||||||
if (server->maxBuf != 0)
|
if (server->maxBuf != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
cifs_set_credits(server, 1);
|
||||||
rc = CIFSSMBNegotiate(xid, ses);
|
rc = CIFSSMBNegotiate(xid, ses);
|
||||||
if (rc == -EAGAIN) {
|
if (rc == -EAGAIN) {
|
||||||
/* retry only once on 1st time connection */
|
/* retry only once on 1st time connection */
|
||||||
|
cifs_set_credits(server, 1);
|
||||||
rc = CIFSSMBNegotiate(xid, ses);
|
rc = CIFSSMBNegotiate(xid, ses);
|
||||||
if (rc == -EAGAIN)
|
if (rc == -EAGAIN)
|
||||||
rc = -EHOSTDOWN;
|
rc = -EHOSTDOWN;
|
||||||
|
|
|
@ -690,3 +690,22 @@ backup_cred(struct cifs_sb_info *cifs_sb)
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add)
|
||||||
|
{
|
||||||
|
spin_lock(&server->req_lock);
|
||||||
|
server->credits += add;
|
||||||
|
server->in_flight--;
|
||||||
|
spin_unlock(&server->req_lock);
|
||||||
|
wake_up(&server->request_q);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cifs_set_credits(struct TCP_Server_Info *server, const int val)
|
||||||
|
{
|
||||||
|
spin_lock(&server->req_lock);
|
||||||
|
server->credits = val;
|
||||||
|
server->oplocks = val > 1 ? enable_oplocks : false;
|
||||||
|
spin_unlock(&server->req_lock);
|
||||||
|
}
|
||||||
|
|
|
@ -262,16 +262,16 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
|
||||||
if (long_op == CIFS_ASYNC_OP) {
|
if (long_op == CIFS_ASYNC_OP) {
|
||||||
/* oplock breaks must not be held up */
|
/* oplock breaks must not be held up */
|
||||||
server->in_flight++;
|
server->in_flight++;
|
||||||
|
server->credits--;
|
||||||
spin_unlock(&server->req_lock);
|
spin_unlock(&server->req_lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (server->in_flight >= server->maxReq) {
|
if (server->credits <= 0) {
|
||||||
spin_unlock(&server->req_lock);
|
spin_unlock(&server->req_lock);
|
||||||
cifs_num_waiters_inc(server);
|
cifs_num_waiters_inc(server);
|
||||||
wait_event(server->request_q,
|
wait_event(server->request_q, has_credits(server));
|
||||||
in_flight(server) < server->maxReq);
|
|
||||||
cifs_num_waiters_dec(server);
|
cifs_num_waiters_dec(server);
|
||||||
spin_lock(&server->req_lock);
|
spin_lock(&server->req_lock);
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,12 +280,16 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* can not count locking commands against total
|
/*
|
||||||
as they are allowed to block on server */
|
* Can not count locking commands against total
|
||||||
|
* as they are allowed to block on server.
|
||||||
|
*/
|
||||||
|
|
||||||
/* update # of requests on the wire to server */
|
/* update # of requests on the wire to server */
|
||||||
if (long_op != CIFS_BLOCKING_OP)
|
if (long_op != CIFS_BLOCKING_OP) {
|
||||||
|
server->credits--;
|
||||||
server->in_flight++;
|
server->in_flight++;
|
||||||
|
}
|
||||||
spin_unlock(&server->req_lock);
|
spin_unlock(&server->req_lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +364,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
|
||||||
mid = AllocMidQEntry(hdr, server);
|
mid = AllocMidQEntry(hdr, server);
|
||||||
if (mid == NULL) {
|
if (mid == NULL) {
|
||||||
mutex_unlock(&server->srv_mutex);
|
mutex_unlock(&server->srv_mutex);
|
||||||
dec_in_flight(server);
|
cifs_add_credits(server, 1);
|
||||||
wake_up(&server->request_q);
|
wake_up(&server->request_q);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +397,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
|
||||||
return rc;
|
return rc;
|
||||||
out_err:
|
out_err:
|
||||||
delete_mid(mid);
|
delete_mid(mid);
|
||||||
dec_in_flight(server);
|
cifs_add_credits(server, 1);
|
||||||
wake_up(&server->request_q);
|
wake_up(&server->request_q);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -565,8 +569,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
|
||||||
mutex_unlock(&ses->server->srv_mutex);
|
mutex_unlock(&ses->server->srv_mutex);
|
||||||
cifs_small_buf_release(in_buf);
|
cifs_small_buf_release(in_buf);
|
||||||
/* Update # of requests on wire to server */
|
/* Update # of requests on wire to server */
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
|
rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
|
||||||
|
@ -602,8 +605,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
|
||||||
midQ->callback = DeleteMidQEntry;
|
midQ->callback = DeleteMidQEntry;
|
||||||
spin_unlock(&GlobalMid_Lock);
|
spin_unlock(&GlobalMid_Lock);
|
||||||
cifs_small_buf_release(in_buf);
|
cifs_small_buf_release(in_buf);
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
spin_unlock(&GlobalMid_Lock);
|
spin_unlock(&GlobalMid_Lock);
|
||||||
|
@ -613,8 +615,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
|
||||||
|
|
||||||
rc = cifs_sync_mid_result(midQ, ses->server);
|
rc = cifs_sync_mid_result(midQ, ses->server);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,8 +639,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
|
||||||
midQ->resp_buf = NULL;
|
midQ->resp_buf = NULL;
|
||||||
out:
|
out:
|
||||||
delete_mid(midQ);
|
delete_mid(midQ);
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -689,8 +689,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
|
||||||
if (rc) {
|
if (rc) {
|
||||||
mutex_unlock(&ses->server->srv_mutex);
|
mutex_unlock(&ses->server->srv_mutex);
|
||||||
/* Update # of requests on wire to server */
|
/* Update # of requests on wire to server */
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,8 +721,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
|
||||||
/* no longer considered to be "in-flight" */
|
/* no longer considered to be "in-flight" */
|
||||||
midQ->callback = DeleteMidQEntry;
|
midQ->callback = DeleteMidQEntry;
|
||||||
spin_unlock(&GlobalMid_Lock);
|
spin_unlock(&GlobalMid_Lock);
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
spin_unlock(&GlobalMid_Lock);
|
spin_unlock(&GlobalMid_Lock);
|
||||||
|
@ -731,8 +729,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
|
||||||
|
|
||||||
rc = cifs_sync_mid_result(midQ, ses->server);
|
rc = cifs_sync_mid_result(midQ, ses->server);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,8 +745,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
|
||||||
rc = cifs_check_receive(midQ, ses->server, 0);
|
rc = cifs_check_receive(midQ, ses->server, 0);
|
||||||
out:
|
out:
|
||||||
delete_mid(midQ);
|
delete_mid(midQ);
|
||||||
dec_in_flight(ses->server);
|
cifs_add_credits(ses->server, 1);
|
||||||
wake_up(&ses->server->request_q);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче