linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: viro@ZenIV.linux.org.uk
Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org,
	linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 17/27] afs: Use a bvec rather than a kvec in afs_send_pages()
Date: Thu, 09 Mar 2017 18:57:46 +0000	[thread overview]
Message-ID: <148908586613.16794.7161660908436275432.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <148908574888.16794.14109877851518811944.stgit@warthog.procyon.org.uk>

Use a bvec rather than a kvec in afs_send_pages() as we don't then have to
call kmap() in advance.  This allows us to pass the array of contiguous
pages that we extracted through to rxrpc in one go rather than passing a
single page at a time.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/afs/rxrpc.c |   97 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 52 insertions(+), 45 deletions(-)

diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 419ef05dcb5e..bf45307ff201 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -259,67 +259,74 @@ void afs_flat_call_destructor(struct afs_call *call)
 	call->buffer = NULL;
 }
 
+#define AFS_BVEC_MAX 8
+
+/*
+ * Load the given bvec with the next few pages.
+ */
+static void afs_load_bvec(struct afs_call *call, struct msghdr *msg,
+			  struct bio_vec *bv, pgoff_t first, pgoff_t last,
+			  unsigned offset)
+{
+	struct page *pages[AFS_BVEC_MAX];
+	unsigned int nr, n, i, to, bytes = 0;
+
+	nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX);
+	n = find_get_pages_contig(call->mapping, first, nr, pages);
+	ASSERTCMP(n, ==, nr);
+
+	msg->msg_flags |= MSG_MORE;
+	for (i = 0; i < nr; i++) {
+		to = PAGE_SIZE;
+		if (first + i >= last) {
+			to = call->last_to;
+			msg->msg_flags &= ~MSG_MORE;
+		}
+		bv[i].bv_page = pages[i];
+		bv[i].bv_len = to - offset;
+		bv[i].bv_offset = offset;
+		bytes += to - offset;
+		offset = 0;
+	}
+
+	iov_iter_bvec(&msg->msg_iter, WRITE | ITER_BVEC, bv, nr, bytes);
+}
+
 /*
  * attach the data from a bunch of pages on an inode to a call
  */
 static int afs_send_pages(struct afs_call *call, struct msghdr *msg)
 {
-	struct page *pages[8];
-	unsigned count, n, loop, offset, to;
+	struct bio_vec bv[AFS_BVEC_MAX];
+	unsigned int bytes, nr, loop, offset;
 	pgoff_t first = call->first, last = call->last;
 	int ret;
 
-	_enter("");
-
 	offset = call->first_offset;
 	call->first_offset = 0;
 
 	do {
-		_debug("attach %lx-%lx", first, last);
-
-		count = last - first + 1;
-		if (count > ARRAY_SIZE(pages))
-			count = ARRAY_SIZE(pages);
-		n = find_get_pages_contig(call->mapping, first, count, pages);
-		ASSERTCMP(n, ==, count);
-
-		loop = 0;
-		do {
-			struct bio_vec bvec = {.bv_page = pages[loop],
-					       .bv_offset = offset};
-			msg->msg_flags = 0;
-			to = PAGE_SIZE;
-			if (first + loop >= last)
-				to = call->last_to;
-			else
-				msg->msg_flags = MSG_MORE;
-			bvec.bv_len = to - offset;
-			offset = 0;
-
-			_debug("- range %u-%u%s",
-			       offset, to, msg->msg_flags ? " [more]" : "");
-			iov_iter_bvec(&msg->msg_iter, WRITE | ITER_BVEC,
-				      &bvec, 1, to - offset);
-
-			/* have to change the state *before* sending the last
-			 * packet as RxRPC might give us the reply before it
-			 * returns from sending the request */
-			if (first + loop >= last)
-				call->state = AFS_CALL_AWAIT_REPLY;
-			ret = rxrpc_kernel_send_data(afs_socket, call->rxcall,
-						     msg, to - offset);
-			if (ret < 0)
-				break;
-		} while (++loop < count);
-		first += count;
-
-		for (loop = 0; loop < count; loop++)
-			put_page(pages[loop]);
+		afs_load_bvec(call, msg, bv, first, last, offset);
+		offset = 0;
+		bytes = msg->msg_iter.count;
+		nr = msg->msg_iter.nr_segs;
+
+		/* Have to change the state *before* sending the last
+		 * packet as RxRPC might give us the reply before it
+		 * returns from sending the request.
+		 */
+		if (first + nr >= last)
+			call->state = AFS_CALL_AWAIT_REPLY;
+		ret = rxrpc_kernel_send_data(afs_socket, call->rxcall,
+					     msg, bytes);
+		for (loop = 0; loop < nr; loop++)
+			put_page(bv[loop].bv_page);
 		if (ret < 0)
 			break;
+
+		first += nr;
 	} while (first <= last);
 
-	_leave(" = %d", ret);
 	return ret;
 }
 

  parent reply	other threads:[~2017-03-09 18:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-09 18:55 [PATCH 01/27] afs: Fix missing put_page() David Howells
2017-03-09 18:55 ` [PATCH 02/27] afs: Fix page overput in afs_fill_page() David Howells
2017-03-09 18:56 ` [PATCH 03/27] afs: Populate group ID from vnode status David Howells
2017-03-09 18:56 ` [PATCH 04/27] afs: Adjust mode bits processing David Howells
2017-03-09 18:56 ` [PATCH 05/27] afs: Deal with an empty callback array David Howells
2017-03-09 18:56 ` [PATCH 06/27] afs: Handle better the server returning excess or short data David Howells
2017-03-09 18:56 ` [PATCH 07/27] afs: Kill struct afs_read::pg_offset David Howells
2017-03-09 18:56 ` [PATCH 08/27] afs: Handle a short write to an AFS page David Howells
2017-03-09 18:56 ` [PATCH 09/27] afs: Flush outstanding writes when an fd is closed David Howells
2017-03-09 18:56 ` [PATCH 10/27] afs: Distinguish mountpoints from symlinks by file mode alone David Howells
2017-03-09 18:57 ` [PATCH 11/27] afs: inode: Replace rcu_assign_pointer() with RCU_INIT_POINTER() David Howells
2017-03-09 18:57 ` [PATCH 12/27] afs: security: " David Howells
2017-03-09 18:57 ` [PATCH 13/27] afs: Migrate vlocation fields to 64-bit David Howells
2017-03-09 18:57 ` [PATCH 14/27] afs: Prevent callback expiry timer overflow David Howells
2017-03-09 18:57 ` [PATCH 15/27] afs: Fix AFS read bug David Howells
2017-03-09 18:57 ` [PATCH 16/27] afs: Make struct afs_read::remain 64-bit David Howells
2017-03-09 18:57 ` David Howells [this message]
2017-03-09 18:57 ` [PATCH 18/27] afs: Fix the maths in afs_fs_store_data() David Howells
2017-03-09 18:58 ` [PATCH 19/27] afs: Invalid op ID should abort with RXGEN_OPCODE David Howells
2017-03-09 18:58 ` [PATCH 20/27] afs: Better abort and net error handling David Howells
2017-03-09 18:58 ` [PATCH 21/27] afs: Populate and use client modification time David Howells
2017-03-09 18:58 ` [PATCH 22/27] afs: Don't set PG_error on local EINTR or ENOMEM when filling a page David Howells
2017-03-09 18:58 ` [PATCH 23/27] afs: Fix page leak in afs_write_begin() David Howells
2017-03-09 18:58 ` [PATCH 24/27] afs: afs_fsync() does two flushes, one of which is redundant David Howells
2017-03-09 18:58 ` [PATCH 25/27] afs: Fix afs_kill_pages() David Howells
2017-03-09 18:58 ` [PATCH 26/27] afs: Fix an off-by-one error in afs_send_pages() David Howells
2017-03-09 18:58 ` [PATCH 27/27] afs: Fix abort on signal while waiting for call completion David Howells

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=148908586613.16794.7161660908436275432.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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).