Quiz 6
Basic Page Replacement
If no frame is free, we find one that is not currently being used and free it. We can free a frame by writing its contents to swap space and changing the page table to indicate that the page is no longer in memory. we can now use the free frame to hold the page for which the process faulted.
(page replacement) We can reduce overhead by using a modify bit (or dirty bit)
When this scheme is used, each page has a modify bit associated with it in the hardware. Set by the hardware whenever any byte in the page is written into, indicating that the page has been modified. When we select a page for replacement, we examine its modify bit. If the bit is set, we know that the page has been modified since it was read in from the disk. In this case, we must write the page to the disk. If the modify beit is not set, however, the page has not been modified since it was read into memory. In this case, we need not write the memory page to the disk: it is already there.
Instead of swapping in a whole process, the pager brings only those pages into memory that it guessed will be used. Thus,
it avoids reading into memory pages that will not be used anyway, decreasing the swap time and the amount of physical memory needed
Demand paging
load pages only as they are needed, commonly used in virtual memory systems. Pages are loaded only when they are demanded during program execution. Pages that are never accessed are thus never loaded into physical memory. Similar to paging system with swapping where processes reside in secondary memory (usually a disk). Use a lazy swapper instead of swapping entire process into memory. A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process.
The ability to execute a program that is only partially in memory would confer many benefits:
-----A program would no longer be constrained by the amount of physical memory that is available. Users would be able to write programs for an extremely large virtual address space, simplifying the programming task. -----Because each user program could take less physical memory, more programs could be run at the same time, with a corresponding increase in CPU utilization and throughput but with no increase in response time or turnaround time -----Less I/O would be needed to load or swap user programs into memory, so each user program would run faster.
Procedure for handling page fault:
1.) Check an internal table (usually kept with the process control block) for this process to determine whether the reference was a valid or an invalid memory access 2.) if the reference was invalid, we terminate the process. if it was valid but we have not yet brought in that page, we now page it in. 3.) we find a free frame(by taking one from the free-frame list) 4.) we schedule a disk operation to read the desired page into the newly allocated frame 5.) when the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory 6.) we restart the instruction that was interrupted by the trap. The process can now access the page as though it had always been in memory
The hardware to support demand paging is the same as the hardware for paging and swapping:
1.) Page table. This table has the ability to mark an entry invalid through a valid-invalid bit or a special value of protection bits. 2.) Secondary memory. This memory holds those pages that are not present in main memory. The secondary memory is usually a high-speed disk. It is known as the swap device, and the section of disk used for this purpose is known as swap space.
In addition to separating logical memory from physical memory, virtual memory allows files and memory to be shared by two or more processes through page sharing leading to the following benefits:
1.) System libraries can be shared by several processes through mapping of the shared object into virtual address space. Although each process considers the libraries to be part of its virtual address space, the actual pages where the libraries reside in physical mmory are shared by all the processes. Typically, a library is mapped read-only into the space of each process that is linked with it. 2.) Similarly, processes can share memory. Two or more processes can communicate through the use of shared memory. Virtual memory allows one process to create a region of memory that it can share with another process. Processes sharing this region consider it part of their virtual address space, yet the actual physical pages of memory are shared 3.)Pages can be shared during process creation with the fork() system call, thus speeding up process creation.
Let p be the probability of a page fault (0<=p<=1). We would expect p to be close to zero - that is, we would expect to have only a few page faults. The effective access times is then:
= (1-p) * ma + p * page fault time
It is up to the ________ _________ ____ to map logical pages to physical page frames in memory
Memory-management unit (MMU)
Page fault
The paging hardware, in translating the address through the page table, will notice that the invalid bit is set, causing a trap to the operating system. This trap is the result of the OS failure to bring the desired page into memory
Sparse address spaces
Virtual address spaces that include holes Using a sparse address space is beneficial because the holes can be filled as the stack or heap segments grow or if we wish to dynamically link libraries(or possibly other shared objects) during program execution.
Copy-on-Write
allows the parent and child processes initially to share the same pages. These shared page are marked as copy-on-write pages, meaning that if either process writes to a shared page, a copy to the shared page is created.
The valid-invalid bit scheme
distinguishes between the pages that are in memory and the pages that are on the disk. when this bit is set to "valid", the associated page is both legal and in memory. If the bit is set to "invalid", the page either is not valid (that is, not in the logical address space of the process) or is valid but is currently on the disk. The page-table entry for a page that is brought into memory is set as usual, but the page-table entry for a page that is not currently in memory is either simply marked invalid or contains the address of the page on disk. While the process executes and accesses pages that are memory resident, execution proceeds normally.
A crucial requirement for demand paging is:
the ability to restart any instruction after a page fault. Because we save the state (registers, condition code, instruction counter) of the interrupted process when the page fault occurs, we must be able to restart the process in exactly the same place and state, except that the desired page is no in memory and is accessible. If we fault when we try to store in C because C is in a page not currently in memory, we will have to get the desired page, bring it in, correct the page table, and restart the instruction. The restart will require fetching the instruction again, decoding it again, fetching the two operands again, and then adding again.
The virtual address space of a process refers to
the logical (or virtual) view of how a process is stored in memory
Virtual memory involves
the separation of logical memory as perceived by users from physical memory. This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available.