linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pipe: save one pipe page
@ 2005-03-16  1:37 pmeda
  0 siblings, 0 replies; only message in thread
From: pmeda @ 2005-03-16  1:37 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm

Save one page in pipe writev without incuring additional
cost(just that ampersand operator).

Signed-off-by: Prasanna Meda <pmeda@akamai.com>

--- a/fs/pipe.c Sun Mar 13 11:01:45 2005
+++ b/fs/pipe.c	Sun Mar 13 11:55:00 2005
@@ -224,6 +224,7 @@
 	int do_wakeup;
 	struct iovec *iov = (struct iovec *)_iov;
 	size_t total_len;
+	ssize_t chars;
 
 	total_len = iov_length(iov, nr_segs);
 	/* Null write succeeds. */
@@ -242,24 +243,26 @@
 	}
 
 	/* We try to merge small writes */
-	if (info->nrbufs && total_len < PAGE_SIZE) {
+	chars = total_len & (PAGE_SIZE-1); /* size of the last buffer */
+	if (info->nrbufs && chars != 0) {
 		int lastbuf = (info->curbuf + info->nrbufs - 1) & (PIPE_BUFFERS-1);
 		struct pipe_buffer *buf = info->bufs + lastbuf;
 		struct pipe_buf_operations *ops = buf->ops;
 		int offset = buf->offset + buf->len;
-		if (ops->can_merge && offset + total_len <= PAGE_SIZE) {
+		if (ops->can_merge && offset + chars <= PAGE_SIZE) {
 			void *addr = ops->map(filp, info, buf);
-			int error = pipe_iov_copy_from_user(offset + addr, iov, total_len);
+			int error = pipe_iov_copy_from_user(offset + addr, iov, chars);
 			ops->unmap(info, buf);
 			ret = error;
 			do_wakeup = 1;
 			if (error)
 				goto out;
-			buf->len += total_len;
-			ret = total_len;
-			goto out;
+			buf->len += chars;
+			total_len -= chars;
+			ret = chars;
+			if (!total_len)
+				goto out;
 		}
-			
 	}
 
 	for (;;) {
@@ -271,7 +274,6 @@
 		}
 		bufs = info->nrbufs;
 		if (bufs < PIPE_BUFFERS) {
-			ssize_t chars;
 			int newbuf = (info->curbuf + bufs) & (PIPE_BUFFERS-1);
 			struct pipe_buffer *buf = info->bufs + newbuf;
 			struct page *page = info->tmp_page;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-03-16  1:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-16  1:37 [PATCH] pipe: save one pipe page pmeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox