This discussion is archived
0 Replies Latest reply: Jan 27, 2012 2:29 AM by 814261 RSS

Synchronous writes

814261 Newbie
Currently Being Moderated
Im looking for help to find out what is correct way to determine when process doing synchronous writes to files.

As much as I understand synchronous writes happens when you open file with O_SYNC and O_DSYNC and perform write call.

I have created small C test with O_SYNC:
write_sync.c
----------------------------
int main()
{

srand ( time(NULL) );
char *filename = "test.txt";
char buf[4];
sprintf(buf,"%d",rand());

int ftest=access("test.txt",F_OK);
int fd = open (filename, O_WRONLY | O_CREAT |O_SYNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
write(fd, buf, sizeof(buf));
close(fd);
}
--------------------------------

Dtrace show this on io:

dtrace -n 'io:::start / execname == "write_sync"/ {printf("%s %d %d %s",execname,args[0]->b_flags,args[0]->b_bufsize,args[2]->fi_pathname);}'

dtrace: description 'io:::start ' matched 6 probes

CPU ID FUNCTION:NAME
11 3381 bdev_strategy:start write_sync 524561 1024 /export/home/user/test.txt
11 3381 bdev_strategy:start write_sync 257 0 <none>
11 3381 bdev_strategy:start write_sync 257 0 <none>
11 3381 bdev_strategy:start write_sync 16777489 0 /export/home/user/test.txt
11 3381 bdev_strategy:start write_sync 16777489 0 /export/home/user/test.txt
11 3381 bdev_strategy:start write_sync 257 0 <none>
11 3381 bdev_strategy:start write_sync 257 0 <none>
11 3381 bdev_strategy:start write_sync 257 0 <none>
11 3381 bdev_strategy:start write_sync 16777473 0 <none>
11 3381 bdev_strategy:start write_sync 16777473 0 <none>

As I see buffer size shows only in first line 1024 and it cold be write I looking for. So b_flags for this write is 524561 and value according to /usr/include/sys/buf.h means:

0x0001 B_BUSY -> not on av_forw/back list
0x0010 B_PAGEIO -> do I/O to pages on bp->p_pages
0x0100 B_WRITE -> non-read pseudo-flag
0x080000 B_NOCACHE -> dont cache block when released

So if this true than you can find all sync writes with
dtrace -n 'io:::start / args[0]->b_flags == 524561 / {@Z[execname,args[2]->fi_pathname]=count();}'

This is how far I got and I'm not really sure if this is correct way.

P.S. sorry for my english

Edited by: 811258 on Jan 27, 2012 2:23 AM

Edited by: 811258 on Jan 27, 2012 2:24 AM

Edited by: 811258 on Jan 27, 2012 2:28 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points