4 ms·
It's definitely a failing of modern virtual-memory operating systems that there's no nice way of doing this without getting the filesystem involved or creating
by rossy 11y ago
It's definitely a failing of modern virtual-memory operating systems that there's no nice way of doing this without getting the filesystem involved or creating race conditions. Windows almost does this right with the Nt* APIs for manipulating sections, but user space programs are not supposed to use those directly. Instead they're stuck with the Windows 9x-era public APIs. A modern API for manipulating virtual memory would be a really powerful thing to have.
- gpderetta 11y agoLinux has remap_file_pages to create non-linear address space mappings. You can do the magic ring buffer dance with a single anon mmap + a single call to remap. On recent kernels the fast implementation of remap_file_pages has been removed because keeping non linear mapping from regressing was too much of a burden; instead a slow emulation has been added. The emulation should still be faster than doing the mmap dance by hand.
- to3m 11y agoI think you can do this on OS X using the Mach vm_XXX family of functions (I've only used them for querying state, though, rather than rearranging the mappings.) The documentation is pretty terrible, though, so some experimentation may be necessary. It's also even less like the POSIX parts than the NS bits are... (Apple doesn't seem to tell you much; OK references are https://www.gnu.org/software/hurd/gnumach-doc/Virtual-Memory-Interface.html#Virtual-Memory-Interface https://www.gnu.org/software/hurd/gnumach-doc/Virtual-Memory... http://www.amazon.co.uk/Mac-OS-Internals-Systems-Approach/dp/0321278542 http://www.amazon.co.uk/Mac-OS-Internals-Systems-Approach/dp..., and, of course, http://www.opensource.apple.com/source/xnu/ http://www.opensource.apple.com/source/xnu/. The source has some reference-style documentation in it.
- aktau 11y agoThis is mentioned in the comments of the original article, I'll quote: > There are a couple of in-depth articles about implementing this same idea on Mach / OS X: > http://www.mikeash.com/pyblog/friday-qa-2012-02-03-ring-buffers-and-mirrored-memory-part-i.html http://www.mikeash.com/pyblog/friday-qa-2012-02-03-ring-buff... > http://www.mikeash.com/pyblog/friday-qa-2012-02-17-ring-buffers-and-mirrored-memory-part-ii.html http://www.mikeash.com/pyblog/friday-qa-2012-02-17-ring-buff...