A few potentially useful patches (from my FreeBSD source)

Barry Bouwsma freebsd-misuser at remove-NOSPAM-to-reply.NOSPAM.dyndns.dk
Sat Aug 7 13:54:38 PDT 2004


[don't reply to me yet -- keep replies on the list for now]

Welcome.

I'm going to offer some of the local patches I have against my
FreeBSD 4.x source that appear to be applicable to DragonFly.
Some of them might even be useful.

I've just applied these patches to my tree and not yet done a
build with them, so no guarantees yet.  They are more for the
ideas contained within than the execution thereof.


This hack is designed to avoid a `doc, it hurts when I do this'
kernel panic that can be induced with a filesystem tuned for a
large average file size and number of files per directory.
With suitable numbers (to match, say, a bunch of WAV files in
one directory), `dirsize' can overflow 32 bits, and be, for
example, 0, which, when divided by, panics.  Therefore I toss
in plenty of 64-bitness, probably too much.

This hack is probably done right as has been applied to the
NetBSD code.  I'm no programmer and know not what I'm doing.


--- /NetBSD/obj/hacks/DragonFly-src/source-hacks/sys/vfs/ufs/ffs_alloc.c-DIST	Sun Jul 18 21:43:48 2004
+++ /NetBSD/obj/hacks/DragonFly-src/source-hacks/sys/vfs/ufs/ffs_alloc.c	Thu Aug  5 10:20:49 2004
@@ -641,8 +641,12 @@
 ffs_dirpref(struct inode *pip)
 {
 	struct fs *fs;
-	int cg, prefcg, dirsize, cgsize;
-	int avgifree, avgbfree, avgndir, curdirsize;
+	int cg, prefcg;
+	/* int cg, prefcg, dirsize, cgsize; */
+	int64_t dirsize, cgsize;
+	int avgifree, avgbfree, avgndir;
+	/* int avgifree, avgbfree, avgndir, curdirsize; */
+	int64_t curdirsize;
 	int minifree, minbfree, maxndir;
 	int mincg, minndir;
 	int maxcontigdirs;
@@ -688,12 +692,12 @@
 	minbfree = avgbfree - avgbfree / 4;
 	if (minbfree < 1)
 		minbfree = 1;
-	cgsize = fs->fs_fsize * fs->fs_fpg;
-	dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
-	curdirsize = avgndir ? (cgsize - avgbfree * fs->fs_bsize) / avgndir : 0;
+	cgsize = (int64_t)fs->fs_fsize * (int64_t)fs->fs_fpg;
+	dirsize = (int64_t)fs->fs_avgfilesize * (int64_t)fs->fs_avgfpdir;
+	curdirsize = avgndir ? (cgsize - (int64_t)avgbfree * fs->fs_bsize) / avgndir : 0;
 	if (dirsize < curdirsize)
 		dirsize = curdirsize;
-	maxcontigdirs = min((avgbfree * fs->fs_bsize) / dirsize, 255);
+	maxcontigdirs = min((int64_t)(avgbfree * fs->fs_bsize) / dirsize, 255);
 	if (fs->fs_avgfpdir > 0)
 		maxcontigdirs = min(maxcontigdirs,
 				    fs->fs_ipg / fs->fs_avgfpdir);



The following disables a check which more than a few FreeBSD users
have discovered breaks their soundcards (there's a PR about this
too).  Well, not breaks, but keeps from working.  Explained in the
comment.  NetBSD does no such check and worked out-of-box with my
card.


--- /NetBSD/obj/hacks/DragonFly-src/source-hacks/sys/dev/sound/pci/fm801.c-ORIG	Thu Aug  7 23:17:13 2003
+++ /NetBSD/obj/hacks/DragonFly-src/source-hacks/sys/dev/sound/pci/fm801.c	Thu Aug  5 10:38:09 2004
@@ -737,11 +737,23 @@
 		 * power-on value should be `0', while on AC97-less tuner
 		 * card (SF64-PCR) it was 0x80.
 		 */
+		/* HACK
+		 * Unfortunately, some fully-sound-capable cards, like the
+		 * TerraTec 512i, return 0x80.  I don't know of any other
+		 * differences to detect between the cards.  As I have one
+		 * of these cards but not an SF64-PCR, I'd prefer to have
+		 * the card work, as would others with the same card.
+		 * Therefore, not knowing better, disable this check.
+		 */
+#ifdef I_HAVE_SF64-PCR
 		if (bus_space_read_1(st, sh, 0x28) == 0) {
+#endif
 			device_set_desc(dev,
 			    "Forte Media FM801 Audio Controller");
 			result = 0;
+#ifdef I_HAVE_SF64-PCR
 		}
+#endif
 
 		bus_release_resource(dev, regtype, regid, reg);
 	}



This patch to userland ppp significantly decreases the amount
of CPU usage.  I believe something like this is present in FreeBSD
with a MFC, and it made a huge difference for me.


--- /NetBSD/obj/hacks/DragonFly-src/source-hacks/usr.sbin/ppp/ip.c-ORIG	Tue Jun 17 06:30:00 2003
+++ /NetBSD/obj/hacks/DragonFly-src/source-hacks/usr.sbin/ppp/ip.c	Thu Aug  5 12:57:47 2004
@@ -162,6 +162,18 @@
   }
 }
 
+char *toprototxt(int cproto)
+{
+  static char prototxt[16];
+  struct protoent *pe;
+
+  if ((pe = getprotobynumber(cproto)) == NULL)
+    snprintf(prototxt, sizeof prototxt, "%d", cproto);
+  else
+    snprintf(prototxt, sizeof prototxt, "%s", pe->p_name);
+  return prototxt;
+}
+
 /*
  * Check a packet against the given filter
  * Returns 0 to accept the packet, non-zero to drop the packet.
@@ -188,8 +200,7 @@
   int match;			/* true if condition matched */
   int mindata;			/* minimum data size or zero */
   const struct filterent *fp = filter->rule;
-  char dbuff[100], dstip[16], prototxt[16];
-  struct protoent *pe;
+  char dbuff[100], dstip[16];
   struct ncpaddr srcaddr, dstaddr;
   const char *payload;		/* IP payload */
   int datalen;			/* IP datagram length */
@@ -240,10 +251,6 @@
     cproto = pip->ip_p;
   }
 
-  if ((pe = getprotobynumber(cproto)) == NULL)
-    snprintf(prototxt, sizeof prototxt, "%d", cproto);
-  else
-    snprintf(prototxt, sizeof prototxt, "%s", pe->p_name);
   gotinfo = estab = syn = finrst = didname = 0;
   sport = dport = 0;
 
@@ -357,7 +364,7 @@
 
           if (datalen < mindata) {
             log_Printf(LogFILTER, " error: proto %s must be at least"
-                       " %d octets\n", prototxt, mindata);
+                       " %d octets\n", toprototxt(cproto), mindata);
             return 1;
           }
 
@@ -368,7 +375,8 @@
                        ", estab = %d, syn = %d, finrst = %d",
                        estab, syn, finrst);
             }
-            log_Printf(LogDEBUG, " Filter: proto = %s, %s\n", prototxt, dbuff);
+            log_Printf(LogDEBUG, " Filter: proto = %s, %s\n",
+                       toprototxt(cproto), dbuff);
           }
           gotinfo = 1;
         }
@@ -425,7 +433,8 @@
             if (log_IsKept(LogFILTER)) {
               snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
               log_Printf(LogFILTER, "%sbound rule = %d accept %s "
-                         "src = %s:%d dst = %s:%d\n", filter->name, n, prototxt,
+                         "src = %s:%d dst = %s:%d\n", filter->name, n,
+                         toprototxt(cproto),
                          ncpaddr_ntoa(&srcaddr), sport, dstip, dport);
             }
           }
@@ -435,7 +444,7 @@
             snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
             log_Printf(LogFILTER,
                        "%sbound rule = %d deny %s src = %s/%d dst = %s/%d\n",
-                       filter->name, n, prototxt,
+                       filter->name, n, toprototxt(cproto),
                        ncpaddr_ntoa(&srcaddr), sport, dstip, dport);
           }
           return 1;
@@ -451,7 +460,7 @@
     snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
     log_Printf(LogFILTER,
                "%sbound rule = implicit deny %s src = %s/%d dst = %s/%d\n",
-               filter->name, prototxt, ncpaddr_ntoa(&srcaddr), sport,
+               filter->name, toprototxt(cproto), ncpaddr_ntoa(&srcaddr), sport,
                dstip, dport);
   }
 


Another performance improver with my FreeBSD was to merge in
the following based on -current, which in part, avoids fsync()ing
the syslog file at every line during boot, which otherwise slows
my boot by several seconds and makes my disk sound like a small
jackhammer.

The patch following also includes another enhancement from FBSD-
current, to allow one to specify a linux-like no-fsync logfile.

You may prefer to take this diff from the original FreeBSD source
rather than trusting my hackery.  Same with the above.


--- /NetBSD/obj/hacks/DragonFly-src/source-hacks/usr.sbin/syslogd/syslogd.c-ORIG	Tue Jun 17 06:30:03 2003
+++ /NetBSD/obj/hacks/DragonFly-src/source-hacks/usr.sbin/syslogd/syslogd.c	Thu Aug  5 13:05:46 2004
@@ -174,6 +174,10 @@
 	int	f_prevlen;			/* length of f_prevline */
 	int	f_prevcount;			/* repetition cnt of prevline */
 	u_int	f_repeatcount;			/* number of "repeated" msgs */
+	int     f_flags;                        /* file-specific flags */
+#define FFLAG_SYNC 0x01
+#define FFLAG_NEEDSYNC        0x02
+
 };
 
 /*
@@ -277,6 +281,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	needdofsync = 0; /* Are any file(s) waiting to be fsynced? */
 
 volatile sig_atomic_t MarkSet, WantDie;
 
@@ -289,6 +294,7 @@
 static int	decode(const char *, CODE *);
 static void	die(int);
 static void	dodie(int);
+static void	dofsync(void);
 static void	domark(int);
 static void	fprintlog(struct filed *, int, const char *);
 static int	*socksetup(int, const char *);
@@ -535,9 +541,12 @@
 				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)
@@ -916,6 +925,20 @@
 }
 
 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];
@@ -1092,8 +1115,10 @@
 			f->f_type = F_UNUSED;
 			errno = e;
 			logerror(f->f_un.f_fname);
-		} else if (flags & SYNC_FILE)
-			(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:
@@ -1555,7 +1580,7 @@
 cfline(const char *line, struct filed *f, const char *prog, const char *host)
 {
 	struct addrinfo hints, *res;
-	int error, i, pri;
+	int error, i, pri, syncfile;
 	const char *p, *q;
 	char *bp;
 	char buf[MAXLINE], ebuf[100];
@@ -1699,6 +1724,12 @@
 	while (*p == '\t' || *p == ' ')
 		p++;
 
+	if (*p == '-') {
+		syncfile = 0;
+		p++;
+	} else
+		syncfile = 1;
+
 	switch (*p) {
 	case '@':
 		(void)strlcpy(f->f_un.f_forw.f_hname, ++p,
@@ -1722,6 +1753,8 @@
 			logerror(p);
 			break;
 		}
+		if (syncfile)
+			f->f_flags |= FFLAG_SYNC;
 		if (isatty(f->f_file)) {
 			if (strcmp(p, ctty) == 0)
 				f->f_type = F_CONSOLE;



And finally, this patch to `mount' helps those of us who use
tab-completion shells that append trailing slashes to directory
names, so that one need not erase the trailing slash before
entering, say, `mount -u /tmp/'


--- /NetBSD/obj/hacks/DragonFly-src/source-hacks/sbin/mount/mount.c-ORIG	Fri Feb  6 23:11:48 2004
+++ /NetBSD/obj/hacks/DragonFly-src/source-hacks/sbin/mount/mount.c	Thu Aug  5 12:51:43 2004
@@ -218,6 +218,9 @@
 		if (vfslist != NULL)
 			usage();
 
+/* XXXX why not do this here, to sanitize `mount -u' paths given
+	by shell auto-completion? */
+		rmslashes(*argv, *argv);
 		if (init_flags & MNT_UPDATE) {
 			mntfromname = NULL;
 			have_fstab = 0;
@@ -256,7 +259,9 @@
 			    mntbuf->f_mntonname, init_flags, options, 0);
 			break;
 		}
+/* XXXX done above instead...
 		rmslashes(*argv, *argv);
+ */
 		if ((fs = getfsfile(*argv)) == NULL &&
 		    (fs = getfsspec(*argv)) == NULL)
 			errx(1, "%s: unknown special file or file system",





I'll see how these go down before throwing more your way.


thanks
barry bouwsma






More information about the Submit mailing list