Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jan 2004 10:15:22 +0100 (CET)
From:      Divacky Roman <xdivac02@stud.fit.vutbr.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/61664: syslogd speedup
Message-ID:  <200401210915.i0L9FMgv094731@eva.fit.vutbr.cz>
Resent-Message-ID: <200401210920.i0L9K6qx061091@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         61664
>Category:       bin
>Synopsis:       syslogd speedup
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 21 01:20:06 PST 2004
>Closed-Date:
>Last-Modified:
>Originator:     Divacky Roman
>Release:        FreeBSD 4.9-STABLE i386
>Organization:
>Environment:
System: FreeBSD eva.fit.vutbr.cz 4.9-STABLE FreeBSD 4.9-STABLE #2: Thu Nov 20 11:20:53 CET 2003 root@tereza.fit.vutbr.cz:/home/src/sys/sys-49/compile/EVA i386


	
>Description:
	When syslogd logs kernel messages it does it quite weird way. It reads
	buffer from /dev/kmsg and then writes it into log file fsync()ing after
	EACH newline.. this is very slow and much less secure than fsync()ing
	it after whole buffer... this patch implements such behviour
>How-To-Repeat:
	apply this patch ;)
>Fix:
--- syslogd.8	Mon Sep  8 21:57:22 2003
+++ /home/roman/kernel/patches/syslogd/syslogd.8	Wed Jan 14 17:21:14 2004
@@ -224,6 +224,9 @@
 logged with each locally-written message.  If specified more than once,
 the names of the facility and priority are logged with each locally-written
 message.
+.It Fl x
+Turns on old behaviour of fsync()ing after each line. This might make syslogd
+slower!
 .El
 .Pp
 The
--- syslogd.c	Sun Nov 16 22:51:06 2003
+++ /home/roman/kernel/patches/syslogd/syslogd.c	Wed Jan 14 17:27:14 2004
@@ -288,6 +288,7 @@
 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	DoFsync;	/* wheter do a fsync() on boot */
 
 volatile sig_atomic_t MarkSet, WantDie;
 
@@ -310,7 +311,7 @@
 static void	markit(void);
 static int	skip_message(const char *, const char *, int);
 static void	printline(const char *, char *);
-static void	printsys(char *);
+static void	printsys(char *, int);
 static int	p_open(const char *, pid_t *);
 static void	readklog(void);
 static void	reapchild(int);
@@ -338,7 +339,7 @@
 	socklen_t len;
 
 	bindhostname = NULL;
-	while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:nop:P:suv")) != -1)
+	while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:nop:P:suvx")) != -1)
 		switch (ch) {
 		case '4':
 			family = PF_INET;
@@ -401,6 +402,9 @@
 		case 'v':		/* log facility and priority */
 		  	LogFacPri++;
 			break;
+		case 'x':
+		        DoFsync++;	/* Do fsync() */	
+			break;
 		case '?':
 		default:
 			usage();
@@ -716,29 +720,34 @@
 
 		for (p = line; (q = strchr(p, '\n')) != NULL; p = q + 1) {
 			*q = '\0';
-			printsys(p);
+			printsys(p, ISKERNEL | ADDDATE);
 		}
 		len = strlen(p);
 		if (len >= MAXLINE - 1) {
-			printsys(p);
+			printsys(p, ISKERNEL | ADDDATE);
 			len = 0;
 		}
+		/* XXX: This could be as well on the end of this function */
+		if (!DoFsync)
+		   fsync (Files->f_file);
 		if (len > 0) 
 			memmove(line, p, len + 1);
 	}
 	if (len > 0)
-		printsys(line);
+		printsys(line, ISKERNEL | ADDDATE | SYNC_FILE);
 }
 
 /*
  * Take a raw input line from /dev/klog, format similar to syslog().
  */
 static void
-printsys(char *p)
+printsys(char *p, int flags)
 {
-	int pri, flags;
+	int pri;
 
-	flags = ISKERNEL | SYNC_FILE | ADDDATE;	/* fsync after write */
+	if (DoFsync) 
+	   flags |= SYNC_FILE;	/* fsync after write */
+	   
 	pri = DEFSPRI;
 	if (*p == '<') {
 		pri = 0;


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401210915.i0L9FMgv094731>