Subject: Re: how to bring a mounted filesystem to an almost clean state?
To: None <tech-kern@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-kern
Date: 02/25/2003 20:05:16
On Wed, Feb 26, 2003 at 11:42:24AM +1100, Daniel Carosone wrote:
> On Tue, Feb 25, 2003 at 12:07:20PM -0600, David Young wrote:
> >   cannot work, but here goes: mark every buffer with its generation,
> >   the buffer's generation being the number of VFS_SYNC's done between
> >   boot time and the time the buffer was most recently "dirtied." For
> 
> I like the sound of this, but also don't understand the details of
> the present implementation.
> 
> One implication would be that you'd have to be careful about
> overlapping/parallel sync() calls - at the simplest they'd need to
> be serialised with some lock. Otherwise you need to deal with
> multiple overlapping generations.

When you say overlap, do you mean that a new sync() comes in while
the snapshot for the last sync() is still underway?  Because I think
that's ok....

You can keep a ring that indicates which generations await a snapshot;
each element tells the number of dirty blocks in that generation.

generation  dirty
            blks
+----------+-----+
|          |     |
| ...      |     |
+----------+-----+
| N        |  3  | <- tail
+----------+-----+
| N+1      |  2  |
+----------+-----+
| N+2      |  4  | <- head
+----------+-----+
| ...      |     |
|          |     |
+----------+-----+

Say that you only have room in the ring for three generations. If a
fourth sync comes before you can flush generation N to disk, then you
can either add the number of dirty blocks in generation N to the number
in N+1, delete generation N, and start generation N+3, or you can add
the dirty blocks in N+2 to the blocks in N+1 and delete N+2 and stay at
generation N+2.

Possibly the ring should only be two generations deep, but it should be
at least long enough that snapshots always complete, even in the face
of zillions of sync()s.

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Engineering from the Right Brain
                        Urbana, IL * (217) 278-3933