Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by HeliumHydride on Sunday March 23, 2025 @11:41PM
(#43457649)
C++26 is getting a trait called "trivial relocatability", which allows you to communicate that a type can be memcpy'd around without fear.
Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by eru on Sunday March 23, 2025 @10:55PM
(#43457492)
> 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.
Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by fc417fc802 on Monday March 24, 2025 @04:53AM
(#43458740)
Is fork really the problem in this scenario?
Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by eru on Monday March 24, 2025 @11:43PM
(#43467934)
I don't think it's the main problem here, but it's just another point where the fork/exec model shows its problems.
Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by fc417fc802 on Tuesday March 25, 2025 @10:30AM
(#43471799)
What 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.
Re:Shift-to-Middle Array: A Faster Alternative to Std:Deque?
by gpderetta on Tuesday March 25, 2025 @06:35AM
(#43469713)
On 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.htm...
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.