From owner-freebsd-current Sat Dec 7 6:26:48 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 95EE737B401 for ; Sat, 7 Dec 2002 06:26:45 -0800 (PST) Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by mx1.FreeBSD.org (Postfix) with SMTP id 71B7A43E9C for ; Sat, 7 Dec 2002 06:26:44 -0800 (PST) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 7 Dec 2002 14:26:41 +0000 (GMT) To: Kirk McKusick Cc: Brooks Davis , Nate Lawson , Archie Cobbs , freebsd-current@FreeBSD.ORG Subject: Re: backgroud fsck is still locking up system (fwd) In-Reply-To: Your message of "Fri, 06 Dec 2002 17:52:38 PST." <200212070152.gB71qc59094441@beastie.mckusick.com> Date: Sat, 07 Dec 2002 14:26:39 +0000 From: Ian Dowse Message-ID: <200212071426.aa60667@salmon.maths.tcd.ie> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <200212070152.gB71qc59094441@beastie.mckusick.com>, Kirk McKusick wr ites: >Adding a two minute delay before starting background fsck >sounds like a very good idea to me. Please send me your >suggested change. BTW, I've been using a fsck_ffs modificaton for a while now that does something like the disabled kernel I/O slowdown, but from userland. It seems to help quite a lot in leaving some disk bandwidth for other processes. Waiting a while before starting the fsck seems like a good idea anyway though. Patch below (I think I posted an earlier version of this before). Ian Index: fsutil.c =================================================================== RCS file: /dump/FreeBSD-CVS/src/sbin/fsck_ffs/fsutil.c,v retrieving revision 1.19 diff -u -r1.19 fsutil.c --- fsutil.c 27 Nov 2002 02:18:57 -0000 1.19 +++ fsutil.c 4 Dec 2002 02:16:28 -0000 @@ -40,6 +40,7 @@ #endif /* not lint */ #include +#include #include #include #include @@ -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() +{ + + /* Delay one in every 8 operations by 16 times the average IO delay */ + slowio_pollcnt = (slowio_pollcnt + 1) & 7; + if (slowio_pollcnt == 0) { + usleep(slowio_delay_usec * 16); + 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 > 1000000) + delay_usec = 1000000; + slowio_delay_usec = (slowio_delay_usec * 63 + delay_usec) >> 6; } /* To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message