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]
This commit is contained in:
parent
4def32ce29
commit
7662db4aa1
@ -188,6 +188,7 @@ struct filed {
|
|||||||
u_int f_repeatcount; /* number of "repeated" msgs */
|
u_int f_repeatcount; /* number of "repeated" msgs */
|
||||||
int f_flags; /* file-specific flags */
|
int f_flags; /* file-specific flags */
|
||||||
#define FFLAG_SYNC 0x01
|
#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: */
|
static int LogFacPri; /* Put facility and priority in log message: */
|
||||||
/* 0=no, 1=numeric, 2=names */
|
/* 0=no, 1=numeric, 2=names */
|
||||||
static int KeepKernFac; /* Keep remotely logged kernel facility */
|
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;
|
volatile sig_atomic_t MarkSet, WantDie;
|
||||||
|
|
||||||
@ -304,6 +306,7 @@ static int deadq_remove(pid_t);
|
|||||||
static int decode(const char *, CODE *);
|
static int decode(const char *, CODE *);
|
||||||
static void die(int);
|
static void die(int);
|
||||||
static void dodie(int);
|
static void dodie(int);
|
||||||
|
static void dofsync();
|
||||||
static void domark(int);
|
static void domark(int);
|
||||||
static void fprintlog(struct filed *, int, const char *);
|
static void fprintlog(struct filed *, int, const char *);
|
||||||
static int *socksetup(int, const char *);
|
static int *socksetup(int, const char *);
|
||||||
@ -557,9 +560,12 @@ main(int argc, char *argv[])
|
|||||||
FD_SET(funix[i], fdsr);
|
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) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
|
dofsync();
|
||||||
|
needdofsync = 0;
|
||||||
if (tvp) {
|
if (tvp) {
|
||||||
tvp = NULL;
|
tvp = NULL;
|
||||||
if (ppid != 1)
|
if (ppid != 1)
|
||||||
@ -975,6 +981,20 @@ logmsg(int pri, const char *msg, const char *from, int flags)
|
|||||||
(void)sigsetmask(omask);
|
(void)sigsetmask(omask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
fprintlog(struct filed *f, int flags, const char *msg)
|
fprintlog(struct filed *f, int flags, const char *msg)
|
||||||
{
|
{
|
||||||
@ -1153,8 +1173,10 @@ fprintlog(struct filed *f, int flags, const char *msg)
|
|||||||
f->f_type = F_UNUSED;
|
f->f_type = F_UNUSED;
|
||||||
errno = e;
|
errno = e;
|
||||||
logerror(f->f_un.f_fname);
|
logerror(f->f_un.f_fname);
|
||||||
} else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC))
|
} else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC)) {
|
||||||
(void)fsync(f->f_file);
|
f->f_flags |= FFLAG_NEEDSYNC;
|
||||||
|
needdofsync = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case F_PIPE:
|
case F_PIPE:
|
||||||
|
Loading…
Reference in New Issue
Block a user