Skip to content

Latest commit

 

History

History
96 lines (72 loc) · 7.88 KB

17_Shared Physical Pages.md

File metadata and controls

96 lines (72 loc) · 7.88 KB

Shared Physical Pages 📘

Shared Physical Pages Concept:

  • Definition: A shared physical page is a physical memory page that is accessed by two or more processes running on a system.
  • Usage: It allows multiple processes to read and write into the same physical memory portion, facilitating data exchange and communication between processes, known as Inter-process Communication (IPC) through shared memory.
  • Page Table Entry: The same physical page is present in the page tables of two or more processes.
  • Physical and Virtual Addresses: The processes generate virtual addresses that map to the same physical memory location using virtual and physical page numbers and offsets. The paging mechanism is utilized to determine the physical address that corresponds to a virtual address.
  • Practical Example: Process P1 and P2 in the lecture both interact with the same physical memory location. For example, a write operation by process P1 on the shared page is visible and accessible to process P2.
  • Utility in IPC: The shared physical pages provide a mechanism where modifications (writes) done by one process on a physical page are available to all processes sharing that page, providing a communication medium between them.

System Configuration & Paging:

  • The virtual address has four bits, decomposed into two parts of two bits each.
  • A system configuration specifies how physical memory is segmented, and how virtual addresses are mapped to physical addresses.
  • The example in the lecture used physical memory fragmented into eight frames, each of size four bytes.
  • Processes generate virtual addresses, which are then decomposed to locate relevant page numbers and offsets, which in turn map to physical addresses.

Data Writing and Reading:

  • Processes can write data into a shared physical page at a specific virtual address, and this data becomes visible to all other processes sharing the page.
  • As illustrated in the lecture, if process P1 writes a string to a shared page, process P2 can read the same string from that page, facilitating data exchange.

IPC via Shared Memory:

  • Shared physical pages enable IPC through shared memory, where processes communicate and exchange data by reading and writing to a shared physical page.

Curiosity 🧠

  1. Q: How does a shared physical page facilitate IPC? A: Shared physical pages allow multiple processes to read and write to the same physical memory, enabling them to exchange data and communicate without using additional data transfer mechanisms.

  2. Q: What challenges might arise with multiple processes writing to a shared physical page? A: Challenges can include race conditions, data inconsistency, and the need for synchronization mechanisms to ensure data integrity and orderly access to the shared memory.

  3. Q: What are virtual and physical addresses, and how are they utilized in shared physical pages? A: Virtual addresses are used by processes and are mapped to physical addresses (actual locations in RAM) through a mechanism like paging. In the context of shared physical pages, multiple processes’ virtual addresses might point to the same physical address, enabling shared memory access.

  4. Q: What is the significance of a system call like mmap in relation to shared physical pages? A: The mmap system call in Unix/Linux allows processes to create a shared memory region, thereby permitting them to map a physical page into their respective address space and enabling data exchange through that shared memory.

  5. Q: How does the operating system manage the mapping of virtual addresses to physical addresses? A: The OS uses a data structure known as the page table to manage the mapping. Each entry in a process's page table holds the mapping between a virtual page and a physical frame in memory. In shared physical pages, entries in the page tables of different processes point to the same physical frame.

  6. Q: How can processes ensure data consistency when writing to a shared physical page? A: Processes must employ synchronization mechanisms, like semaphores or mutexes, to manage access to shared pages, ensuring that write and read operations occur in an orderly and consistent manner without clashes or overwrites.

  7. Q: Explain a practical scenario where shared physical pages might be useful. A: Shared physical pages can be highly useful in scenarios where processes need to exchange data rapidly and frequently, for example, in a producer-consumer scenario where one process generates data (producer) and another process consumes it (consumer). The shared physical page can act as a buffer or exchange point for the data.

Concepts in Simple Words 🌟

  • Shared Physical Pages:

    • Think of shared physical pages like a shared notebook used by multiple people (processes). They all can read and write in it, so if one person writes a note, the others can read it.
    • In computer terms, when two or more running software processes use the same memory spot (page), we say they are using a shared physical page. It's like all of them writing and reading notes from the same page in the shared notebook.
  • Inter-process Communication (IPC) through Shared Memory:

    • The shared notebook (physical page) becomes a way for all the people (processes) to communicate with each other. One writes a note, and others can read it and respond by writing their own notes.
    • So, through sharing this one page, different software processes can talk to each other by writing and reading data to and from that shared memory spot. This is called inter-process communication through shared memory.

+--------------+       +--------------+       +--------------+
|  Process P1  |       |  Process P2  |       |  Process P3  |
+--------------+       +--------------+       +--------------+
       |                      |                      |
       | Virtual Address      | Virtual Address      | Virtual Address
       | (e.g., 1001)         | (e.g., 1101)         | (e.g., 1010)
       V                      V                      V
+----------------+      +----------------+      +----------------+
|  Page Table P1 |      |  Page Table P2 |      |  Page Table P3 |
+----------------+      +----------------+      +----------------+
       |                      |                      |
       | Maps to              | Maps to              | Maps to
       | Physical Page Y      | Physical Page Y      | Physical Page Y
       V                      V                      V
+-------------------+
|  Physical Page Y  |
+-------------------+
       |
       | Contains data written/read by
       | P1, P2, and P3
       V
+------------------------------------+
|  Shared Data (e.g., "Hello World") |
+------------------------------------+
  • Process P1, P2, and P3: These represent individual software processes. They all have virtual addresses which are supposed to map to some physical location in the RAM.

  • Page Table P1, P2, and P3: When a process wants to access memory, it consults its page table. The page table helps convert a "virtual" address (used by the process) to a "physical" address (actual location in RAM). The entries in these page tables are set in a way that they all point to the same physical page (Y).

  • Physical Page Y: This is a spot in the physical memory (RAM) that is being shared by all three processes. They all map to this page via their respective page tables, meaning they can all read and write data here.

  • Shared Data: When one process writes data into Physical Page Y, this data becomes visible to all other processes due to the shared mapping. So, if Process P1 writes "Hello World" into the memory, Process P2 and P3 can read this data, enabling communication between them.

This is a simplified representation and might not cover all technical details, but it should give a fundamental idea of how shared physical pages can facilitate IPC.