Skip to contentSkip to conversation

cifs: asynchronous read support for uncached reads

PATCH New Jeff Layton 1 participant 6 messages Apr 14, 2012 1 message not in the archive

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

cover cifs: asynchronous read support for uncached reads

This patchset converts cifs_iovec_read to issue and collect asynchronous reads. This is primarily of use when a share is mounted with forcedirectio, or strictcache and the client doesn't have an oplock for the file being read.

This greatly increases read performance in this situation. Here are some test results from my craptacular KVM test rig to samba. Here's the command that I ran:

    $ dd if=./ddtest.out of=/dev/null bs=1M

Unpatched 3.4-rc2 kernel -- rsize is always capped at 16k here:

    1073741824 bytes (1.1 GB) copied, 97.6394 s, 11.0 MB/s

Patched 3.4-rc2 kernel -- rsize=1M:

    1073741824 bytes (1.1 GB) copied, 9.89869 s, 108 MB/s

Patched 3.4-rc2 kernel -- rsize=61440:

    1073741824 bytes (1.1 GB) copied, 13.4146 s, 80.0 MB/s

The first few patches abstract out and clean up some of the code. The last one converts cifs_iovec_read to use the async read infrastructure. This also lifts the artificial limit on the rsize.

Once this goes in, I'd like to begin discussing a transition to make strictcache the default since that's what the protocol mandates. I'll come up with a more detailed proposal for that in the near future.

I'd like to see this set go into the 3.5 merge window. Merging it into a branch destined for linux-next soon in order to get it more testing would be ideal though.

Jeff Layton (5):
cifs: make cifs_readdata_alloc take a work_func_t arg
cifs: abstract out function to marshal the iovec for readv receives
cifs: add refcounting to cifs_readdata structures
cifs: add wrapper for cifs_async_readv to retry opening file
cifs: convert cifs_iovec_read to use async reads

 fs/cifs/cifsproto.h |    8 +-
 fs/cifs/cifssmb.c   |  120 +-------------
 fs/cifs/file.c      |  452 ++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 392 insertions(+), 188 deletions(-)
Signature · 1 line
1.7.7.6

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

#2 lore raw

PATCH 1/5 cifs: make cifs_readdata_alloc take a work_func_t arg

We'll need different completion routines for an uncached read. Allow the caller to set the one he needs at allocation time. Also, move most of these functions to file.c so we can make more of them static.

---
 fs/cifs/cifsproto.h |    2 --
 fs/cifs/cifssmb.c   |   50 --------------------------------------------------
 fs/cifs/file.c      |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 53 deletions(-)
fs/cifs/cifsproto.h +0 -2
index 96192c1..d57cdf4 100644
@@ -476,8 +476,6 @@ struct cifs_readdata {
 	struct kvec			iov[1];
 };
 
-struct cifs_readdata *cifs_readdata_alloc(unsigned int nr_pages);
-void cifs_readdata_free(struct cifs_readdata *rdata);
 int cifs_async_readv(struct cifs_readdata *rdata);
 
 /* asynchronous write support */
fs/cifs/cifssmb.c +0 -50

68 lines not on this page · raw message

fs/cifs/file.c +49 -1

68 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#3 lore raw

PATCH 2/5 cifs: abstract out function to marshal the iovec for readv receives

In reply to a message not in the archive

Cached and uncached reads will need to do different things here to handle the difference when the pages are in pagecache and not. Abstract out the function that marshals the page list into a kvec array.

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/cifssmb.c   |   67 +++-----------------------------------------------
 fs/cifs/file.c      |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 63 deletions(-)
fs/cifs/cifsproto.h +2 -0
index d57cdf4..f309b43 100644
@@ -472,6 +472,8 @@ struct cifs_readdata {
 	int				result;
 	struct list_head		pages;
 	struct work_struct		work;
+	int (*marshal_iov) (struct cifs_readdata *rdata,
+			    unsigned int remaining);
 	unsigned int			nr_iov;
 	struct kvec			iov[1];
 };
fs/cifs/cifssmb.c +4 -63

88 lines not on this page · raw message

fs/cifs/file.c +68 -0

80 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#4 lore raw

PATCH 3/5 cifs: add refcounting to cifs_readdata structures

In reply to a message not in the archive

This isn't strictly necessary for the async readpages code, but the uncached version will need to be able to collect the replies after issuing the calls. Add a kref to cifs_readdata and use change the code to take and put references appropriately.

---
 fs/cifs/cifsproto.h |    2 ++
 fs/cifs/cifssmb.c   |    3 +++
 fs/cifs/file.c      |   21 ++++++++++++++-------
 3 files changed, 19 insertions(+), 7 deletions(-)
fs/cifs/cifsproto.h +2 -0
index f309b43..63e91c7 100644
@@ -464,6 +464,7 @@ extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
 
 /* asynchronous read support */
 struct cifs_readdata {
+	struct kref			refcount;
 	struct cifsFileInfo		*cfile;
 	struct address_space		*mapping;
 	__u64				offset;
@@ -478,6 +479,7 @@ struct cifs_readdata {
 	struct kvec			iov[1];
 };
 
+void cifs_readdata_release(struct kref *refcount);
 int cifs_async_readv(struct cifs_readdata *rdata);
 
 /* asynchronous write support */
fs/cifs/cifssmb.c +3 -0
index 733af77..2591bf8 100644
@@ -1635,12 +1635,15 @@ cifs_async_readv(struct cifs_readdata *rdata)
 	rdata->iov[0].iov_base = smb;
 	rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;
 
+	kref_get(&rdata->refcount);
 	rc = cifs_call_async(tcon->ses->server, rdata->iov, 1,
 			     cifs_readv_receive, cifs_readv_callback,
 			     rdata, false);
 
 	if (rc == 0)
 		cifs_stats_inc(&tcon->num_reads);
+	else
+		kref_put(&rdata->refcount, cifs_readdata_release);
 
 	cifs_small_buf_release(smb);
 	return rc;
fs/cifs/file.c +14 -7
index 183381d..ae285e0 100644
@@ -2347,16 +2347,22 @@ cifs_readdata_alloc(unsigned int nr_vecs, work_func_t complete)
 	rdata = kzalloc(sizeof(*rdata) +
 			sizeof(struct kvec) * nr_vecs, GFP_KERNEL);
 	if (rdata != NULL) {
+		kref_init(&rdata->refcount);
 		INIT_WORK(&rdata->work, complete);
 		INIT_LIST_HEAD(&rdata->pages);
 	}
 	return rdata;
 }
 
-static void
-cifs_readdata_free(struct cifs_readdata *rdata)
+void
+cifs_readdata_release(struct kref *refcount)
 {
-	cifsFileInfo_put(rdata->cfile);
+	struct cifs_readdata *rdata = container_of(refcount,
+					struct cifs_readdata, refcount);
+
+	if (rdata->cfile)
+		cifsFileInfo_put(rdata->cfile);
+
 	kfree(rdata);
 }
 
@@ -2651,7 +2657,7 @@ cifs_readv_complete(struct work_struct *work)
 
 		page_cache_release(page);
 	}
-	cifs_readdata_free(rdata);
+	kref_put(&rdata->refcount, cifs_readdata_release);
 }
 
 static int
@@ -2837,9 +2843,8 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
 		}
 
 		spin_lock(&cifs_file_list_lock);
-		cifsFileInfo_get(open_file);
 		spin_unlock(&cifs_file_list_lock);
-		rdata->cfile = open_file;
+		rdata->cfile = cifsFileInfo_get(open_file);
 		rdata->mapping = mapping;
 		rdata->offset = offset;
 		rdata->bytes = bytes;
@@ -2864,9 +2869,11 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
 				unlock_page(page);
 				page_cache_release(page);
 			}
-			cifs_readdata_free(rdata);
+			kref_put(&rdata->refcount, cifs_readdata_release);
 			break;
 		}
+
+		kref_put(&rdata->refcount, cifs_readdata_release);
 	}
 
 	return rc;
Signature · 1 line
1.7.7.6
#5 lore raw

PATCH 4/5 cifs: add wrapper for cifs_async_readv to retry opening file

In reply to a message not in the archive

We'll need this same bit of code for the uncached case.

---
 fs/cifs/file.c |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)
fs/cifs/file.c +18 -9
index ae285e0..d2a4259 100644
@@ -2366,6 +2366,23 @@ cifs_readdata_release(struct kref *refcount)
 	kfree(rdata);
 }
 
+static int
+cifs_retry_async_readv(struct cifs_readdata *rdata)
+{
+	int rc;
+
+	do {
+		if (rdata->cfile->invalidHandle) {
+			rc = cifs_reopen_file(rdata->cfile, true);
+			if (rc != 0)
+				continue;
+		}
+		rc = cifs_async_readv(rdata);
+	} while (rc == -EAGAIN);
+
+	return rc;
+}
+
 static ssize_t
 cifs_iovec_read(struct file *file, const struct iovec *iov,
 		 unsigned long nr_segs, loff_t *poffset)
@@ -2852,15 +2869,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
 		rdata->marshal_iov = cifs_readpages_marshal_iov;
 		list_splice_init(&tmplist, &rdata->pages);
 
-		do {
-			if (open_file->invalidHandle) {
-				rc = cifs_reopen_file(open_file, true);
-				if (rc != 0)
-					continue;
-			}
-			rc = cifs_async_readv(rdata);
-		} while (rc == -EAGAIN);
-
+		rc = cifs_retry_async_readv(rdata);
 		if (rc != 0) {
 			list_for_each_entry_safe(page, tpage, &rdata->pages,
 						 lru) {
Signature · 1 line
1.7.7.6
#6 lore raw

PATCH 5/5 cifs: convert cifs_iovec_read to use async reads

In reply to a message not in the archive

Convert cifs_iovec_read to use async I/O. This also raises the limit on the rsize for uncached reads. We first allocate a set of pages to hold the replies, then issue the reads in parallel and then collect the replies and copy the results into the iovec.

A possible future optimization would be to kmap and inline the iovec buffers and read the data directly from the socket into that. That would require some rather complex conversion of the iovec into a kvec however.

---
 fs/cifs/cifsproto.h |    2 +
 fs/cifs/file.c      |  294 ++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 236 insertions(+), 60 deletions(-)
fs/cifs/cifsproto.h +2 -0
index 63e91c7..eeb789d 100644
@@ -465,6 +465,8 @@ extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
 /* asynchronous read support */
 struct cifs_readdata {
 	struct kref			refcount;
+	struct list_head		list;
+	struct completion		done;
 	struct cifsFileInfo		*cfile;
 	struct address_space		*mapping;
 	__u64				offset;
fs/cifs/file.c +234 -60

340 lines not on this page · raw message

Signature · 1 line
1.7.7.6