P3L3: Inter-Process Communication Flashcards
What does the OS need to do to enable processes to share memory?
The OS needs to map their virtual addresses to the same physical memory.
This involves changing each processes page table so that the each one has VPNs that point to shared PFNs.
When processes share memory, do they use the same virtual addresses to access the same memory?
There is no guarantee the virtual addresses will be the same.
For processes to communicate using a shared memory-based communication channel, do they still have to copy data from one location to another?
Data copying is reduced but not eliminated.
Only part of each address space is mapped to the shared memory, so the processes will sometimes need to copy from the local part of their address space to the shared part.
What are the costs associated with message-based IPCs?
Message-based IPCs copy data to the kernel each time they send a message, which also requires a context switch to the kernel, and then the same thing happens on the receiving end. That is two data copies and two context switches for a one-way communication.
Each message has significant overhead.
What are the costs associated with shared memory IPC?
A single, large, up-front cost of mapping the address spaces to the shared physical memory. While this single cost is large, it is amortized over the subsequent sending of messages. Especially for large data transfers, this one-time cost can be worthwhile.
What are the tradeoffs between message-based vs. shared-memory-based communication?
MESSAGE-BASED
Pros:
- Simplicity: the OS handles all channel management and synchronization operations.
Cons:
- This means the OS gets involved in each message: every send and receive requires a system call and a data copy, increasing overhead.
SHARED MEMORY
Pros:
- After mapping virtual to physical memory, the OS is out of the way. This eliminates system calls and reduces data copies.
Cons:
- Developer has to define the communication protocol and explicitly handle all synchronization.
What mechanisms are useful for synchronizing different processes?
- Mutexes: Use them like we did in multithreading
- Semaphores: If we initialize to 1, will act like mutex and only allow one process to access. The locking process decrements semaphore to 0, increments back to 1 on unlock.
- Message-passing IPCs: Can be used to share info about mutexes and semaphores between processes and to let other processes know when read/write operations are complete