FROM : Douglas Davidson
DATE : Tue May 13 17:53:16 2008
On May 13, 2008, at 8:08 AM, Jens Alfke wrote:
> While we're on the topic, it's worth noting that memory-mapping
> files on removable or network filesystems can be dangerous. If you
> read/write a mapped memory location, and the kernel has to page it
> in, but the file's filesystem is no longer accessible due to a
> network issue or a yanked USB cable ... you get a bus-error. I've
> seen discussion of ways to handle this by installing a signal
> handler whenever you access mapped memory, but it would be pretty
> tricky to pull off. The conclusion was that it's only safe to memory-
> map files that are either (a) on the boot filesystem, or (b) in the
> user's home directory. (The latter might be on a networked
> filesystem, but if it ever gets disconnected, most of the upper
> layers of the OS and applications will be hosed anyway...)
I would add, (c) files that are on the same volume as the executable;
for example, files in your application bundle or one of your framework
bundles should be safe to map in. The reasoning here is that if a
volume containing an executable your application is currently using
goes away, the application is dead anyway--in fact, the executables
themselves are usually mapped. I'm not so certain about (b); it may
be possible to survive the loss or temporary absence of the user's
home directory, depending on what your application is doing. However,
the files I typically have wanted to map in have been fixed data files
that are part of the system, the application, or one of its
frameworks, for which the home directory would be an unlikely location
anyway.
Douglas Davidson
DATE : Tue May 13 17:53:16 2008
On May 13, 2008, at 8:08 AM, Jens Alfke wrote:
> While we're on the topic, it's worth noting that memory-mapping
> files on removable or network filesystems can be dangerous. If you
> read/write a mapped memory location, and the kernel has to page it
> in, but the file's filesystem is no longer accessible due to a
> network issue or a yanked USB cable ... you get a bus-error. I've
> seen discussion of ways to handle this by installing a signal
> handler whenever you access mapped memory, but it would be pretty
> tricky to pull off. The conclusion was that it's only safe to memory-
> map files that are either (a) on the boot filesystem, or (b) in the
> user's home directory. (The latter might be on a networked
> filesystem, but if it ever gets disconnected, most of the upper
> layers of the OS and applications will be hosed anyway...)
I would add, (c) files that are on the same volume as the executable;
for example, files in your application bundle or one of your framework
bundles should be safe to map in. The reasoning here is that if a
volume containing an executable your application is currently using
goes away, the application is dead anyway--in fact, the executables
themselves are usually mapped. I'm not so certain about (b); it may
be possible to survive the loss or temporary absence of the user's
home directory, depending on what your application is doing. However,
the files I typically have wanted to map in have been fixed data files
that are part of the system, the application, or one of its
frameworks, for which the home directory would be an unlikely location
anyway.
Douglas Davidson






Cocoa mail archive

