Pavel's buffered-io-tweaks patch from 6746