Skip to contentSkip to conversation

cifs: asynchronous writepages support (try #3)

PATCH In review Jeff Layton 3 participants 17 messages May 2, 2011 – May 6, 2011 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cifs: asynchronous writepages support (try #3)

This is the third version of this set. There are a number of changes from the last one:

- WB_SYNC_ALL writepages no longer waits for all of the writes to complete before returning. Instead, if the result of a write is EAGAIN, the write call is resent. This makes cifs writepages work more like writepages does in other filesystems. It also simplifies the writepages code significantly.

- there's a patch that makes the max_pending limit use the value sent in the NEGOTIATE request instead of a hardcoded limit set via a module parameter

This patchset changes the CIFS code to do asynchronous writes in writepages(). It uses the asynchronous call infrastructure that was added to handle SMB echoes. The idea here is to have the kernel issue a write request and then have it handle the reply asynchronously.

For now, this just changes the writepages codepath. Once the patchset has had a bit more refinement and testing, I'll see about changing some of the other codepaths (writepage(), for instance), and maybe adding async readpages support.

I'm not 100% thrilled with this approach overall -- I think we do need to handle writes asynchronously, but the fact that we're using our own writepages routine kind of hamstrings this code.

Another possible approach here would be to move to more page-based I/O like NFS has. Have writepage() set up the pages for writeback and coalesce them together as it goes, and then issue the write all at once. That would also allow us to handle larger write sizes than 56k.

Obviously, that's a much larger project to cobble together however. Much of this code would still be applicable if we did decide to go that route eventually.

This patch is based on Steve's for-2.6.40 branch plus some other patches forward ported on top of it. That branch seems to be a bit out of date though, so once it has been updated, I'll rebase this again to fix up the merge conflicts.

Review and test feedback would be welcome.

Jeff Layton (8):
cifs: consolidate SendReceive response checks
cifs: make cifs_send_async take a kvec array
cifs: don't call mid_q_entry->callback under the Global_MidLock
cifs: add ignore_pend flag to cifs_call_async
cifs: add cifs_async_writev
cifs: convert cifs_writepages to use async writes
cifs: clean up wsize negotiation and allow for larger wsize
cifs: use the server's MaxMpxCount to determine max requests in
flight

 fs/cifs/cifsfs.c        |   12 ---
 fs/cifs/cifsglob.h      |   21 +----
 fs/cifs/cifsproto.h     |   28 +++++-
 fs/cifs/cifssmb.c       |  244 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/cifs/connect.c       |   95 +++++++++++++------
 fs/cifs/file.c          |  224 ++++++++++++++++---------------------------
 fs/cifs/netmisc.c       |    2 +-
 fs/cifs/smb2transport.c |   14 +--
 fs/cifs/transport.c     |  203 ++++++++++++---------------------------
 9 files changed, 486 insertions(+), 357 deletions(-)
Signature · 1 line
1.7.4.4

A message that is not in the archive (sent off-list or not yet received): 1304345069-2441-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/8 cifs: consolidate SendReceive response checks

Further consolidate the SendReceive code by moving the checks run over the packet into a separate function that all the SendReceive variants can call.

We can also eliminate the check for a receive_len that's too big or too small. cifs_demultiplex_thread already checks that and disconnects the socket if that occurs, while setting the midStatus to MALFORMED. It'll never call this code if that's the case.

Finally do a little cleanup. Use "goto out" on errors so that the flow of code in the normal case is more evident. Also switch the logErr variable in map_smb_to_linux_error to a bool.

---
 fs/cifs/cifsproto.h |    4 +-
 fs/cifs/netmisc.c   |    2 +-
 fs/cifs/transport.c |  158 ++++++++++++++-------------------------------------
 3 files changed, 46 insertions(+), 118 deletions(-)
fs/cifs/cifsproto.h +3 -1
index 76c4dc7f..4af7db8 100644
@@ -74,6 +74,8 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
 			int * /* bytes returned */ , const int long_op);
 extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
 			struct smb_hdr *in_buf, int flags);
+extern int cifs_check_receive(struct mid_q_entry *mid,
+			struct TCP_Server_Info *server, bool log_error);
 extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *,
 			struct kvec *, int /* nvec to send */,
 			int * /* type of buf returned */ , const int flags);
@@ -97,7 +99,7 @@ extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
 extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port);
 extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
 				const unsigned short int port);
-extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
+extern int map_smb_to_linux_error(struct smb_hdr *smb, bool logErr);
 extern void header_assemble(struct smb_hdr *, char /* command */ ,
 			    const struct cifs_tcon *, int /* length of
 			    fixed section (word count) in two byte units */);
fs/cifs/netmisc.c +1 -1
index 79b71c2..73e47e8 100644
@@ -836,7 +836,7 @@ ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
 }
 
 int
-map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
+map_smb_to_linux_error(struct smb_hdr *smb, bool logErr)
 {
 	unsigned int i;
 	int rc = -EIO;	/* if transport error smb error may not be set */
fs/cifs/transport.c +42 -116

216 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#3 lore raw

PATCH 2/8 cifs: make cifs_send_async take a kvec array

In reply to a message not in the archive

We'll need this for async writes, so convert the call to take a kvec array. CIFSSMBEcho is changed to put a kvec on the stack and pass in the SMB buffer using that.

---
 fs/cifs/cifsproto.h |    4 ++--
 fs/cifs/cifssmb.c   |    6 ++++--
 fs/cifs/transport.c |   13 +++++++------
 3 files changed, 13 insertions(+), 10 deletions(-)
fs/cifs/cifsproto.h +2 -2
index 4af7db8..e255a2b 100644
@@ -65,8 +65,8 @@ extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,
 					struct TCP_Server_Info *server);
 extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
 extern int wait_for_free_request(struct TCP_Server_Info *sv, const int long_op);
-extern int cifs_call_async(struct TCP_Server_Info *server,
-			   struct smb_hdr *in_buf, mid_callback_t *callback,
+extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
+			   unsigned int nvec, mid_callback_t *callback,
 			   void *cbdata);
 extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
 			struct smb_hdr * /* input */ ,
fs/cifs/cifssmb.c +4 -2
index 0e3834d..418b3b2 100644
@@ -725,6 +725,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
 {
 	ECHO_REQ *smb;
 	int rc = 0;
+	struct kvec iov;
 
 	cFYI(1, "In echo request");
 
@@ -739,9 +740,10 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
 	put_bcc(1, &smb->hdr);
 	smb->Data[0] = 'a';
 	inc_rfc1001_len(smb, 3);
+	iov.iov_base = smb;
+	iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;
 
-	rc = cifs_call_async(server, (struct smb_hdr *)smb,
-				cifs_echo_callback, server);
+	rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server);
 	if (rc)
 		cFYI(1, "Echo request failed: %d", rc);
 
fs/cifs/transport.c +7 -6
index d9833fc..7ccf292 100644
@@ -349,11 +349,12 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ)
  * the result. Caller is responsible for dealing with timeouts.
  */
 int
-cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
-		mid_callback_t *callback, void *cbdata)
+cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
+		unsigned int nvec, mid_callback_t *callback, void *cbdata)
 {
 	int rc;
 	struct mid_q_entry *mid;
+	struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
 
 	rc = wait_for_free_request(server, CIFS_ASYNC_OP);
 	if (rc)
@@ -361,10 +362,10 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
 
 	/* enable signing if server requires it */
 	if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
-		in_buf->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
+		hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
 
 	mutex_lock(&server->srv_mutex);
-	mid = AllocMidQEntry(in_buf, server);
+	mid = AllocMidQEntry(hdr, server);
 	if (mid == NULL) {
 		mutex_unlock(&server->srv_mutex);
 		return -ENOMEM;
@@ -375,7 +376,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
 	list_add_tail(&mid->qhead, &server->pending_mid_q);
 	spin_unlock(&GlobalMid_Lock);
 
-	rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
+	rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
 	if (rc) {
 		mutex_unlock(&server->srv_mutex);
 		goto out_err;
@@ -385,7 +386,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
 	mid->callback_data = cbdata;
 	mid->midState = MID_REQUEST_SUBMITTED;
 	cifs_in_send_inc(server);
-	rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
+	rc = smb_sendv(server, iov, nvec);
 	cifs_in_send_dec(server);
 	cifs_save_when_sent(mid);
 	mutex_unlock(&server->srv_mutex);
Signature · 1 line
1.7.4.4
#4 lore raw

PATCH 3/8 cifs: don't call mid_q_entry->callback under the Global_MidLock

In reply to a message not in the archive

Holding the spinlock while we call this function means that it can't sleep, which really limits what it can do. Taking it out from under the spinlock also means less contention for this global lock.

Change the semantics such that the Global_MidLock is not held when the callback is called. To do this requires that we take extra care not to have sync_mid_result remove the mid from the list when the mid is in a state where that has already happened. This prevents list corruption when the mid is sitting on a private list for reconnect or when cifsd is coming down.

---
 fs/cifs/cifsglob.h      |    7 +++----
 fs/cifs/connect.c       |   30 ++++++++++++++++++++++++------
 fs/cifs/smb2transport.c |   14 ++++----------
 fs/cifs/transport.c     |   23 ++++++++---------------
 4 files changed, 39 insertions(+), 35 deletions(-)
fs/cifs/cifsglob.h +3 -4
index ccbac61..b3a6404 100644
@@ -583,9 +583,8 @@ struct mid_q_entry;
  * This is the prototype for the mid callback function. When creating one,
  * take special care to avoid deadlocks. Things to bear in mind:
  *
- * - it will be called by cifsd
- * - the GlobalMid_Lock will be held
- * - the mid will be removed from the pending_mid_q list
+ * - it will be called by cifsd, with no locks held
+ * - the mid will be removed from any lists
  */
 typedef void (mid_callback_t)(struct mid_q_entry *mid);
 
@@ -739,7 +738,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
 #define   MID_RESPONSE_RECEIVED 4
 #define   MID_RETRY_NEEDED      8 /* session closed while this request out */
 #define   MID_RESPONSE_MALFORMED 0x10
-#define   MID_NO_RESPONSE_NEEDED 0x20
+#define   MID_SHUTDOWN		 0x20
 
 /* Types of response buffer returned from SendReceive2 */
 #define   CIFS_NO_BUFFER        0    /* Response buffer not returned */
fs/cifs/connect.c +24 -6
index 2df4785..4667cfa 100644
@@ -141,6 +141,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
 	struct cifs_ses *ses;
 	struct cifs_tcon *tcon;
 	struct mid_q_entry *mid_entry;
+	struct list_head retry_list;
 
 	spin_lock(&GlobalMid_Lock);
 	if (server->tcpStatus == CifsExiting) {
@@ -192,16 +193,23 @@ cifs_reconnect(struct TCP_Server_Info *server)
 	mutex_unlock(&server->srv_mutex);
 
 	/* mark submitted MIDs for retry and issue callback */
-	cFYI(1, "%s: issuing mid callbacks", __func__);
+	INIT_LIST_HEAD(&retry_list);
+	cFYI(1, "%s: moving mids to private list", __func__);
 	spin_lock(&GlobalMid_Lock);
 	list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
 		mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
 		if (mid_entry->midState == MID_REQUEST_SUBMITTED)
 			mid_entry->midState = MID_RETRY_NEEDED;
+		list_move(&mid_entry->qhead, &retry_list);
+	}
+	spin_unlock(&GlobalMid_Lock);
+
+	cFYI(1, "%s: moving mids to private list", __func__);
+	list_for_each_safe(tmp, tmp2, &retry_list) {
+		mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
 		list_del_init(&mid_entry->qhead);
 		mid_entry->callback(mid_entry);
 	}
-	spin_unlock(&GlobalMid_Lock);
 
 	while (server->tcpStatus == CifsNeedReconnect) {
 		try_to_freeze();
@@ -675,12 +683,12 @@ multi_t2_fnd:
 			mid_entry->when_received = jiffies;
 #endif
 			list_del_init(&mid_entry->qhead);
-			mid_entry->callback(mid_entry);
 			break;
 		}
 		spin_unlock(&GlobalMid_Lock);
 
 		if (mid_entry != NULL) {
+			mid_entry->callback(mid_entry);
 			/* Was previous buf put in mpx struct for multi-rsp? */
 			if (!isMultiRsp) {
 				/* smb buffer will be freed by user thread */
@@ -744,15 +752,25 @@ multi_t2_fnd:
 		cifs_small_buf_release(smallbuf);
 
 	if (!list_empty(&server->pending_mid_q)) {
+		struct list_head dispose_list;
+
+		INIT_LIST_HEAD(&dispose_list);
 		spin_lock(&GlobalMid_Lock);
 		list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
 			mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
-			cFYI(1, "Clearing Mid 0x%x - issuing callback",
-					 mid_entry->mid);
+			cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
+			mid_entry->midState = MID_SHUTDOWN;
+			list_move(&mid_entry->qhead, &dispose_list);
+		}
+		spin_unlock(&GlobalMid_Lock);
+
+		/* now walk dispose list and issue callbacks */
+		list_for_each_safe(tmp, tmp2, &dispose_list) {
+			mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
+			cFYI(1, "Callback mid 0x%x", mid_entry->mid);
 			list_del_init(&mid_entry->qhead);
 			mid_entry->callback(mid_entry);
 		}
-		spin_unlock(&GlobalMid_Lock);
 		/* 1/8th of sec is more than enough time for them to exit */
 		msleep(125);
 	}
fs/cifs/smb2transport.c +4 -10
index a187587..e0fa75308 100644
@@ -276,28 +276,22 @@ sync_smb2_mid_result(struct smb2_mid_entry *mid, struct TCP_Server_Info *server)
 
 	spin_lock(&GlobalMid_Lock);
 	/* ensure that it's no longer on the pending_mid_q */
-	list_del_init(&mid->qhead);
 
 	switch (mid->mid_state) {
 	case MID_RESPONSE_RECEIVED:
 		spin_unlock(&GlobalMid_Lock);
 		return rc;
-	case MID_REQUEST_SUBMITTED:
-		/* socket is going down, reject all calls */
-		if (server->tcpStatus == CifsExiting) {
-			cERROR(1, "%s: canceling mid=%lld cmd=0x%x state=%d",
-				__func__, mid->mid, le16_to_cpu(mid->command),
-				mid->mid_state);
-			rc = -EHOSTDOWN;
-			break;
-		}
 	case MID_RETRY_NEEDED:
 		rc = -EAGAIN;
 		break;
 	case MID_RESPONSE_MALFORMED:
 		rc = -EIO;
 		break;
+	case MID_SHUTDOWN:
+		rc = -EHOSTDOWN;
+		break;
 	default:
+		list_del_init(&mid->qhead);
 		cERROR(1, "%s: invalid mid state mid=%lld state=%d", __func__,
 			mid->mid, mid->mid_state);
 		rc = -EIO;
fs/cifs/transport.c +8 -15
index 7ccf292..a31c279 100644
@@ -428,7 +428,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
 }
 
 static int
-sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
+cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
 {
 	int rc = 0;
 
@@ -436,28 +436,21 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
 		mid->mid, mid->midState);
 
 	spin_lock(&GlobalMid_Lock);
-	/* ensure that it's no longer on the pending_mid_q */
-	list_del_init(&mid->qhead);
-
 	switch (mid->midState) {
 	case MID_RESPONSE_RECEIVED:
 		spin_unlock(&GlobalMid_Lock);
 		return rc;
-	case MID_REQUEST_SUBMITTED:
-		/* socket is going down, reject all calls */
-		if (server->tcpStatus == CifsExiting) {
-			cERROR(1, "%s: canceling mid=%d cmd=0x%x state=%d",
-			       __func__, mid->mid, mid->command, mid->midState);
-			rc = -EHOSTDOWN;
-			break;
-		}
 	case MID_RETRY_NEEDED:
 		rc = -EAGAIN;
 		break;
 	case MID_RESPONSE_MALFORMED:
 		rc = -EIO;
 		break;
+	case MID_SHUTDOWN:
+		rc = -EHOSTDOWN;
+		break;
 	default:
+		list_del_init(&mid->qhead);
 		cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__,
 			mid->mid, mid->midState);
 		rc = -EIO;
@@ -617,7 +610,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
 
 	cifs_small_buf_release(in_buf);
 
-	rc = sync_mid_result(midQ, ses->server);
+	rc = cifs_sync_mid_result(midQ, ses->server);
 	if (rc != 0) {
 		atomic_dec(&ses->server->inFlight);
 		wake_up(&ses->server->request_q);
@@ -735,7 +728,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
 		spin_unlock(&GlobalMid_Lock);
 	}
 
-	rc = sync_mid_result(midQ, ses->server);
+	rc = cifs_sync_mid_result(midQ, ses->server);
 	if (rc != 0) {
 		atomic_dec(&ses->server->inFlight);
 		wake_up(&ses->server->request_q);
@@ -906,7 +899,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
 		rstart = 1;
 	}
 
-	rc = sync_mid_result(midQ, ses->server);
+	rc = cifs_sync_mid_result(midQ, ses->server);
 	if (rc != 0)
 		return rc;
 
Signature · 1 line
1.7.4.4
#5 lore raw

PATCH 4/8 cifs: add ignore_pend flag to cifs_call_async

In reply to a message not in the archive

The current code always ignores the max_pending limit. Have it instead only optionally ignore the pending limit. For CIFSSMBEcho, we need to ignore it to make sure they always can go out. For async reads, writes and potentially other calls, we need to respect it.

---
 fs/cifs/cifsproto.h |    2 +-
 fs/cifs/cifssmb.c   |    2 +-
 fs/cifs/transport.c |    5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)
fs/cifs/cifsproto.h +1 -1
index e255a2b..c621b45 100644
@@ -67,7 +67,7 @@ extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
 extern int wait_for_free_request(struct TCP_Server_Info *sv, const int long_op);
 extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
 			   unsigned int nvec, mid_callback_t *callback,
-			   void *cbdata);
+			   void *cbdata, bool ignore_pend);
 extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
 			struct smb_hdr * /* input */ ,
 			struct smb_hdr * /* out */ ,
fs/cifs/cifssmb.c +1 -1
index 418b3b2..d4698b9 100644
@@ -743,7 +743,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
 	iov.iov_base = smb;
 	iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;
 
-	rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server);
+	rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server, true);
 	if (rc)
 		cFYI(1, "Echo request failed: %d", rc);
 
fs/cifs/transport.c +3 -2
index a31c279..ad32b70 100644
@@ -350,13 +350,14 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ)
  */
 int
 cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
-		unsigned int nvec, mid_callback_t *callback, void *cbdata)
+		unsigned int nvec, mid_callback_t *callback, void *cbdata,
+		bool ignore_pend)
 {
 	int rc;
 	struct mid_q_entry *mid;
 	struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
 
-	rc = wait_for_free_request(server, CIFS_ASYNC_OP);
+	rc = wait_for_free_request(server, ignore_pend ? CIFS_ASYNC_OP : 0);
 	if (rc)
 		return rc;
 
Signature · 1 line
1.7.4.4
#6 lore raw

PATCH 5/8 cifs: add cifs_async_writev

In reply to a message not in the archive

Add the ability for CIFS to do an asynchronous write. The kernel will set the frame up as it would for a "normal" SMBWrite2 request, and use cifs_call_async to send it. The mid callback will then be configured to handle the result.

---
 fs/cifs/cifsproto.h |   18 ++++
 fs/cifs/cifssmb.c   |  238 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 256 insertions(+), 0 deletions(-)
fs/cifs/cifsproto.h +18 -0
index c621b45..d35019b 100644
@@ -433,4 +433,22 @@ extern int mdfour(unsigned char *, unsigned char *, int);
 extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
 extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
 			unsigned char *p24);
+
+/* asynchronous write support */
+struct cifs_writedata {
+	struct kref			refcount;
+	enum writeback_sync_modes	sync_mode;
+	struct work_struct		work;
+	struct cifsFileInfo		*cfile;
+	__u64				offset;
+	unsigned int			bytes;
+	int				result;
+	unsigned int			nr_pages;
+	struct page 			*pages[1];
+};
+
+int cifs_async_writev(struct cifs_writedata *wdata);
+struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages);
+void cifs_writedata_release(struct kref *refcount);
+
 #endif			/* _CIFSPROTO_H */
fs/cifs/cifssmb.c +238 -0

250 lines not on this page · raw message

Signature · 1 line
1.7.4.4

A message that is not in the archive (sent off-list or not yet received): 1304345069-2441-6-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#8 lore raw

Re: [PATCH 5/8] cifs: add cifs_async_writev

Quoted 76 lines · On Mon, 2 May 2011 10:04:26 -0400 Jeff Layton…

Add the ability for CIFS to do an asynchronous write. The kernel will set the frame up as it would for a "normal" SMBWrite2 request, and use cifs_call_async to send it. The mid callback will then be configured to handle the result.

---
 fs/cifs/cifsproto.h |   18 ++++
 fs/cifs/cifssmb.c   |  238 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 256 insertions(+), 0 deletions(-)
fs/cifs/cifsproto.h +18 -0
index c621b45..d35019b 100644
@@ -433,4 +433,22 @@ extern int mdfour(unsigned char *, unsigned char *, int);
 extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
 extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
 			unsigned char *p24);
+
+/* asynchronous write support */
+struct cifs_writedata {
+	struct kref			refcount;
+	enum writeback_sync_modes	sync_mode;
+	struct work_struct		work;
+	struct cifsFileInfo		*cfile;
+	__u64				offset;
+	unsigned int			bytes;
+	int				result;
+	unsigned int			nr_pages;
+	struct page 			*pages[1];
+};
+
+int cifs_async_writev(struct cifs_writedata *wdata);
+struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages);
+void cifs_writedata_release(struct kref *refcount);
+
 #endif			/* _CIFSPROTO_H */
fs/cifs/cifssmb.c +22 -0
index d4698b9..6ff9b0a 100644
@@ -32,6 +32,7 @@
 #include <linux/vfs.h>
 #include <linux/slab.h>
 #include <linux/posix_acl_xattr.h>
+#include <linux/pagemap.h>
 #include <asm/uaccess.h>
 #include "cifspdu.h"
 #include "cifsglob.h"
@@ -1604,6 +1605,243 @@ CIFSSMBWrite(const int xid, struct cifs_tcon *tcon,
 	return rc;
 }
 
+void
+cifs_writedata_release(struct kref *refcount)
+{
+	struct cifs_writedata *wdata = container_of(refcount,
+					struct cifs_writedata, refcount);
+
+	if (wdata->cfile)
+		cifsFileInfo_put(wdata->cfile);
+
+	kfree(wdata);
+}
+
+/*
+ * Write failed with a retryable error. Resend the write request. It's also
+ * possible that the page was redirtied so re-clean the page.
+ */
+static void
+cifs_writev_requeue(struct cifs_writedata *wdata)
+{
+	int i, rc;
+	struct inode *inode = wdata->cfile->dentry->d_inode;

fs/cifs/cifssmb.c CIFSSMBWrite(const int xid, struct cifs_tcon *tcon, · line 1638

Quoted 10 lines
fs/cifs/cifssmb.c +10 -0
+
+	for (i = 0; i < wdata->nr_pages; i++) {
+		lock_page(wdata->pages[i]);
+		clear_page_dirty_for_io(wdata->pages[i]);
+	}
+
+	do {
+		rc = cifs_async_writev(wdata);
+	} while(rc != -EAGAIN);
+

<forehead slap>

The above should be == -EAGAIN...

Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

PATCH 6/8 cifs: convert cifs_writepages to use async writes

In reply to a message not in the archive

Have cifs_writepages issue asynchronous writes instead of waiting on each write call to complete before issuing another. This also allows us to return more quickly from writepages. It can just send out all of the I/Os and not wait around for the replies.

In the WB_SYNC_ALL case, if the write completes with a retryable error, then the completion workqueue job will resend the write.

This also changes the page locking semantics a little bit. Instead of holding the page lock until the response is received, release it after doing the send. This will reduce contention for the page lock and should prevent processes that have the file mmap'ed from being blocked unnecessarily.

---
 fs/cifs/file.c |  224 ++++++++++++++++++++-----------------------------------
 1 files changed, 82 insertions(+), 142 deletions(-)
fs/cifs/file.c +82 -142
index b3d2e3f..a40234f 100644
@@ -1092,29 +1092,12 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
 static int cifs_writepages(struct address_space *mapping,
 			   struct writeback_control *wbc)
 {
-	unsigned int bytes_to_write;
-	unsigned int bytes_written;
-	struct cifs_sb_info *cifs_sb;
-	int done = 0;
-	pgoff_t end;
-	pgoff_t index;
-	int range_whole = 0;
-	struct kvec *iov;
-	int len;
-	int n_iov = 0;
-	pgoff_t next;
-	int nr_pages;
-	__u64 offset = 0;
-	struct cifsFileInfo *open_file;
-	struct cifs_tcon *tcon;
-	struct cifsInodeInfo *cifsi = CIFS_I(mapping->host);
+	struct cifs_sb_info *cifs_sb = CIFS_SB(mapping->host->i_sb);
+	bool done = false, scanned = false, range_whole = false;
+	pgoff_t end, index;
+	struct cifs_writedata *wdata;
 	struct page *page;
-	struct pagevec pvec;
 	int rc = 0;
-	int scanned = 0;
-	int xid;
-
-	cifs_sb = CIFS_SB(mapping->host->i_sb);
 
 	/*
 	 * If wsize is smaller that the page cache size, default to writing
@@ -1123,27 +1106,6 @@ static int cifs_writepages(struct address_space *mapping,
 	if (cifs_sb->wsize < PAGE_CACHE_SIZE)
 		return generic_writepages(mapping, wbc);
 
-	iov = kmalloc(32 * sizeof(struct kvec), GFP_KERNEL);
-	if (iov == NULL)
-		return generic_writepages(mapping, wbc);
-
-	/*
-	 * if there's no open file, then this is likely to fail too,
-	 * but it'll at least handle the return. Maybe it should be
-	 * a BUG() instead?
-	 */
-	open_file = find_writable_file(CIFS_I(mapping->host), false);
-	if (!open_file) {
-		kfree(iov);
-		return generic_writepages(mapping, wbc);
-	}
-
-	tcon = tlink_tcon(open_file->tlink);
-	cifsFileInfo_put(open_file);
-
-	xid = GetXid();
-
-	pagevec_init(&pvec, 0);
 	if (wbc->range_cyclic) {
 		index = mapping->writeback_index; /* Start from prev offset */
 		end = -1;
@@ -1151,24 +1113,34 @@ static int cifs_writepages(struct address_space *mapping,
 		index = wbc->range_start >> PAGE_CACHE_SHIFT;
 		end = wbc->range_end >> PAGE_CACHE_SHIFT;
 		if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
-			range_whole = 1;
-		scanned = 1;
+			range_whole = true;
+		scanned = true;
 	}
 retry:
-	while (!done && (index <= end) &&
-	       (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-			PAGECACHE_TAG_DIRTY,
-			min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1))) {
-		int first;
-		unsigned int i;
-
-		first = -1;
-		next = 0;
-		n_iov = 0;
-		bytes_to_write = 0;
-
-		for (i = 0; i < nr_pages; i++) {
-			page = pvec.pages[i];
+	while (!done && index <= end) {
+		unsigned int i, nr_pages, found_pages;
+		pgoff_t next = 0, tofind;
+
+		tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1,
+				end - index) + 1;
+
+		wdata = cifs_writedata_alloc((unsigned int)tofind);
+		if (!wdata) {
+			rc = -ENOMEM;
+			break;
+		}
+
+		found_pages = find_get_pages_tag(mapping, &index,
+						 PAGECACHE_TAG_DIRTY,
+						 tofind, wdata->pages);
+		if (found_pages == 0) {
+			kref_put(&wdata->refcount, cifs_writedata_release);
+			break;
+		}
+
+		nr_pages = 0;
+		for (i = 0; i < found_pages; i++) {
+			page = wdata->pages[i];
 			/*
 			 * At this point we hold neither mapping->tree_lock nor
 			 * lock on the page itself: the page may be truncated or
@@ -1177,7 +1149,7 @@ retry:
 			 * mapping
 			 */
 
-			if (first < 0)
+			if (nr_pages == 0)
 				lock_page(page);
 			else if (!trylock_page(page))
 				break;
@@ -1188,7 +1160,7 @@ retry:
 			}
 
 			if (!wbc->range_cyclic && page->index > end) {
-				done = 1;
+				done = true;
 				unlock_page(page);
 				break;
 			}
@@ -1215,119 +1187,87 @@ retry:
 			set_page_writeback(page);
 
 			if (page_offset(page) >= mapping->host->i_size) {
-				done = 1;
+				done = true;
 				unlock_page(page);
 				end_page_writeback(page);
 				break;
 			}
 
-			/*
-			 * BB can we get rid of this?  pages are held by pvec
-			 */
-			page_cache_get(page);
+			wdata->pages[i] = page;
+			next = page->index + 1;
+			++nr_pages;
+		}
 
-			len = min(mapping->host->i_size - page_offset(page),
-				  (loff_t)PAGE_CACHE_SIZE);
+		/* reset index to refind any pages skipped */
+		if (nr_pages == 0)
+			index = wdata->pages[0]->index + 1;
 
-			/* reserve iov[0] for the smb header */
-			n_iov++;
-			iov[n_iov].iov_base = kmap(page);
-			iov[n_iov].iov_len = len;
-			bytes_to_write += len;
+		/* put any pages we aren't going to use */
+		for (i = nr_pages; i < found_pages; i++) {
+			page_cache_release(wdata->pages[i]);
+			wdata->pages[i] = NULL;
+		}
 
-			if (first < 0) {
-				first = i;
-				offset = page_offset(page);
-			}
-			next = page->index + 1;
-			if (bytes_to_write + PAGE_CACHE_SIZE > cifs_sb->wsize)
-				break;
+		/* nothing to write? */
+		if (nr_pages == 0) {
+			kref_put(&wdata->refcount, cifs_writedata_release);
+			continue;
 		}
-		if (n_iov) {
-retry_write:
-			open_file = find_writable_file(CIFS_I(mapping->host),
-							false);
-			if (!open_file) {
-				cERROR(1, "No writable handles for inode");
-				rc = -EBADF;
-			} else {
-				rc = CIFSSMBWrite2(xid, tcon, open_file->netfid,
-						   bytes_to_write, offset,
-						   &bytes_written, iov, n_iov,
-						   0);
-				cifsFileInfo_put(open_file);
-			}
 
-			cFYI(1, "Write2 rc=%d, wrote=%u", rc, bytes_written);
+		wdata->sync_mode = wbc->sync_mode;
+		wdata->nr_pages = nr_pages;
+		wdata->offset = page_offset(wdata->pages[0]);
 
-			/*
-			 * For now, treat a short write as if nothing got
-			 * written. A zero length write however indicates
-			 * ENOSPC or EFBIG. We have no way to know which
-			 * though, so call it ENOSPC for now. EFBIG would
-			 * get translated to AS_EIO anyway.
-			 *
-			 * FIXME: make it take into account the data that did
-			 *	  get written
-			 */
-			if (rc == 0) {
-				if (bytes_written == 0)
-					rc = -ENOSPC;
-				else if (bytes_written < bytes_to_write)
-					rc = -EAGAIN;
+		do {
+			if (wdata->cfile != NULL)
+				cifsFileInfo_put(wdata->cfile);
+			wdata->cfile = find_writable_file(CIFS_I(mapping->host),
+							  false);
+			if (!wdata->cfile) {
+				cERROR(1, "No writable handles for inode");
+				rc = -EBADF;
+				break;
 			}
+			rc = cifs_async_writev(wdata);
+		} while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
 
-			/* retry on data-integrity flush */
-			if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN)
-				goto retry_write;
-
-			/* fix the stats and EOF */
-			if (bytes_written > 0) {
-				cifs_stats_bytes_written(tcon, bytes_written);
-				cifs_update_eof(cifsi, offset, bytes_written);
-			}
+		for (i = 0; i < nr_pages; ++i)
+			unlock_page(wdata->pages[i]);
 
-			for (i = 0; i < n_iov; i++) {
-				page = pvec.pages[first + i];
-				/* on retryable write error, redirty page */
+		/* send failure -- clean up the mess */
+		if (rc != 0) {
+			for (i = 0; i < nr_pages; ++i) {
 				if (rc == -EAGAIN)
-					redirty_page_for_writepage(wbc, page);
-				else if (rc != 0)
-					SetPageError(page);
-				kunmap(page);
-				unlock_page(page);
-				end_page_writeback(page);
-				page_cache_release(page);
+					redirty_page_for_writepage(wbc,
+							   wdata->pages[i]);
+				else
+					SetPageError(wdata->pages[i]);
+				end_page_writeback(wdata->pages[i]);
+				page_cache_release(wdata->pages[i]);
 			}
-
 			if (rc != -EAGAIN)
 				mapping_set_error(mapping, rc);
-			else
-				rc = 0;
-
-			if ((wbc->nr_to_write -= n_iov) <= 0)
-				done = 1;
-			index = next;
-		} else
-			/* Need to re-find the pages we skipped */
-			index = pvec.pages[0]->index + 1;
+		}
+		kref_put(&wdata->refcount, cifs_writedata_release);
 
-		pagevec_release(&pvec);
+		if ((wbc->nr_to_write -= nr_pages) <= 0)
+			done = true;
+		index = next;
 	}
+
 	if (!scanned && !done) {
 		/*
 		 * We hit the last page and there is more work to be done: wrap
 		 * back to the start of the file
 		 */
-		scanned = 1;
+		scanned = true;
 		index = 0;
 		goto retry;
 	}
+
 	if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
 		mapping->writeback_index = index;
 
-	FreeXid(xid);
-	kfree(iov);
 	return rc;
 }
 
Signature · 1 line
1.7.4.4
#10 lore raw

PATCH 7/8 cifs: clean up wsize negotiation and allow for larger wsize

In reply to a message not in the archive

Now that we can handle larger wsizes in writepages, fix up the negotiation of the wsize to allow for that. Make the code default to a wsize of (128k - PAGE_CACHE_SIZE). That gives us a size that goes up to the max frame size specified in RFC1001.

If CAP_LARGE_WRITE_AND_X isn't set, then set that down to a the largest size allowed by the protocol (USHRT_MAX), or the specified wsize, whichever is smaller.

If a larger wsize is specified, then check to make sure the server supports the POSIX extension that allows it to ignore the 128k limit. If it doesn't then set it to the default value.

---
 fs/cifs/connect.c |   60 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 40 insertions(+), 20 deletions(-)
fs/cifs/connect.c +40 -20
index 4667cfa..b5e4b75 100644
@@ -2614,23 +2614,6 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
 	else /* default */
 		cifs_sb->rsize = CIFSMaxBufSize;
 
-	if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
-		cERROR(1, "wsize %d too large, using 4096 instead",
-			  pvolume_info->wsize);
-		cifs_sb->wsize = 4096;
-	} else if (pvolume_info->wsize)
-		cifs_sb->wsize = pvolume_info->wsize;
-	else
-		cifs_sb->wsize = min_t(const int,
-					PAGEVEC_SIZE * PAGE_CACHE_SIZE,
-					127*1024);
-		/* old default of CIFSMaxBufSize was too small now
-		   that SMB Write2 can send multiple pages in kvec.
-		   RFC1001 does not describe what happens when frame
-		   bigger than 128K is sent so use that as max in
-		   conjunction with 52K kvec constraint on arch with 4K
-		   page size  */
-
 	if (cifs_sb->rsize < 2048) {
 		cifs_sb->rsize = 2048;
 		/* Windows ME may prefer this */
@@ -2708,6 +2691,44 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
 			   "mount option supported");
 }
 
+/*
+ * default to a wsize of 128k - PAGE_CACHE_SIZE -- one page less than the
+ * largest frame size described in RFC1001. This allows space for the header
+ * without going over that by default.
+ */
+#define CIFS_MAX_RFC1001_WSIZE (128 * 1024 - PAGE_CACHE_SIZE)
+
+/*
+ * It's possible to increase the wsize by setting the wsize parm directly
+ * up to a hard limit of 2^24 - PAGE_CACHE_SIZE. That might make for
+ * "interesting" allocation problems during writeback however (as we have to
+ * allocate an array of pointers for the pages). A 16M write means ~32kb
+ * page array with PAGE_CACHE_SIZE == 4096.
+ */
+#define CIFS_MAX_WSIZE ((1<<24) - PAGE_CACHE_SIZE)
+
+static unsigned int
+cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)
+{
+	__u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
+	struct TCP_Server_Info *server = tcon->ses->server;
+	unsigned int wsize = pvolume_info->wsize ? pvolume_info->wsize :
+				CIFS_MAX_RFC1001_WSIZE;
+
+	/* no CAP_LARGE_WRITE_X? Limit it to 16 bits */
+	if (!(server->capabilities & CAP_LARGE_WRITE_X))
+		wsize = min_t(unsigned int, wsize, USHRT_MAX);
+
+	/* can server support 24-bit write sizes? (via UNIX extensions) */
+	if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
+		wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1001_WSIZE);
+
+	/* hard limit of CIFS_MAX_WSIZE */
+	wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
+
+	return wsize;
+}
+
 static int
 is_path_accessible(int xid, struct cifs_tcon *tcon,
 		   struct cifs_sb_info *cifs_sb, const char *full_path)
@@ -2898,13 +2919,12 @@ try_mount_again:
 		cifs_sb->rsize = 1024 * 127;
 		cFYI(DBG2, "no very large read support, rsize now 127K");
 	}
-	if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
-		cifs_sb->wsize = min(cifs_sb->wsize,
-			       (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
 	if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
 		cifs_sb->rsize = min(cifs_sb->rsize,
 			       (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
 
+	cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info);
+
 remote_path_check:
 	/* check if a whole path (including prepath) is not remote */
 	if (!rc && tcon) {
Signature · 1 line
1.7.4.4
#11 lore raw

PATCH 8/8 cifs: use the server's MaxMpxCount to determine max requests in flight

In reply to a message not in the archive

Currently, we have a default cap of 50 outstanding requests and a hard cap of 256. However, the server sends us how many requests it can handle simultaneously via the MaxMapCount value in the NegProt request. Use that value instead and eliminate the cifs_max_pending module parm.

---
 fs/cifs/cifsfs.c    |   12 ------------
 fs/cifs/cifsglob.h  |   14 +-------------
 fs/cifs/connect.c   |    5 +++--
 fs/cifs/transport.c |    6 +++---
 4 files changed, 7 insertions(+), 30 deletions(-)
fs/cifs/cifsfs.c +0 -12
index fb6a2ad..22f0b1a 100644
@@ -72,10 +72,6 @@ unsigned int cifs_min_small = 30;
 module_param(cifs_min_small, int, 0);
 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
 				 "Range: 2 to 256");
-unsigned int cifs_max_pending = CIFS_MAX_REQ;
-module_param(cifs_max_pending, int, 0);
-MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
-				   "Default: 50 Range: 2 to 256");
 unsigned short echo_retries = 5;
 module_param(echo_retries, ushort, 0644);
 MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and "
@@ -1035,14 +1031,6 @@ init_cifs(void)
 	spin_lock_init(&cifs_file_list_lock);
 	spin_lock_init(&GlobalMid_Lock);
 
-	if (cifs_max_pending < 2) {
-		cifs_max_pending = 2;
-		cFYI(1, "cifs_max_pending set to min of 2");
-	} else if (cifs_max_pending > 256) {
-		cifs_max_pending = 256;
-		cFYI(1, "cifs_max_pending set to max of 256");
-	}
-
 	rc = cifs_fscache_register();
 	if (rc)
 		goto out_clean_proc;
fs/cifs/cifsglob.h +1 -13
index b3a6404..5f7c52a 100644
@@ -56,17 +56,6 @@
  */
 #define CIFS_MAX_ACTIMEO (1 << 30)
 
-/*
- * MAX_REQ is the maximum number of requests that WE will send
- * on one socket concurrently. It also matches the most common
- * value of max multiplex returned by servers.  We may
- * eventually want to use the negotiated value (in case
- * future servers can handle more) when we are more confident that
- * we will not have problems oveloading the socket with pending
- * write data.
- */
-#define CIFS_MAX_REQ 50
-
 #define RFC1001_NAME_LEN 15
 #define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
 
@@ -185,8 +174,8 @@ struct TCP_Server_Info {
 	__u16 sec_mode;
 	bool session_estab; /* mark when very first sess is established */
 	u16 dialect; /* dialect index that server chose */
+	u16 maxReq;  /* Clients should submit no more */
 	enum securityEnum secType;
-	unsigned int maxReq;	/* Clients should submit no more */
 	/* than maxReq distinct unanswered SMBs to the server when using  */
 	/* multiplexed reads or writes */
 	unsigned int maxBuf;	/* maxBuf specifies the maximum */
@@ -905,7 +894,6 @@ GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
 GLOBAL_EXTERN unsigned int CIFSMaxBufSize;  /* max size not including hdr */
 GLOBAL_EXTERN unsigned int cifs_min_rcv;    /* min size of big ntwrk buf pool */
 GLOBAL_EXTERN unsigned int cifs_min_small;  /* min size of small buf pool */
-GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/
 
 /* reconnect after this many failed echo attempts */
 GLOBAL_EXTERN unsigned short echo_retries;
fs/cifs/connect.c +3 -2
index b5e4b75..5a636ab 100644
@@ -728,8 +728,8 @@ multi_t2_fnd:
 	/* Note that cifs_max_pending is normally 50, but
 	can be set at module install time to as little as two */
 	spin_lock(&GlobalMid_Lock);
-	if (atomic_read(&server->inFlight) >= cifs_max_pending)
-		atomic_set(&server->inFlight, cifs_max_pending - 1);
+	if (atomic_read(&server->inFlight) >= server->maxReq)
+		atomic_set(&server->inFlight, server->maxReq - 1);
 	/* We do not want to set the max_pending too low or we
 	could end up with the counter going negative */
 	spin_unlock(&GlobalMid_Lock);
@@ -1770,6 +1770,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
 	tcp_ses->noautotune = volume_info->noautotune;
 	/* BB should we set this unconditionally now, especially for SMB2 */
 	tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay;
+	tcp_ses->maxReq = 1; /* reset after NEGOTIATE */
 	atomic_set(&tcp_ses->inFlight, 0);
 	init_waitqueue_head(&tcp_ses->response_q);
 	init_waitqueue_head(&tcp_ses->request_q);
fs/cifs/transport.c +3 -3
index ad32b70..89a9892 100644
@@ -265,12 +265,12 @@ int wait_for_free_request(struct TCP_Server_Info *server,
 	spin_lock(&GlobalMid_Lock);
 	while (1) {
 		if ((server->is_smb2 == false) && 
-		    atomic_read(&server->inFlight) >= cifs_max_pending) {
+		    atomic_read(&server->inFlight) >= server->maxReq) {
 			spin_unlock(&GlobalMid_Lock);
 			cifs_num_waiters_inc(server);
 			wait_event(server->request_q,
-				   atomic_read(&server->inFlight)
-				     < cifs_max_pending);
+				atomic_read(&server->inFlight) <
+						server->maxReq);
 			cifs_num_waiters_dec(server);
 			spin_lock(&GlobalMid_Lock);
 #ifdef CONFIG_CIFS_SMB2
Signature · 1 line
1.7.4.4

A message that is not in the archive (sent off-list or not yet received): 1304345069-2441-9-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#13 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

2011/5/2 Jeff Layton <[email protected]>:

Quoted 6 lines

Currently, we have a default cap of 50 outstanding requests and a hard cap of 256. However, the server sends us how many requests it can handle simultaneously via the MaxMapCount value in the NegProt request. Use that value instead and eliminate the cifs_max_pending module parm.

If we ignore this limit for Echo request, can a server drop a connection if we send, e.g. maxReq write requests and 1 Echo request?
http://msdn.microsoft.com/en-us/library/ee441946(v=PROT.13).aspx
doesn't mention about any exceptions for Echo request in this case.

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): BANLkTinJHDQup-QwRNrZF19L_VycUCf1Jw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#15 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

Quoted 6 lines · On Wed, 4 May 2011 14:38:07 +0400 Pavel Shilovsky…

2011/5/2 Jeff Layton <[email protected]>:

Quoted 5 lines

Currently, we have a default cap of 50 outstanding requests and a hard cap of 256. However, the server sends us how many requests it can handle simultaneously via the MaxMapCount value in the NegProt request. Use that value instead and eliminate the cifs_max_pending module parm.

Quoted 8 lines
Quoted 1 line

If we ignore this limit for Echo request, can a server drop a connection if we send, e.g. maxReq write requests and 1 Echo request?
http://msdn.microsoft.com/en-us/library/ee441946(v=PROT.13).aspx
doesn't mention about any exceptions for Echo request in this case.

Well, we currently ignore this for oplock breaks too...

I suppose we probably ought to have a small number of slots kept in reserve for echoes and oplock breaks. Instead of just ignoring the limit for those we can allow these calls access to those "emergency" slots.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20110504070955.07d9420f-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#17 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

Quoted 18 lines · Jeff Layton
Quoted 6 lines · On Wed, 4 May 2011 14:38:07 +0400 Pavel Shilovsky…

2011/5/2 Jeff Layton <[email protected]>:

Quoted 5 lines

Currently, we have a default cap of 50 outstanding requests and a hard cap of 256. However, the server sends us how many requests it can handle simultaneously via the MaxMapCount value in the NegProt request. Use that value instead and eliminate the cifs_max_pending module parm.

Quoted 8 lines
Quoted 1 line

If we ignore this limit for Echo request, can a server drop a connection if we send, e.g. maxReq write requests and 1 Echo request?
http://msdn.microsoft.com/en-us/library/ee441946(v=PROT.13).aspx
doesn't mention about any exceptions for Echo request in this case.

Quoted 6 lines

Well, we currently ignore this for oplock breaks too...

I suppose we probably ought to have a small number of slots kept in reserve for echoes and oplock breaks. Instead of just ignoring the limit for those we can allow these calls access to those "emergency" slots.

Two reserved slots: 1 for oplock break, 1 for echo.

Note that if maxmpx is set to 2 on negotiate, we also have to disable oplock (echo + 1 pending open request would max out our maxmpx)

Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): BANLkTimbNy+v-B2jzYH1hnEjtaKij5n6_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#19 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

2011/5/6 Steve French <[email protected]>:

Quoted 1 line

Two reserved slots:    1 for oplock break, 1 for echo.

What's if we need to send oplock break for two files in almost the same time?

Quoted 2 lines

Note that if maxmpx is set to 2 on negotiate, we also have to disable oplock (echo + 1 pending open request would max out our maxmpx)

What's if maxmpx is set to 1? According to the link (that I posted above) it is a possible situation.

Note that now we don't count block locking command, but the spec doesn't tell anything about it - so, I think we should count them too.

May be we should drop any exceptions, count all types of requests and move to smth like priority queue? In this case we can use three kind of lists and put echo requests into the highest priority list - e.g. "3", oplock break requests - "2", and all other requests into the priority "1" list. Or we can use only one double-linked list and put all echo and oplock break requests to the head, and all other requests
- to the tail.

Thoughts?

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#20 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

Quoted 5 lines · On Fri, 6 May 2011 11:01:52 +0400 Pavel Shilovsky…

2011/5/6 Steve French <[email protected]>:

Quoted 1 line

Two reserved slots:    1 for oplock break, 1 for echo.

What's if we need to send oplock break for two files in almost the same time?

Quoted 9 lines
Quoted 2 lines

Note that if maxmpx is set to 2 on negotiate, we also have to disable oplock (echo + 1 pending open request would max out our maxmpx)

What's if maxmpx is set to 1? According to the link (that I posted above) it is a possible situation.

Note that now we don't count block locking command, but the spec doesn't tell anything about it - so, I think we should count them too.

Ditto. The blocking lock code is a mess anyway -- that really needs a fundamental re-think.

Quoted 10 lines

May be we should drop any exceptions, count all types of requests and move to smth like priority queue? In this case we can use three kind of lists and put echo requests into the highest priority list - e.g. "3", oplock break requests - "2", and all other requests into the priority "1" list. Or we can use only one double-linked list and put all echo and oplock break requests to the head, and all other requests
- to the tail.

Thoughts?

A priority queue doesn't really help here. What if you already have maxmpx calls in flight and suddenly need to send an oplock break? You'll just be stuck.

I think all you really need here is a flag for the slot allocator that tells whether some calls are allowed to dip into the emergency pool, and keep a couple of slots in reserve for echoes and oplock breaks like Steve suggests.

In practice, there's probably no reason to have more than one echo in flight, and we could modify the echo code not to send one when there's already one that the server hasn't responded to.

If the server sends back a maxmpx value less than 2 we should probably fail the mount. Less than 3, and we should disable oplocks.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20110506074145.053e09a5-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#22 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

Quoted 41 lines · Jeff Layton
Quoted 5 lines · On Fri, 6 May 2011 11:01:52 +0400 Pavel Shilovsky…

2011/5/6 Steve French <[email protected]>:

Quoted 1 line

Two reserved slots:    1 for oplock break, 1 for echo.

What's if we need to send oplock break for two files in almost the same time?

Quoted 9 lines
Quoted 2 lines

Note that if maxmpx is set to 2 on negotiate, we also have to disable oplock (echo + 1 pending open request would max out our maxmpx)

What's if maxmpx is set to 1? According to the link (that I posted above) it is a possible situation.

Note that now we don't count block locking command, but the spec doesn't tell anything about it - so, I think we should count them too.

Ditto. The blocking lock code is a mess anyway -- that really needs a fundamental re-think.

Quoted 10 lines

May be we should drop any exceptions, count all types of requests and move to smth like priority queue? In this case we can use three kind of lists and put echo requests into the highest priority list - e.g. "3", oplock break requests - "2", and all other requests into the priority "1" list. Or we can use only one double-linked list and put all echo and oplock break requests to the head, and all other requests
- to the tail.

Thoughts?

A priority queue doesn't really help here. What if you already have maxmpx calls in flight and suddenly need to send an oplock break? You'll just be stuck.

I think all you really need here is a flag for the slot allocator that tells whether some calls are allowed to dip into the emergency pool, and keep a couple of slots in reserve for echoes and oplock breaks like Steve suggests.

Quoted 6 lines

In practice, there's probably no reason to have more than one echo in flight, and we could modify the echo code not to send one when there's already one that the server hasn't responded to.

If the server sends back a maxmpx value less than 2 we should probably fail the mount. Less than 3, and we should disable oplocks.

Setting maxmpxcount to 1 could be a server bug - IIRC some servers used to set it to zero or 1 a long time ago (hope none do it know but don't remember - we could also log an error in dmesg on maxmpxcount set to implausible value of 0, 1 or 2).

I am not too worried about multiple oplocks in flight as long as we have one in reserve for oplock and one in reserve for echo.

Signature · 3 lines
Thanks,

Steve
#23 lore raw

Re: [PATCH 8/8] cifs: use the server's MaxMpxCount to determine max requests in flight

In reply to a message not in the archive
Quoted 26 lines · On Thu, 5 May 2011 21:38:47 -0500 Steve French…
Quoted 18 lines · Jeff Layton
Quoted 6 lines · On Wed, 4 May 2011 14:38:07 +0400 Pavel Shilovsky…

2011/5/2 Jeff Layton <[email protected]>:

Quoted 5 lines

Currently, we have a default cap of 50 outstanding requests and a hard cap of 256. However, the server sends us how many requests it can handle simultaneously via the MaxMapCount value in the NegProt request. Use that value instead and eliminate the cifs_max_pending module parm.

Quoted 8 lines
Quoted 1 line

If we ignore this limit for Echo request, can a server drop a connection if we send, e.g. maxReq write requests and 1 Echo request?
http://msdn.microsoft.com/en-us/library/ee441946(v=PROT.13).aspx
doesn't mention about any exceptions for Echo request in this case.

Quoted 6 lines

Well, we currently ignore this for oplock breaks too...

I suppose we probably ought to have a small number of slots kept in reserve for echoes and oplock breaks. Instead of just ignoring the limit for those we can allow these calls access to those "emergency" slots.

Quoted 5 lines

Two reserved slots: 1 for oplock break, 1 for echo.

Note that if maxmpx is set to 2 on negotiate, we also have to disable oplock (echo + 1 pending open request would max out our maxmpx)

Right.

I think I'm just going to end up dropping this patch from the set. It's not really required for this and it probably deserves to be a separate set of patches.

Signature · 1 line
Jeff Layton <[email protected]>