Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Oct 2002 22:36:55 -0800
From:      Kirk McKusick <mckusick@beastie.mckusick.com>
To:        Ian Dowse <iedowse@maths.tcd.ie>
Cc:        Poul-Henning Kamp <phk@critter.freebsd.dk>, Dan Nelson <dnelson@allantgroup.com>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/fs/specfs spec_vnops.c src/sys/kern subr_disk.c src/sys/ufs/ffs ffs_snapshot.c 
Message-ID:  <200210280636.g9S6at59021626@beastie.mckusick.com>
In-Reply-To: Your message of "Sun, 27 Oct 2002 22:00:23 GMT." <200210272200.aa72517@salmon.maths.tcd.ie> 

next in thread | previous in thread | raw e-mail | index | archive | help
The point of running a process niced is so that it will not hog
resources on your system. before this change, running find niced
had no effect because it was totally I/O bound. With this change
a niced find will run slower. If you want it to run at full speed,
why are you nice'ing it? And, yes, nice'ing the background fsck
by plus 4 will slow it down by a factor of about 6. Again,
that is the point. Reduce its demands on the system. There is no
particular rush in having it finish, and if you run it full bore,
other activity on the system will be severely impacted. Again, if
getting background fsck done as quickly as possible is the desire,
then don't run it nice'd. The whole point of this change is to
make nice have an effect on positively niced I/O bound jobs. It
is doing exactly what it is supposed to do. What is all the
uproar about?

	Kirk McKusick

=-=-=-=-=

To: Poul-Henning Kamp <phk@critter.freebsd.dk>
cc: Dan Nelson <dnelson@allantgroup.com>,
   Kirk McKusick <mckusick@mckusick.com>, cvs-committers@FreeBSD.org,
   cvs-all@FreeBSD.org
Subject: Re: cvs commit: src/sys/fs/specfs spec_vnops.c src/sys/kern subr_disk.c src/sys/ufs/ffs ffs_snapshot.c 
In-Reply-To: Your message of "Thu, 24 Oct 2002 17:12:19 +0200."
             <5892.1035472339@critter.freebsd.dk> 
Date: Sun, 27 Oct 2002 22:00:23 +0000
From: Ian Dowse <iedowse@maths.tcd.ie>
X-ASK-Info: Whitelist match

In message <5892.1035472339@critter.freebsd.dk>, Poul-Henning Kamp writes:
>In message <20021024145822.GA69650@dan.emsphone.com>, Dan Nelson writes:
>>In the last episode (Oct 21), Kirk McKusick said:
>>>   Log:
>>>   This checkin reimplements the io-request priority hack in a way
>>>   that works in the new threaded kernel. It was commented out of
>>
>>I think this cure is worse than the disease.  Background fsck times on
>>my system went from 10 minutes to an hour, and niced processes that
>>want to do any disk I/O at all run at a glacial speed.  Try running
>>"nice find /" on an otherwise-idle system, for example.  Don't bother
>>running anything at nice -20 :)
>
>I as somewhat afraid of this, and therefore floated the idea that
>the pacing should be moved all the way up to physio() so it only
>affected niced processes which access raw-devices, but Kirk thought
>hitting all disk-access was more logical.
>
>I can't really make up my mind either way.

How about just doing the IO slowing in userland? Something like the
following patch should pace fsck's read IO to use 50% or less of
the disk bandwidth in background mode, and slows itself down if the
disk becomes busy. Further adjustment of the algorithm is probably
required to compensate for usleep() rounding up to 1/hz.

Ian

Index: fsutil.c
===================================================================
RCS file: /dump/FreeBSD-CVS/src/sbin/fsck_ffs/fsutil.c,v
retrieving revision 1.18
diff -u -r1.18 fsutil.c
--- fsutil.c	19 Oct 2002 05:36:48 -0000	1.18
+++ fsutil.c	27 Oct 2002 21:25:19 -0000
@@ -40,6 +40,7 @@
 #endif /* not lint */
 
 #include <sys/param.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #include <sys/disklabel.h>
@@ -62,7 +63,13 @@
 
 #include "fsck.h"
 
+static void slowio_start(void);
+static void slowio_end(void);
+
 long	diskreads, totalreads;	/* Disk cache statistics */
+struct timeval slowio_starttime;
+int slowio_delay_usec = 10000;	/* Initial IO delay for background fsck */
+int slowio_pollcnt;
 
 int
 ftypeok(union dinode *dp)
@@ -350,10 +357,15 @@
 
 	offset = blk;
 	offset *= dev_bsize;
+	if (bkgrdflag)
+		slowio_start();
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK BLK", blk);
-	else if (read(fd, buf, (int)size) == size)
+	else if (read(fd, buf, (int)size) == size) {
+		if (bkgrdflag)
+			slowio_end();
 		return (0);
+	}
 	rwerror("READ BLK", blk);
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK BLK", blk);
@@ -463,6 +475,39 @@
 	idesc.id_blkno = blkno;
 	idesc.id_numfrags = frags;
 	(void)pass4check(&idesc);
+}
+
+/* Slow down IO so as to leave some disk bandwidth for other processes */
+void
+slowio_start()
+{
+
+	usleep(slowio_delay_usec);
+
+	/* Sample only 1/16 of operations */
+	slowio_pollcnt = (slowio_pollcnt + 1) & 15;
+	if (slowio_pollcnt == 0)
+		gettimeofday(&slowio_starttime, NULL);
+}
+
+void
+slowio_end()
+{
+	struct timeval tv;
+	int delay_usec;
+
+	if (slowio_pollcnt != 0)
+		return;
+
+	/* Update the slowdown interval. */
+	gettimeofday(&tv, NULL);
+	delay_usec = (tv.tv_sec - slowio_starttime.tv_sec) * 1000000 +
+	    (tv.tv_usec - slowio_starttime.tv_usec);
+	if (delay_usec < 64)
+		delay_usec = 64;
+	if (delay_usec > 10000000)
+		delay_usec = 10000000;
+	slowio_delay_usec = (slowio_delay_usec * 63 + delay_usec) >> 6;
 }
 
 /*



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




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