Add an optimized way of writing back dirty pages.

We maintain a tree of all dirty buckets and work then
bucket by bucket in sequential order.