From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: linux-kernel@vger.kernel.org
Cc: Amit Shah <amit.shah@redhat.com>,
Anthony Liguori <anthony@codemonkey.ws>,
Arnd Bergmann <arnd@arndb.de>, Borislav Petkov <bp@amd64.org>,
"Franch Ch. Eigler" <fche@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Herbert Xu <herbert@gondor.hengli.com.au>,
Ingo Molnar <mingo@redhat.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Steven Rostedt <rostedt@goodmis.org>,
virtualization@lists.linux-foundation.org, qemu-devel@nongnu.org,
yrl.pp-manager.tt@hitachi.com,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Subject: [PATCH V2 5/6] virtio/console: Allocate scatterlist according to the current pipe size
Date: Thu, 09 Aug 2012 21:31:20 +0900 [thread overview]
Message-ID: <20120809123120.8542.10604.stgit@ltc189.sdl.hitachi.co.jp> (raw)
In-Reply-To: <20120809123029.8542.38311.stgit@ltc189.sdl.hitachi.co.jp>
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Allocate scatterlist according to the current pipe size.
This allows splicing bigger buffer if the pipe size has
been changed by fcntl.
Changes in v2:
- Just a minor fix for avoiding a confliction with previous patch.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
drivers/char/virtio_console.c | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b2fc2ab..e88f843 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -229,7 +229,6 @@ struct port {
bool guest_connected;
};
-#define MAX_SPLICE_PAGES 32
/* This is the very early arch-specified put chars function. */
static int (*early_put_chars)(u32, const char *, int);
@@ -482,15 +481,16 @@ struct buffer_token {
void *buf;
struct scatterlist *sg;
} u;
- bool sgpages;
+ /* If sgpages == 0 then buf is used, else sg is used */
+ unsigned int sgpages;
};
-static void reclaim_sg_pages(struct scatterlist *sg)
+static void reclaim_sg_pages(struct scatterlist *sg, unsigned int nrpages)
{
int i;
struct page *page;
- for (i = 0; i < MAX_SPLICE_PAGES; i++) {
+ for (i = 0; i < nrpages; i++) {
page = sg_page(&sg[i]);
if (!page)
break;
@@ -511,7 +511,7 @@ static void reclaim_consumed_buffers(struct port *port)
}
while ((tok = virtqueue_get_buf(port->out_vq, &len))) {
if (tok->sgpages)
- reclaim_sg_pages(tok->u.sg);
+ reclaim_sg_pages(tok->u.sg, tok->sgpages);
else
kfree(tok->u.buf);
kfree(tok);
@@ -581,7 +581,7 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count,
tok = kmalloc(sizeof(*tok), GFP_ATOMIC);
if (!tok)
return -ENOMEM;
- tok->sgpages = false;
+ tok->sgpages = 0;
tok->u.buf = in_buf;
sg_init_one(sg, in_buf, in_count);
@@ -597,7 +597,7 @@ static ssize_t send_pages(struct port *port, struct scatterlist *sg, int nents,
tok = kmalloc(sizeof(*tok), GFP_ATOMIC);
if (!tok)
return -ENOMEM;
- tok->sgpages = true;
+ tok->sgpages = nents;
tok->u.sg = sg;
return __send_to_port(port, sg, nents, in_count, tok, nonblock);
@@ -797,6 +797,7 @@ out:
struct sg_list {
unsigned int n;
+ unsigned int size;
size_t len;
struct scatterlist *sg;
};
@@ -807,7 +808,7 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
struct sg_list *sgl = sd->u.data;
unsigned int offset, len;
- if (sgl->n == MAX_SPLICE_PAGES)
+ if (sgl->n == sgl->size)
return 0;
/* Try lock this page */
@@ -868,12 +869,12 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
sgl.n = 0;
sgl.len = 0;
- sgl.sg = kmalloc(sizeof(struct scatterlist) * MAX_SPLICE_PAGES,
- GFP_KERNEL);
+ sgl.size = pipe->nrbufs;
+ sgl.sg = kmalloc(sizeof(struct scatterlist) * sgl.size, GFP_KERNEL);
if (unlikely(!sgl.sg))
return -ENOMEM;
- sg_init_table(sgl.sg, MAX_SPLICE_PAGES);
+ sg_init_table(sgl.sg, sgl.size);
ret = __splice_from_pipe(pipe, &sd, pipe_to_sg);
if (likely(ret > 0))
ret = send_pages(port, sgl.sg, sgl.n, sgl.len, true);
next prev parent reply other threads:[~2012-08-09 12:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-09 12:30 [PATCH V2 0/6] virtio-trace: Support virtio-trace Yoshihiro YUNOMAE
2012-08-09 12:30 ` [PATCH V2 1/6] virtio/console: Add splice_write support Yoshihiro YUNOMAE
2012-08-09 12:30 ` [PATCH V2 2/6] virtio/console: Add a failback for unstealable pipe buffer Yoshihiro YUNOMAE
2012-08-09 12:31 ` [PATCH V2 3/6] virtio/console: Wait until the port is ready on splice Yoshihiro YUNOMAE
2012-08-09 12:31 ` [PATCH V2 4/6] ftrace: Allow stealing pages from pipe buffer Yoshihiro YUNOMAE
2012-08-09 12:31 ` Yoshihiro YUNOMAE [this message]
2012-08-09 12:31 ` [PATCH V2 6/6] tools: Add guest trace agent as a user tool Yoshihiro YUNOMAE
2012-08-12 23:28 ` [PATCH V2 0/6] virtio-trace: Support virtio-trace Rusty Russell
2012-08-21 5:16 ` Amit Shah
2012-08-21 12:33 ` Masami Hiramatsu
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=20120809123120.8542.10604.stgit@ltc189.sdl.hitachi.co.jp \
--to=yoshihiro.yunomae.ez@hitachi.com \
--cc=amit.shah@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=arnd@arndb.de \
--cc=bp@amd64.org \
--cc=fche@redhat.com \
--cc=fweisbec@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.hengli.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
--cc=yrl.pp-manager.tt@hitachi.com \
/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
all inboxes | Powered by JetHome®