From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: Gunnar Ritter <Gunnar.Ritter@pluto.uni-freiburg.de>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
Steve French <smfltc@us.ibm.com>
Subject: Re: [PATCH 1/3] copyfile: generic_sendpage
Date: Tue, 7 Sep 2004 13:45:36 +0200 [thread overview]
Message-ID: <20040907114536.GA26630@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20040907110913.GA25802@wohnheim.fh-wedel.de>
On Tue, 7 September 2004 13:09:13 +0200, Jörn Engel wrote:
>
> I did the loop inside the kernel, so the syscall overhead is less of
> an issue. 4k is a safe bet for _really_ slow devices and if people
> want to increase it, hey, it's just a single constant to touch.
And a stupid bug I missed. Call sendfile with count>filesize and the
loop doesn't terminate. Fixed patch below.
Jörn
--
Premature optimization is the root of all evil.
-- Donald Knuth
Linus and Andrew are rightfully concerned about local DoS via a large
file->file sendfile(). This patch turns large sendfile() calls into a
loop of 4k chunks. After each chunk, it adds a cond_resched for
interactivity and a signal check to allow aborts etc. after the user
found out what a bad idea this may be.
Signed-off-by: Jörn Engel <joern@wohnheim.fh-wedel.de>
---
read_write.c | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletion(-)
--- linux-2.6.8cow/fs/read_write.c~sendfile_loop 2004-09-05 12:06:39.000000000 +0200
+++ linux-2.6.8cow/fs/read_write.c 2004-09-07 13:27:30.000000000 +0200
@@ -561,6 +561,35 @@
return ret;
}
+/**
+ * sendfile() of a 2GB file over usb1-attached hard drives can take a moment.
+ * This little loop is supposed to stop now and then to check for signals,
+ * reschedule and generally play nice with others.
+ */
+ssize_t inline __vfs_sendfile(struct file *in_file, loff_t *ppos, size_t count,
+ read_actor_t actor, struct file *out_file)
+{
+ ssize_t done = 0, ret;
+ while (count) {
+ size_t n = min(count, (size_t)4096);
+ ret = in_file->f_op->sendfile(in_file, ppos, n, actor,out_file);
+ if (ret < 0) {
+ if (done)
+ return done;
+ else
+ return ret;
+ }
+
+ done += ret;
+ count -= ret;
+
+ if ((ret == 0) || signal_pending(current))
+ break;
+ cond_resched();
+ }
+ return done;
+}
+
ssize_t vfs_sendfile(struct file *out_file, struct file *in_file, loff_t *ppos,
size_t count, loff_t max)
{
@@ -608,7 +637,7 @@
count = max - pos;
}
- ret = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor, out_file);
+ ret = __vfs_sendfile(in_file, ppos, count, file_send_actor, out_file);
if (*ppos > max)
return -EOVERFLOW;
next prev parent reply other threads:[~2004-09-07 11:46 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-04 16:57 [PATCH 1/3] copyfile: generic_sendpage Jörn Engel
2004-09-04 16:59 ` [PATCH 2/3] copyfile: sendfile Jörn Engel
2004-09-04 17:04 ` [PATCH 3/3] copyfile: copyfile Jörn Engel
2004-09-04 17:08 ` Jörn Engel
2004-09-04 17:11 ` [PATCH 2/3] copyfile: sendfile Christoph Hellwig
2004-09-04 17:16 ` Jörn Engel
2004-09-04 17:12 ` [PATCH 1/3] copyfile: generic_sendpage Christoph Hellwig
2004-09-04 17:22 ` Jörn Engel
2004-09-04 17:25 ` Christoph Hellwig
2004-09-07 8:32 ` Jan Blunck
2004-09-04 22:39 ` Andrew Morton
2004-09-05 0:16 ` William Lee Irwin III
2004-09-05 0:23 ` Andrew Morton
2004-09-06 11:54 ` Jörn Engel
2004-09-06 12:45 ` Gunnar Ritter
2004-09-06 13:35 ` Jörn Engel
2004-09-06 14:32 ` Gunnar Ritter
2004-09-06 14:46 ` Oliver Neukum
2004-09-06 15:51 ` Gunnar Ritter
2004-09-07 11:09 ` Jörn Engel
2004-09-07 11:45 ` Jörn Engel [this message]
2004-09-07 12:03 ` Gunnar Ritter
2004-09-07 12:08 ` Jörn Engel
2004-09-07 12:32 ` Gunnar Ritter
2004-09-07 11:48 ` Gunnar Ritter
2004-09-07 12:04 ` Jörn Engel
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=20040907114536.GA26630@wohnheim.fh-wedel.de \
--to=joern@wohnheim.fh-wedel.de \
--cc=Gunnar.Ritter@pluto.uni-freiburg.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=smfltc@us.ibm.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