Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
677b06ca
Commit
677b06ca
authored
Jan 15, 2011
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply patch for test_fsync to add tests for O_DIRECT.
Adjusted patch by Josh Berkus
parent
8f5d65e9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
249 additions
and
32 deletions
+249
-32
src/tools/fsync/Makefile
src/tools/fsync/Makefile
+2
-2
src/tools/fsync/README
src/tools/fsync/README
+15
-6
src/tools/fsync/test_fsync.c
src/tools/fsync/test_fsync.c
+232
-24
No files found.
src/tools/fsync/Makefile
View file @
677b06ca
...
@@ -16,9 +16,9 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
...
@@ -16,9 +16,9 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS
=
test_fsync.o
OBJS
=
test_fsync.o
all
:
test_fsync
all
:
submake-libpq submake-libpgport
test_fsync
test_fsync
:
test_fsync.o
| submake-libpq submake-libpgport
test_fsync
:
test_fsync.o
$(libpq_builddir)/libpq.a
$(CC)
$(CFLAGS)
test_fsync.o
$(libpq_pgport)
$(LDFLAGS)
$(LDFLAGS_EX)
$(LIBS)
-o
$@$(X)
$(CC)
$(CFLAGS)
test_fsync.o
$(libpq_pgport)
$(LDFLAGS)
$(LDFLAGS_EX)
$(LIBS)
-o
$@$(X)
clean distclean maintainer-clean
:
clean distclean maintainer-clean
:
...
...
src/tools/fsync/README
View file @
677b06ca
src/tools/fsync/README
test_fsync
==========
fsync
=====
This program tests fsync. The tests are described as part of the program output.
This program tests fsync. The tests are described as part of the program output.
Usage: test_fsync [-f filename] [loops]
Usage: test_fsync [-f filename] [loops]
Loops defaults to 5000. The default output file is /var/tmp/test_fsync.out.
test_fsync is intended to give you a reasonable idea of what the fastest
Consider that /tmp or /var/tmp might be memory-based file systems.
fsync_method is on your specific system, as well as supplying diagnostic
information in the event of an identified I/O problem. However,
differences shown by test_fsync might not make any difference in real
database throughput, especially since many database servers are not
speed-limited by their transaction logs.
The output filename defaults to test_fsync.out in the current directory.
test_fsync should be run in the same filesystem as your transaction log
directory (pg_xlog).
Loops default to 2000. Increase this to get more accurate measurements.
src/tools/fsync/test_fsync.c
View file @
677b06ca
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
*
*
* test_fsync.c
* test_fsync.c
* test
various
fsync() methods
* test
s all supported
fsync() methods
*/
*/
#include "postgres.h"
#include "postgres.h"
...
@@ -22,19 +22,18 @@
...
@@ -22,19 +22,18 @@
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include <string.h>
/*
#ifdef WIN32
* put the temp files in the local directory
* unless the user specifies otherwise
*/
#define FSYNC_FILENAME "./test_fsync.out"
#define FSYNC_FILENAME "./test_fsync.out"
#else
/* /tmp might be a memory file system */
#define FSYNC_FILENAME "/var/tmp/test_fsync.out"
#endif
#define WRITE_SIZE (8 * 1024)
/* 8k */
#define WRITE_SIZE (8 * 1024)
/* 8k */
#define LABEL_FORMAT "\t%-30s"
#define LABEL_FORMAT "\t%-30s"
int
loops
=
10000
;
int
loops
=
2000
;
void
die
(
char
*
str
);
void
die
(
char
*
str
);
void
print_elapse
(
struct
timeval
start_t
,
struct
timeval
stop_t
);
void
print_elapse
(
struct
timeval
start_t
,
struct
timeval
stop_t
);
...
@@ -42,14 +41,14 @@ void print_elapse(struct timeval start_t, struct timeval stop_t);
...
@@ -42,14 +41,14 @@ void print_elapse(struct timeval start_t, struct timeval stop_t);
int
int
main
(
int
argc
,
char
*
argv
[])
main
(
int
argc
,
char
*
argv
[])
{
{
struct
timeval
start_t
;
struct
timeval
start_t
,
stop_t
;
struct
timeval
stop_t
;
int
tmpfile
,
i
;
int
tmpfile
,
i
;
char
*
full_buf
=
(
char
*
)
malloc
(
XLOG_SEG_SIZE
),
char
*
full_buf
=
(
char
*
)
malloc
(
XLOG_SEG_SIZE
),
*
buf
;
*
buf
,
*
filename
=
FSYNC_FILENAME
;
char
*
filename
=
FSYNC_FILENAME
;
/*
* arguments: loops and filename (optional)
*/
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"-f"
)
==
0
)
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"-f"
)
==
0
)
{
{
filename
=
argv
[
2
];
filename
=
argv
[
2
];
...
@@ -63,11 +62,16 @@ main(int argc, char *argv[])
...
@@ -63,11 +62,16 @@ main(int argc, char *argv[])
for
(
i
=
0
;
i
<
XLOG_SEG_SIZE
;
i
++
)
for
(
i
=
0
;
i
<
XLOG_SEG_SIZE
;
i
++
)
full_buf
[
i
]
=
random
();
full_buf
[
i
]
=
random
();
/*
* test if we can open the target file
*/
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
O_CREAT
,
S_IRUSR
|
S_IWUSR
))
==
-
1
)
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
O_CREAT
,
S_IRUSR
|
S_IWUSR
))
==
-
1
)
die
(
"Cannot open output file."
);
die
(
"Cannot open output file."
);
if
(
write
(
tmpfile
,
full_buf
,
XLOG_SEG_SIZE
)
!=
XLOG_SEG_SIZE
)
if
(
write
(
tmpfile
,
full_buf
,
XLOG_SEG_SIZE
)
!=
XLOG_SEG_SIZE
)
die
(
"write failed"
);
die
(
"write failed"
);
/* fsync now so later fsync's don't have to do it */
/*
* fsync now so that dirty buffers don't skew later tests
*/
if
(
fsync
(
tmpfile
)
!=
0
)
if
(
fsync
(
tmpfile
)
!=
0
)
die
(
"fsync failed"
);
die
(
"fsync failed"
);
close
(
tmpfile
);
close
(
tmpfile
);
...
@@ -77,7 +81,7 @@ main(int argc, char *argv[])
...
@@ -77,7 +81,7 @@ main(int argc, char *argv[])
printf
(
"Loops = %d
\n\n
"
,
loops
);
printf
(
"Loops = %d
\n\n
"
,
loops
);
/*
/*
*
Simple write
*
Test a simple write without fsync
*/
*/
printf
(
"Simple write:
\n
"
);
printf
(
"Simple write:
\n
"
);
printf
(
LABEL_FORMAT
,
"8k write"
);
printf
(
LABEL_FORMAT
,
"8k write"
);
...
@@ -95,10 +99,13 @@ main(int argc, char *argv[])
...
@@ -95,10 +99,13 @@ main(int argc, char *argv[])
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
/*
*
Compare file sync methods with one 8k write
*
Test all fsync methods using single 8k writes
*/
*/
printf
(
"
\n
Compare file sync methods using one write:
\n
"
);
printf
(
"
\n
Compare file sync methods using one write:
\n
"
);
/*
* Test open_datasync if available
*/
#ifdef OPEN_DATASYNC_FLAG
#ifdef OPEN_DATASYNC_FLAG
printf
(
LABEL_FORMAT
,
"open_datasync 8k write"
);
printf
(
LABEL_FORMAT
,
"open_datasync 8k write"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -115,10 +122,40 @@ main(int argc, char *argv[])
...
@@ -115,10 +122,40 @@ main(int argc, char *argv[])
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
* If O_DIRECT is enabled, test that with open_datasync
*/
#if PG_O_DIRECT != 0
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
O_DSYNC
|
PG_O_DIRECT
,
0
))
==
-
1
)
printf
(
"
\t
(unavailable: o_direct on this filesystem)
\n
"
);
else
{
printf
(
LABEL_FORMAT
,
"open_datasync 8k direct I/O write"
);
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
}
#else
printf
(
"
\t
(unavailable: o_direct)
\n
"
);
#endif
#else
#else
printf
(
"
\t
(unavailable: open_datasync)
\n
"
);
printf
(
"
\t
(unavailable: open_datasync)
\n
"
);
#endif
#endif
/*
* Test open_sync if available
*/
#ifdef OPEN_SYNC_FLAG
#ifdef OPEN_SYNC_FLAG
printf
(
LABEL_FORMAT
,
"open_sync 8k write"
);
printf
(
LABEL_FORMAT
,
"open_sync 8k write"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -135,10 +172,40 @@ main(int argc, char *argv[])
...
@@ -135,10 +172,40 @@ main(int argc, char *argv[])
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
* If O_DIRECT is enabled, test that with open_sync
*/
#if PG_O_DIRECT != 0
printf
(
LABEL_FORMAT
,
"open_sync 8k direct I/O write"
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
OPEN_SYNC_FLAG
|
PG_O_DIRECT
,
0
))
==
-
1
)
printf
(
"
\t
(unavailable: o_direct on this filesystem)
\n
"
);
else
{
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
}
#else
printf
(
"
\t
(unavailable: o_direct)
\n
"
);
#endif
#else
#else
printf
(
"
\t
(unavailable: open_sync)
\n
"
);
printf
(
"
\t
(unavailable: open_sync)
\n
"
);
#endif
#endif
/*
* Test fdatasync if available
*/
#ifdef HAVE_FDATASYNC
#ifdef HAVE_FDATASYNC
printf
(
LABEL_FORMAT
,
"8k write, fdatasync"
);
printf
(
LABEL_FORMAT
,
"8k write, fdatasync"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -160,6 +227,9 @@ main(int argc, char *argv[])
...
@@ -160,6 +227,9 @@ main(int argc, char *argv[])
printf
(
"
\t
(unavailable: fdatasync)
\n
"
);
printf
(
"
\t
(unavailable: fdatasync)
\n
"
);
#endif
#endif
/*
* Test fsync
*/
printf
(
LABEL_FORMAT
,
"8k write, fsync"
);
printf
(
LABEL_FORMAT
,
"8k write, fsync"
);
fflush
(
stdout
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
...
@@ -178,11 +248,40 @@ main(int argc, char *argv[])
...
@@ -178,11 +248,40 @@ main(int argc, char *argv[])
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
* If fsync_writethrough is available, test as well
*/
#ifdef HAVE_FSYNC_WRITETHROUGH
printf
(
LABEL_FORMAT
,
"8k write, fsync_writethrough"
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
die
(
"Cannot open output file."
);
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
fcntl
(
tmpfile
,
F_FULLFSYNC
)
!=
0
)
die
(
"fsync failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
#else
printf
(
"
\t
(unavailable: fsync_writethrough)
\n
"
);
#endif
/*
/*
* Compare file sync methods with two 8k write
* Compare some of the file sync methods with
* two 8k writes to see if timing is different
*/
*/
printf
(
"
\n
Compare file sync methods using two writes:
\n
"
);
printf
(
"
\n
Compare file sync methods using two writes:
\n
"
);
/*
* Test open_datasync with and without o_direct
*/
#ifdef OPEN_DATASYNC_FLAG
#ifdef OPEN_DATASYNC_FLAG
printf
(
LABEL_FORMAT
,
"2 open_datasync 8k writes"
);
printf
(
LABEL_FORMAT
,
"2 open_datasync 8k writes"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -201,10 +300,36 @@ main(int argc, char *argv[])
...
@@ -201,10 +300,36 @@ main(int argc, char *argv[])
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
#if PG_O_DIRECT != 0
printf
(
LABEL_FORMAT
,
"2 open_datasync direct I/O 8k writes"
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
O_DSYNC
|
PG_O_DIRECT
,
0
))
==
-
1
)
die
(
"Cannot open output file."
);
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
#else
printf
(
"
\t
(unavailable: o_direct)
\n
"
);
#endif
#else
#else
printf
(
"
\t
(unavailable: open_datasync)
\n
"
);
printf
(
"
\t
(unavailable: open_datasync)
\n
"
);
#endif
#endif
/*
* Test open_sync with and without o_direct
*/
#ifdef OPEN_SYNC_FLAG
#ifdef OPEN_SYNC_FLAG
printf
(
LABEL_FORMAT
,
"2 open_sync 8k writes"
);
printf
(
LABEL_FORMAT
,
"2 open_sync 8k writes"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -223,8 +348,36 @@ main(int argc, char *argv[])
...
@@ -223,8 +348,36 @@ main(int argc, char *argv[])
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
#if PG_O_DIRECT != 0
printf
(
LABEL_FORMAT
,
"2 open_sync direct I/O 8k writes"
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
|
OPEN_SYNC_FLAG
|
PG_O_DIRECT
,
0
))
==
-
1
)
die
(
"Cannot open output file."
);
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
#else
printf
(
"
\t
(unavailable: o_direct)
\n
"
);
#endif
#endif
#else
printf
(
"
\t
(unavailable: open_sync)
\n
"
);
#endif
/*
* Test fdatasync
*/
#ifdef HAVE_FDATASYNC
#ifdef HAVE_FDATASYNC
printf
(
LABEL_FORMAT
,
"8k write, 8k write, fdatasync"
);
printf
(
LABEL_FORMAT
,
"8k write, 8k write, fdatasync"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -248,6 +401,9 @@ main(int argc, char *argv[])
...
@@ -248,6 +401,9 @@ main(int argc, char *argv[])
printf
(
"
\t
(unavailable: fdatasync)
\n
"
);
printf
(
"
\t
(unavailable: fdatasync)
\n
"
);
#endif
#endif
/*
* Test basic fsync
*/
printf
(
LABEL_FORMAT
,
"8k write, 8k write, fsync"
);
printf
(
LABEL_FORMAT
,
"8k write, 8k write, fsync"
);
fflush
(
stdout
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
...
@@ -268,11 +424,43 @@ main(int argc, char *argv[])
...
@@ -268,11 +424,43 @@ main(int argc, char *argv[])
close
(
tmpfile
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
* Test fsync_writethrough if available
*/
#ifdef HAVE_FSYNC_WRITETHROUGH
printf
(
LABEL_FORMAT
,
"8k write, 8k write, fsync_writethrough"
);
fflush
(
stdout
);
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
die
(
"Cannot open output file."
);
gettimeofday
(
&
start_t
,
NULL
);
for
(
i
=
0
;
i
<
loops
;
i
++
)
{
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
write
(
tmpfile
,
buf
,
WRITE_SIZE
)
!=
WRITE_SIZE
)
die
(
"write failed"
);
if
(
fcntl
(
tmpfile
,
F_FULLFSYNC
)
!=
0
)
die
(
"fsync failed"
);
if
(
lseek
(
tmpfile
,
0
,
SEEK_SET
)
==
-
1
)
die
(
"seek failed"
);
}
gettimeofday
(
&
stop_t
,
NULL
);
close
(
tmpfile
);
print_elapse
(
start_t
,
stop_t
);
#else
printf
(
"
\t
(unavailable: fsync_writethrough)
\n
"
);
#endif
/*
/*
* Compare 1 to 2 writes
* Compare 1 to 2 writes
*/
*/
printf
(
"
\n
Compare open_sync with different sizes:
\n
"
);
printf
(
"
\n
Compare open_sync with different sizes:
\n
"
);
printf
(
"(This is designed to compare the cost of one large
\n
"
);
printf
(
"sync'ed write and two smaller sync'ed writes.)
\n
"
);
/*
* Test open_sync with different size files
*/
#ifdef OPEN_SYNC_FLAG
#ifdef OPEN_SYNC_FLAG
printf
(
LABEL_FORMAT
,
"open_sync 16k write"
);
printf
(
LABEL_FORMAT
,
"open_sync 16k write"
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -312,12 +500,20 @@ main(int argc, char *argv[])
...
@@ -312,12 +500,20 @@ main(int argc, char *argv[])
#endif
#endif
/*
/*
* Fsync another file descriptor?
* Test whether fsync can sync data written on a different
* descriptor for the same file. This checks the efficiency
* of multi-process fsyncs against the same file.
* Possibly this should be done with writethrough on platforms
* which support it.
*/
*/
printf
(
"
\n
Test if fsync on non-write file descriptor is honored:
\n
"
);
printf
(
"
\n
Test if fsync on non-write file descriptor is honored:
\n
"
);
printf
(
"(If the times are similar, fsync() can sync data written
\n
"
);
printf
(
"(If the times are similar, fsync() can sync data written
\n
"
);
printf
(
"on a different descriptor.)
\n
"
);
printf
(
"on a different descriptor.)
\n
"
);
/*
* first write, fsync and close, which is the
* normal behavior without multiple descriptors
*/
printf
(
LABEL_FORMAT
,
"8k write, fsync, close"
);
printf
(
LABEL_FORMAT
,
"8k write, fsync, close"
);
fflush
(
stdout
);
fflush
(
stdout
);
gettimeofday
(
&
start_t
,
NULL
);
gettimeofday
(
&
start_t
,
NULL
);
...
@@ -330,14 +526,22 @@ main(int argc, char *argv[])
...
@@ -330,14 +526,22 @@ main(int argc, char *argv[])
if
(
fsync
(
tmpfile
)
!=
0
)
if
(
fsync
(
tmpfile
)
!=
0
)
die
(
"fsync failed"
);
die
(
"fsync failed"
);
close
(
tmpfile
);
close
(
tmpfile
);
/*
* open and close the file again to be consistent
* with the following test
*/
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
if
((
tmpfile
=
open
(
filename
,
O_RDWR
,
0
))
==
-
1
)
die
(
"Cannot open output file."
);
die
(
"Cannot open output file."
);
/* do nothing but the open/close the tests are consistent. */
close
(
tmpfile
);
close
(
tmpfile
);
}
}
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/*
* Now open, write, close, open again and fsync
* This simulates processes fsyncing each other's
* writes.
*/
printf
(
LABEL_FORMAT
,
"8k write, close, fsync"
);
printf
(
LABEL_FORMAT
,
"8k write, close, fsync"
);
fflush
(
stdout
);
fflush
(
stdout
);
gettimeofday
(
&
start_t
,
NULL
);
gettimeofday
(
&
start_t
,
NULL
);
...
@@ -358,18 +562,22 @@ main(int argc, char *argv[])
...
@@ -358,18 +562,22 @@ main(int argc, char *argv[])
gettimeofday
(
&
stop_t
,
NULL
);
gettimeofday
(
&
stop_t
,
NULL
);
print_elapse
(
start_t
,
stop_t
);
print_elapse
(
start_t
,
stop_t
);
/* cleanup */
/*
* cleanup
*/
free
(
full_buf
);
free
(
full_buf
);
unlink
(
filename
);
unlink
(
filename
);
return
0
;
return
0
;
}
}
/*
* print out the writes per second for tests
*/
void
void
print_elapse
(
struct
timeval
start_t
,
struct
timeval
stop_t
)
print_elapse
(
struct
timeval
start_t
,
struct
timeval
stop_t
)
{
{
double
total_time
=
(
stop_t
.
tv_sec
-
start_t
.
tv_sec
)
+
double
total_time
=
(
stop_t
.
tv_sec
-
start_t
.
tv_sec
)
+
/* usec subtraction might be negative, e.g. 5.4 - 4.8 */
(
stop_t
.
tv_usec
-
start_t
.
tv_usec
)
*
0
.
000001
;
(
stop_t
.
tv_usec
-
start_t
.
tv_usec
)
*
0
.
000001
;
double
per_second
=
loops
/
total_time
;
double
per_second
=
loops
/
total_time
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment