LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-03-2011, 03:26 PM   #1
mroht
LQ Newbie
 
Registered: Jun 2011
Distribution: Debian, Ubuntu, Enterprise stuff (at work...)
Posts: 4

Rep: Reputation: Disabled
why are 3 IOs produced by writing one byte via write()?


hi,

i play around with c for producing some io to a san-disk and struggle with basics here. :-(

if i'm using the write()-call to write 1 byte to a file on the disk iostat tells me i'm producing 3 writes. if i write 1 byte twice a second, it tells me i produce 6 writes (w/s).

of course i'm sure there's no other traffic to the disk. :-)

can anyone explain? i would expect iostat tells me 1w/s or 2w/s.

sorry if this is a dumb question...
 
Old 06-03-2011, 06:33 PM   #2
Rearden888
LQ Newbie
 
Registered: Jan 2010
Location: Anacortes, WA
Distribution: Arch, Debian, CentOS
Posts: 27
Blog Entries: 2

Rep: Reputation: 3
Might have something to do with the journaling for the file system? What kind of filesystem are you writing to?
 
1 members found this post helpful.
Old 06-03-2011, 11:12 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,336

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
Try strace.
 
Old 06-04-2011, 03:02 AM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
What about file metadata?
 
1 members found this post helpful.
Old 06-04-2011, 09:31 AM   #5
mroht
LQ Newbie
 
Registered: Jun 2011
Distribution: Debian, Ubuntu, Enterprise stuff (at work...)
Posts: 4

Original Poster
Rep: Reputation: Disabled
thanks for your replies. i'm using ext3 (so journaling could be the point?). strace does nothing strange / all works as expected:

Code:
[...]
# load glibc
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY) = 3
[...]
# open the file with sync-flag (got file-descriptor nr 3)
open("/mnt/testdevice/io", O_WRONLY|O_CREAT|O_TRUNC|O_DSYNC, 0644) = 3
[...]
# write 1 byte to fd nr 3
write(3, "\0", 1)                       = 1
[...]
# close the file
close(3)                                = 0
[...]
if it is the journaling/metadata-thing which produces the additional io, i should be able kick it by working directly on the device-node (e.g. /dev/mapper/<mydevice>) instead of opening a file on a journaling fs, right?

*nargh*, seems that loop-devices could not be monitored by
Code:
iostat -d <device-node> -x 1
& i don't have a "real" device/partition to test it until monday...

any further ideas? can i track the behaviour by using the sources without being a guru? i tried to look inside the glibc source, but i'm a rookie in this stuff. even not sure if i got the right snippet, but if so, i don't understand it (seems to do nothing but checking for false arguments?)

Code:
# /usr/src/glibc/eglibc-2.13/io/write.c
[...]

/* Write NBYTES of BUF to FD.  Return the number written, or -1.  */
ssize_t __libc_write (int fd, const void *buf, size_t nbytes)
{
  if (nbytes == 0)
    return 0;
  if (fd < 0)
    {
      __set_errno (EBADF);
      return -1;
    }
  if (buf == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  __set_errno (ENOSYS);
  return -1;
}
libc_hidden_def (__libc_write)
stub_warning (write)

weak_alias (__libc_write, __write)
libc_hidden_weak (__write)
weak_alias (__libc_write, write)
#include <stub-tag.h>
 
Old 06-04-2011, 09:43 AM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,464

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Hi

Just a guess, but it could have to do with the updating of timestamps. When you write a character to a file, it has to update the timestamps - both in the inode of the directory entry of that file, as well as the directory itself.
 
1 members found this post helpful.
Old 06-04-2011, 10:05 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,336

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
If you're putting (more) software block device drivers between the application and the "real" (FSVO "real") ,I/O block device drivers, all bets are off.
 
Old 06-04-2011, 11:24 AM   #8
mroht
LQ Newbie
 
Registered: Jun 2011
Distribution: Debian, Ubuntu, Enterprise stuff (at work...)
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
If you're putting (more) software block device drivers between the application and the "real" (FSVO "real") ,I/O block device drivers, all bets are off.
yupp, i just guessed loop-device-io would be measurable the same way other block-device-abstractions are. but you're right - iostat tells me, whatever i do, no io at all for loop-devices...

hope monday is far far away but i will test "raw-access" to the dev-node itself then.
 
Old 06-06-2011, 12:26 PM   #9
mroht
LQ Newbie
 
Registered: Jun 2011
Distribution: Debian, Ubuntu, Enterprise stuff (at work...)
Posts: 4

Original Poster
Rep: Reputation: Disabled
hi. just wanted to share the "results": it's definitely the metadata/journal-stuff. i tried writing the device-node itself and all works as expected (1 byte write -> 1 IO (using SYNC-flag of course)). mounting an ext3 with noatime etc. does not improve anything, using ext2 produces lesser IO as ext3. thanks for your input!
btw. if anyone has links which describe IO-related stuff in depth/detail (write() -> libc() -> kernel / fc-stuff) - i would like to read it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to copy an entire disk byte-for-byte Pawprint Linux - Software 6 06-16-2011 12:01 PM
write network packets to memory in byte format ehsanen77 Linux - Networking 2 02-12-2011 12:52 AM
byte to byte remote comparison louisJ Linux - Newbie 3 09-21-2007 06:28 PM
c++ ios::app and ios::ate gearoid_murphy Programming 6 04-08-2006 08:01 AM
difference between distro produced by group vs. produced by single person lostsoul Linux - General 2 04-08-2004 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration