From: Roger Larsson <roger.larsson@skelleftea.mail.telia.com>
To: George Greer <greerga@m-l.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [Bench] New benchmark showing fileserver problem in 2.4.12
Date: Fri, 19 Oct 2001 08:08:50 +0200 [thread overview]
Message-ID: <200110190614.f9J6E5A18498@maild.telia.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0110182252050.13061-100000@bacon.van.m-l.org>
In-Reply-To: <Pine.LNX.4.33.0110182252050.13061-100000@bacon.van.m-l.org>
On Friday 19 October 2001 04:53, you wrote:
> On Thu, 18 Oct 2001, Roger Larsson wrote:
> >On Thursday 18 October 2001 04:01, Leo Mauro wrote:
> >> Small fix to Linus's sample code
> >>
> >> unsigned int so_far = 0;
> >> for (;;) {
> >> int bytes = read(in, buf+so_far, BUFSIZE-so_far);
> >> if (bytes <= 0)
> >> break;
> >> so_far += bytes;
> >> if (so_far < BUFSIZE)
> >> continue;
> >> write(out, buf, BUFSIZE);
> >> - so_far = 0;
> >> + so_far -= BUFSIZE;
> >> }
> >> if (so_far)
> >> write(out, buf, so_far);
> >>
> >> to avoid losing data.
> >
> >I was close to press the send button but noticed the "BUFSIZE-so_far"
> >in the read call, just in time(TM).
> >
> >If it had not been there you would have needed to copy data from the
> >end of buf (from above BUFSIZE) to the beginning of buf too...
> >(the required size of buf would have been 2*BUFSIZE)
>
> Since you only ever have BUFSIZE bytes when you write, aren't:
>
> so_far -= BUFSIZE;
>
> and
>
> so_far = 0;
>
> identical? I'd say the assignment to 0 would be faster.
I was not specific enough. I intended to say that Linus code was ok.
And that if so_far -= BUFSIZE ever was something different from
zero you would need to move the read bytes too...
This code not using continue is probably easier to read...
(+ error checking...)
unsigned int so_far = 0;
for (;;) {
int bytes = read(in, buf+so_far, BUFSIZE-so_far);
if (bytes <= 0)
break;
so_far += bytes;
if (so_far == BUFSIZE) {
write(out, buf, BUFSIZE);
so_far = 0;
}
}
if (so_far)
write(out, buf, so_far);
/RogerL
--
Roger Larsson
Skellefteå
Sweden
next prev parent reply other threads:[~2001-10-19 6:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-17 13:06 Robert Cohen
2001-10-17 14:12 ` Marcelo Tosatti
2001-10-17 15:12 ` M. Edward Borasky
2001-10-17 15:18 ` John Stoffel
2001-10-17 15:47 ` Andreas Dilger
2001-10-17 16:44 ` Linus Torvalds
2001-10-18 2:01 ` Leo Mauro
2001-10-18 8:30 ` James Sutherland
2001-10-18 21:36 ` Roger Larsson
2001-10-19 2:53 ` George Greer
2001-10-19 6:08 ` Roger Larsson [this message]
[not found] ` <200110171644.f9HGinZ17717@penguin.transmeta.com>
2001-10-18 4:51 ` Robert Cohen
-- strict thread matches above, loose matches on Subject: below --
2001-10-16 9:07 Robert Cohen
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=200110190614.f9J6E5A18498@maild.telia.com \
--to=roger.larsson@skelleftea.mail.telia.com \
--cc=greerga@m-l.org \
--cc=linux-kernel@vger.kernel.org \
/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®