summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcperciva <cperciva@FreeBSD.org>2004-07-04 19:13:58 +0000
committercperciva <cperciva@FreeBSD.org>2004-07-04 19:13:58 +0000
commit7662db4aa1781530b9ac3f043b3602cbf141b788 (patch)
tree886efee3e841be9fd6551f1dd7f2fa8878edc1d6
parent4def32ce29e18bf1097e7a4117193834a6e7e99a (diff)
downloadFreeBSD-src-7662db4aa1781530b9ac3f043b3602cbf141b788.zip
FreeBSD-src-7662db4aa1781530b9ac3f043b3602cbf141b788.tar.gz
Where syslogd would have fsync()ed a file in the past, instead set a flag
FFLAG_NEEDSYNC and fsync the file when select() next returns zero. This dramatically speeds up the process of logging large amounts of data, while leaving the essential semantics (that data can be expected to be on disk if we crash) unchanged. In my tests, this speeds up the rc phase of booting by 18-20%. [1] YES PLEASE! by: phk [1]
-rw-r--r--usr.sbin/syslogd/syslogd.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 367901c..5721437 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -188,6 +188,7 @@ struct filed {
u_int f_repeatcount; /* number of "repeated" msgs */
int f_flags; /* file-specific flags */
#define FFLAG_SYNC 0x01
+#define FFLAG_NEEDSYNC 0x02
};
/*
@@ -292,6 +293,7 @@ static int UniquePriority; /* Only log specified priority? */
static int LogFacPri; /* Put facility and priority in log message: */
/* 0=no, 1=numeric, 2=names */
static int KeepKernFac; /* Keep remotely logged kernel facility */
+static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */
volatile sig_atomic_t MarkSet, WantDie;
@@ -304,6 +306,7 @@ static int deadq_remove(pid_t);
static int decode(const char *, CODE *);
static void die(int);
static void dodie(int);
+static void dofsync();
static void domark(int);
static void fprintlog(struct filed *, int, const char *);
static int *socksetup(int, const char *);
@@ -557,9 +560,12 @@ main(int argc, char *argv[])
FD_SET(funix[i], fdsr);
}
- i = select(fdsrmax+1, fdsr, NULL, NULL, tvp);
+ i = select(fdsrmax+1, fdsr, NULL, NULL,
+ needdofsync ? &tv : tvp);
switch (i) {
case 0:
+ dofsync();
+ needdofsync = 0;
if (tvp) {
tvp = NULL;
if (ppid != 1)
@@ -976,6 +982,20 @@ logmsg(int pri, const char *msg, const char *from, int flags)
}
static void
+dofsync(void)
+{
+ struct filed *f;
+
+ for (f = Files; f; f = f->f_next) {
+ if ((f->f_type == F_FILE) &&
+ (f->f_flags & FFLAG_NEEDSYNC)) {
+ f->f_flags &= ~FFLAG_NEEDSYNC;
+ (void)fsync(f->f_file);
+ }
+ }
+}
+
+static void
fprintlog(struct filed *f, int flags, const char *msg)
{
struct iovec iov[7];
@@ -1153,8 +1173,10 @@ fprintlog(struct filed *f, int flags, const char *msg)
f->f_type = F_UNUSED;
errno = e;
logerror(f->f_un.f_fname);
- } else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC))
- (void)fsync(f->f_file);
+ } else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC)) {
+ f->f_flags |= FFLAG_NEEDSYNC;
+ needdofsync = 1;
+ }
break;
case F_PIPE:
OpenPOWER on IntegriCloud