5 ms·
For C++, that's only valid for some subset of types, which currently can't be expressed with type traits. "Address-free" has a close enough definition in the co
by o11c 2y ago
For C++, that's only valid for some subset of types, which currently can't be expressed with type traits. "Address-free" has a close enough definition in the context of atomics.
Trivially moveable types are probably sufficient (at least, I can't construct a case where being trivially copyable is needed), but not necessary; there are many things a special member function can do without caring about the address.
In practice, the main problem is that you can't use private mappings (which are the default and for good reason); you have to use shared mapping, which are very finicky to set up and cause infelicities with `fork`. [This does make me wonder how reflinks/`copy_file_range` interact with `mmap` and the page cache.]
Really, you should just fix all your APIs to take an `iovec` array.
- eru 2y ago> In practice, the main problem is that you can't use private mappings (which are the default and for good reason); you have to use shared mapping, which are very finicky to set up and cause infelicities with `fork`. [This does make me wonder how reflinks/`copy_file_range` interact with `mmap` and the page cache.] Yet another reason fork was never a good design choice.
- fc417fc802 2y agoIs fork really the problem in this scenario?
- eru 2y agoI don't think it's the main problem here, but it's just another point where the fork/exec model shows its problems.
- fc417fc802 2y agoWhat would you replace fork with? I don't get it. Isn't the desired improvement here to how the kernel handles the lifetime of mappings? It seems orthogonal to me.
- HeliumHydride 2y agoC++26 is getting a trait called "trivial relocatability", which allows you to communicate that a type can be memcpy'd around without fear.
- gpderetta 2y agoOn linux you can use remap_file_pages[1] to setup your magic ring buffer. Yes, these days it is emulated in the kernel, but here we only care about setting up the expected duplicated mapping of anon pages instead of minimizing the allocations of VMAs. Also linux has MADV_DONTFORK, would that allay your concerns? (there is a potential race between mmap and the madvice call, but if you are forking in a multithreaded program you have worse concerns). [1] https://man7.org/linux/man-pages/man2/remap_file_pages.2.html https://man7.org/linux/man-pages/man2/remap_file_pages.2.htm...