linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: v9fs-developer@lists.sourceforge.net
Cc: linux-fsdevel@vger.kernel.org,
	"Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>,
	Badari Pulavarty <pbadari@us.ibm.com>
Subject: [PATCH 5/5] [net/9p] Achieve zero copy on read path.
Date: Tue, 17 Aug 2010 10:27:25 -0700	[thread overview]
Message-ID: <1282066045-3945-6-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1282066045-3945-1-git-send-email-jvrao@linux.vnet.ibm.com>

This patch avoids copy_to_user by employing get_user_pages_fast() on the
udata buffer. This will eliminate an additonal copy of kernel buffer into
user buffer. We filter out the kernel buffers (kernel_read()) by comparing
segments.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
---
 net/9p/client.c   |   18 ++++++++++++++++--
 net/9p/protocol.c |   33 +++++++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/net/9p/client.c b/net/9p/client.c
index 7ce58fb..d11c7dd 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -1282,6 +1282,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 	struct p9_client *clnt;
 	struct p9_req_t *req;
 	char *dataptr;
+	int page_direct = 0;
 
 	P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid,
 					(long long unsigned) offset, count);
@@ -1296,7 +1297,20 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 	if (count < rsize)
 		rsize = count;
 
-	req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize);
+	if (clnt->trans_mod->capability &&
+		clnt->trans_mod->capability(P9_CAP_GET_MAX_SG_PAGES) &&
+			(udata && !segment_eq(get_fs(), KERNEL_DS)))
+		page_direct = 1;
+
+	if (page_direct) {
+		rsize = count;
+		req = p9_client_rpc(clnt, P9_TREAD, "dqE", fid->fid, offset,
+				rsize, udata);
+	} else {
+		req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset,
+				rsize);
+	}
+
 	if (IS_ERR(req)) {
 		err = PTR_ERR(req);
 		goto error;
@@ -1314,7 +1328,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 		memmove(data, dataptr, count);
 	}
 
-	if (udata) {
+	if (udata && !page_direct) {
 		err = copy_to_user(udata, dataptr, count);
 		if (err) {
 			err = -EFAULT;
diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index 97f313d..b82d117 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -194,6 +194,25 @@ pdu_write_u(struct p9_fcall *pdu, struct p9_client *c, const char __user *udata,
 	return len;
 }
 
+	static size_t
+pdu_write_ur(struct p9_fcall *pdu, struct p9_client *c,
+		const char __user *udata, size_t size)
+{
+	size_t len = size;
+	int max_req_sg_pages = 0;
+
+	if (c->trans_mod->capability)
+		max_req_sg_pages =
+			c->trans_mod->capability(P9_CAP_GET_MAX_SG_PAGES);
+	if (max_req_sg_pages) {
+		len = pdu_fill_pages(pdu, udata, size, 1, max_req_sg_pages);
+		if (len < 0)
+			return len;
+		pdu->pdata_read_len = len;
+	}
+	return len;
+}
+
 /*
 	b - int8_t
 	w - int16_t
@@ -534,8 +553,18 @@ p9pdu_vwritef(struct p9_fcall *pdu, struct p9_client *c, const char *fmt,
 				if (!errcode &&
 					pdu_write_u(pdu, c, udata, count) < 0)
 					errcode = -EFAULT;
-			}
-			break;
+			 }
+			 break;
+		case 'E':{
+				 int32_t count = va_arg(ap, int32_t);
+				 const char __user *udata =
+					 va_arg(ap, const void __user *);
+				 errcode = p9pdu_writef(pdu, c, "d", count);
+				 if (!errcode &&
+					pdu_write_ur(pdu, c, udata, count) < 0)
+					errcode = -EFAULT;
+			 }
+			 break;
 		case 'T':{
 				int16_t nwname = va_arg(ap, int);
 				const char **wnames = va_arg(ap, const char **);
-- 
1.6.5.2


      parent reply	other threads:[~2010-08-17 17:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-17 17:27 [00/05] Add zero copy capability to virtio transport Venkateswararao Jujjuri (JV)
2010-08-17 17:27 ` [PATCH 1/5] [net/9p] Add capability() to p9_trans_module Venkateswararao Jujjuri (JV)
2010-08-17 20:43   ` [V9fs-developer] " Eric Van Hensbergen
2010-08-17 20:46     ` Latchesar Ionkov
2010-08-17 23:31       ` Venkateswararao Jujjuri (JV)
2010-08-18 15:16         ` Eric Van Hensbergen
2010-08-18 16:56           ` Venkateswararao Jujjuri (JV)
2010-08-18 18:26             ` Eric Van Hensbergen
2010-08-17 17:27 ` [PATCH 2/5] [net/9p] Pass p9_client structure to pdu perpartion routines Venkateswararao Jujjuri (JV)
2010-08-17 17:27 ` [PATCH 3/5] [net/9p] Add support for placing page addresses directly on the sg list Venkateswararao Jujjuri (JV)
2010-08-18 20:50   ` [V9fs-developer] " Latchesar Ionkov
2010-08-19 18:28     ` Venkateswararao Jujjuri (JV)
2010-08-19 18:49       ` Latchesar Ionkov
2010-08-19 20:47         ` Venkateswararao Jujjuri (JV)
2010-08-19 21:07           ` Latchesar Ionkov
2010-08-19 21:26             ` Eric Van Hensbergen
2010-08-19 23:35               ` Venkateswararao Jujjuri (JV)
2010-08-20  0:27                 ` Eric Van Hensbergen
2010-08-17 17:27 ` [PATCH 4/5] [net/9p] Achieve zero copy on write path Venkateswararao Jujjuri (JV)
2010-08-19 19:30   ` [V9fs-developer] " Latchesar Ionkov
2010-08-19 20:55     ` Venkateswararao Jujjuri (JV)
2010-08-17 17:27 ` Venkateswararao Jujjuri (JV) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1282066045-3945-6-git-send-email-jvrao@linux.vnet.ibm.com \
    --to=jvrao@linux.vnet.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=pbadari@us.ibm.com \
    --cc=v9fs-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).