From owner-freebsd-current Sat Dec 7 7:59:24 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 AD8BA37B401 for ; Sat, 7 Dec 2002 07:59:20 -0800 (PST) Received: from beastie.mckusick.com (beastie.mckusick.com [209.31.233.184]) by mx1.FreeBSD.org (Postfix) with ESMTP id 24DB843ED1 for ; Sat, 7 Dec 2002 07:59:20 -0800 (PST) (envelope-from mckusick@beastie.mckusick.com) Received: from beastie.mckusick.com (localhost [127.0.0.1]) by beastie.mckusick.com (8.12.3/8.12.3) with ESMTP id gB7Fx059097656; Sat, 7 Dec 2002 07:59:00 -0800 (PST) (envelope-from mckusick@beastie.mckusick.com) Message-Id: <200212071559.gB7Fx059097656@beastie.mckusick.com> To: Ian Dowse Subject: Re: backgroud fsck is still locking up system (fwd) Cc: Brooks Davis , Nate Lawson , Archie Cobbs , freebsd-current@FreeBSD.ORG, Robert Watson In-Reply-To: Your message of "Sat, 07 Dec 2002 14:26:39 GMT." <200212071426.aa60667@salmon.maths.tcd.ie> Date: Sat, 07 Dec 2002 07:59:00 -0800 From: Kirk McKusick 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 Thanks for reminding me about your userland change to background fsck. I have tried it out and concur that it is the right approach until we manage to get the general solution in the kernel. I suggest that you propose it to release engineering and if approved check it in. Kirk McKusick =-=-=-=-=-= 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 X-ASK-Info: Whitelist match 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