Hi,
Hellbender wrote:Any thoughts why this might be bad/good idea?
The main problem with memory mapped files is that there's no sane way to handle any errors. If there's a read error, or you run out of "RAM + swap", or the user unplugs a USB flash device, or the file system or device driver crashes, or...
For all cases where an error occurs in a "memory mapped file" area, you only really have 2 choices - you can terminate the process, or using something hideously problematic like "signals" to deliver the error to the process.
For memory mapping all block devices you'd have the same problem.
Note: For files on "unreliable devices" (anything removable, anything with "higher than normal media failure rates", etc) I'd make sure the data is copied to something more reliable (RAM, swap) before returning from the function that creates a memory mapping (sacrifice performance for reliability), or I'd refuse to allow the file to be memory mapped. If you memory map all block devices you can't do the "copy to something more reliable first" thing and can't refuse.
The next problem you'll have for memory mapped block devices is that they're mostly used by file system code; and (properly designed) file system code typically needs/uses synchronisation guarantees to ensure writes occur in a well defined order (and ensure that a power failure or other problem at the wrong time doesn't leave you with a corrupted file system).
The next problem you'll have is that the interfaces for file systems (and everything below that - storage device drivers, "software RAID" layers, whatever) need to be asynchronous for performance reasons. Mostly, you want an "as large as possible" list of pending operations so that you can optimise the order that operations are performed (e.g. taking into account things like head/seek travel time, IO priorities, etc). Worse, you want to be able to adjust the IO priority of pending operations in various cases (and also be able to cancel them). For example; if there's a low priority "prefetch block #1234" that was requested earlier (but postponed because higher priority operations where being done instead) but then you find out that the process needs this block of data ASAP (it goes from "prefetch for process" to "needed for process to continue"), then you want to change the IO priority of that request to a higher priority after the request was made; regardless of whether the request is still in the file system's list of pending operations, or if the request has made it's way through the file system code and other layers and is in the storage device driver's list of pending operations.
With a "memory mapped device" interface, the file system can't communicate information like IO priorities to the lower layers (e.g. storage device driver), can't cancel pending operations, etc. Without this information the lower layers can't optimise the order that operations are performed (and can't avoid doing work that was cancelled), and performance will suffer (especially under load where performance matters most).
Cheers,
Brendan