This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: fread split in many read
- From: "Kaz Kylheku" <kaz at zeugmasystems dot com>
- To: "Nicolas Boulay" <nicolas dot boulay at gmail dot com>, <libc-alpha at sources dot redhat dot com>
- Date: Mon, 22 Jan 2007 10:55:46 -0800
- Subject: RE: fread split in many read
Nicolas Boulay wrote:
> Hello,
>
> I use strace on some program. And i could see that most of the time,
> the transfert get fragmented using 4K paquets.
You are using C streams (FILE *), which are buffered by default on
non-interactive devices. The default buffer size in glibc is 4096 bytes.
Streams are designed to efficiently support a mixture of variable length
transfer operations using functions like getc and putc, fread and write,
and fgets and fputs.
> Bloc layer are design to concatenate consecutive access. So why
> fragment to then defragement. Anticipatory scheduler wait for new read
> demand, i understood why it's so efficent if each fread are split.
Use read and write if you want to control the I/O transfer unit sizes,
and do I/O in large blocks.
You can tune the stream buffer size too. Read up on setvbuf.
> I don't check a lot the fwrite part, but i still see 4K write . Some
> file system tend to be atomic on write to avoid trashing file. So
> spliting write, destroy this feature.
A large write by itself does not guarantee atomicity. Atomic supersedes
require special logic in the filesystem. You can emulate atomic
supersede using the rename() operation: prepare a new version of the
file under a temporary name, and then move it over top of the old one.
You also need a recovery procedure in place that removes the temporary
files after a crash.