From: "Stephen C. Tweedie" <sct@redhat.com>
To: Linus Torvalds <torvalds@transmeta.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Stephen Tweedie <sct@redhat.com>, Ben LaHaise <bcrl@redhat.com>
Subject: [testcase] fsync/O_SYNC simple test cases
Date: Wed, 22 Nov 2000 11:29:03 +0000 [thread overview]
Message-ID: <20001122112903.E6516@redhat.com> (raw)
Hi,
The code below may be useful for doing simple testing of the O_SYNC
and f[data]sync code in the kernel. It times various combinations of
updates-in-place and appends under various synchronisation mechanisms,
making it possible to see clearly whether fdatasync is skipping inode
updates for updates-in-place, for example.
--Stephen
synctest.c:
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/resource.h>
int iterations = 1000;
struct timeval last_stopwatch_time;
void stopwatch()
{
struct timeval now;
int delta;
gettimeofday(&now, 0);
delta = (now.tv_sec - last_stopwatch_time.tv_sec) * 1000000 +
(now.tv_usec - last_stopwatch_time.tv_usec);
printf ("Stopwatch: elapsed time %d.%03d seconds\n",
delta / 1000000, (delta / 1000) % 1000);
last_stopwatch_time = now;
}
int main()
{
int fd, syncfd;
int i;
int err;
char c;
fd = open("syncfile", O_CREAT|O_TRUNC|O_RDWR, 0666);
if (fd < 0) {
perror("open");
exit(1);
}
syncfd = open("syncfile", O_RDWR|O_SYNC, 0666);
if (syncfd < 0) {
perror("open");
exit(1);
}
c = -1;
err = pwrite(fd, &c, 1, 0);
if (err != 1) {
perror("pwrite");
exit(1);
}
gettimeofday(&last_stopwatch_time, 0);
/* First pass: do nothing but fsync */
printf ("Performing %d fsyncs:\n", iterations);
for (i=0; i<iterations; i++)
fsync(fd);
printf ("done. \n");
stopwatch();
/* Next pass: do nothing but fdatasync */
printf ("Performing %d fdatasyncs:\n", iterations);
for (i=0; i<iterations; i++)
fdatasync(fd);
printf ("done. \n");
stopwatch();
/* Next pass: do fsync with a file read in each pass to force an
* atime timestamp update */
printf ("Performing %d atime fsyncs:\n", iterations);
for (i=0; i<iterations; i++) {
pread(fd, &c, 1, 0);
fsync(fd);
}
printf ("done. \n");
stopwatch();
/* Next pass: do fdatasync with a file read in each pass to
* force an atime timestamp update */
printf ("Performing %d atime fdatasyncs:\n", iterations);
for (i=0; i<iterations; i++) {
pread(fd, &c, 1, 0);
fdatasync(fd);
}
printf ("done. \n");
stopwatch();
/* Next pass: do fdatasync with a file write in each pass: this
* should do a real sync of the data, but not of the inode. */
printf ("Performing %d write fdatasyncs:\n", iterations);
for (i=0; i<iterations; i++) {
pwrite(fd, &c, 1, 0);
fdatasync(fd);
}
printf ("done. \n");
stopwatch();
/* Next pass: do fdatasync with a file append in each pass: this
* should do a real sync of the data, and should also sync the
* inode for the new i_size. */
printf ("Performing %d append fdatasyncs:\n", iterations);
for (i=0; i<iterations; i++) {
pwrite(fd, &c, 1, i);
fdatasync(fd);
}
printf ("done. \n");
stopwatch();
/* Next pass: do fsync with a file write in each pass: this
* should do a real sync of the data and inode in each round,
* resulting in much head banging. */
printf ("Performing %d write fsyncs:\n", iterations);
for (i=0; i<iterations; i++) {
pwrite(fd, &c, 1, 0);
fsync(fd);
}
printf ("done. \n");
stopwatch();
/* Next pass: do O_SYNC writes. */
printf ("Performing %d O_SYNC writes:\n", iterations);
for (i=0; i<iterations; i++) {
pwrite(syncfd, &c, 1, 0);
}
printf ("done. \n");
stopwatch();
/* Next pass: do O_SYNC appends. */
ftruncate(syncfd, 0);
fsync(syncfd);
printf ("Performing %d O_SYNC appends:\n", iterations);
for (i=0; i<iterations; i++) {
pwrite(syncfd, &c, 1, i);
}
printf ("done. \n");
stopwatch();
return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
reply other threads:[~2000-11-22 12:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20001122112903.E6516@redhat.com \
--to=sct@redhat.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=bcrl@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.