3 ms·
i may be missing context, but shared memory across processes, without ipc?
by dupontcyborg 3mo ago
i may be missing context, but shared memory across processes, without ipc?
- Giefo6ah 3mo agoThere's nothing special about threads vs processes in Linux. mmap works the same, the challenge is to map the same file. You can share a path, pass a file descriptor via fork or unix domain socket, among other techniques.
- LoganDark 3mo agoThat induces disk I/O overhead (even if it somehow doesn't impact IPC performance)
- drdexebtjl 3mo agoThe file doesn’t have to be disk-backed.
- LoganDark 3mo agoDon't you need something mounted for that?
- yxhuvud 3mo agoNo, you can use a memfd.
- tankenmate 3mo agoAnd `/dev/shm/` (which postgres uses by default on most Unix platforms)
- outpost_mystic2 3mo agoIt doesnt. Processes can share memory
- frollogaston 3mo agoBeing really pedantic here, shared memory is considered IPC, but not the kind you're thinking of. Shared address space, no overhead.
- guenthert 3mo agoAs long as we're pedantic ... the subject is shared memory. Unless you specify the same, non-null, target address in the call to mmap (and the kernel happens to grant you that mapping on all calling sites), the addresses will be different; the address space is not shared (each mapping might also have different access permissions). That distinction is important as pointers generally cannot be shared (a problem which can of course be solved with one more indirection ;-) .
- JackSlateur 3mo ago"Shared address space, no overhead" But concurrent access, so synchronization is required (lock or whatever), so overhead :)
- frollogaston 3mo agoYeah that's true, and I'd say threads need synchronization for concurrent access too, but supposedly the options for doing that are faster than what you need to use across processes.