心得分享

Card image cap

王同學 報告/作業 分享經驗 5/13 OS作業

5/13 OS作業
名稱 5/13 OS作業

1. Give the methods that are used in page table and TLB for searching the accessing pages. Compare the differences on the searches between these two hardwares and give reasons why TLB will help the search of the pages.


The CPU's memory management unit (MMU) stores a cache of recently used mappings from the operating system's page table. This is called the translation lookaside buffer (TLB), which is an associative cache.
When a virtual address needs to be translated into a physical address, the TLB is searched first. If a match is found (a TLB hit), the physical address is returned and memory access can continue. However, if there is no match (called a TLB miss), the handler will typically look up the address mapping in the page table to see whether a mapping exists (a page walk). If one exists, it is written back to the TLB (this must be done, as the hardware accesses memory through the TLB in a virtual memory system), and the faulting instruction is restarted (this may happen in parallel as well). This subsequent translation will find a TLB hit, and the memory access will continue.




2. What is the purpose of paging the page table?
The purpose of paging the page table is to speed up the time of seeking the memory ,by doing so ,all of the data can be separated into group so that the system can search the data in a more efficient way.


3. Consider a 32bit address space with 2K bytes page size, assuming that each entry consists of 4 bytes, how much memory are required for the page table for each process? Explain your reason.


A 32 bit address can address 2^32 bytes in a byte addressable machine. Since the size of a page 4K bytes (2^12), the number of addressable pages is 2^32 / >2^12 = 2^20

With 4 byte entries in the page table we can reference 2^32 pages. Since each page is 2^12 B long, the maximum addressable physical memory size is 2^32 * 2^12 = 2^44 B (assuming no protection bits are used).


4. Compare the main memory organization schemes of contiguous-memory allocation, pure segmentation, and pure paging with respect to the following issues:
a. external fragmentation
b. internal fragmentation
c. ability to share code across processes


a. External fragmentation Contiguous allocation with fixed size partions does not suffer from external fragmentation, but contiguous allocation with variable sized partitions does. Pure paging does not suffer from external fragmentation, since partitions and pages are fixed in size. Segmentation does suffer from external fragmentation.
b. Internal fragmentation Segmentation and variable-sized partitions do not suffer from internal fragmentation, since by definition, a segment/partition is exactly as large as it needs to be. However, contiguous allocation with fixed-size partitions and paging both may suffer from internal fragmentation when partitions and pages are not completely filled.
c. Ability to share code across processes Contiguous allocation provides no support for code sharing.
In segmentation, as long as the segments of a process do not mix text and data, we can easily share code between processes. We simply adjust the segment tables of each process to point to the same segment of code in memory. For security reasons, however, it would probably be desirable to have some method of preventing processes from modifying code, since doing so would allow one process to change the code executed by another.
In pure paging, code can be shared across processes simply by sharing page frames. To do this, adjust the page tables of the two processes so that their different logical pages map to the same physical page frame. However, we do need to make certain that no page frame contains any data, which should not be shared. We could accomplish this by, for example, padding the last page of the text segment of the process with no-op machine language instructions.

更新日期:2016/5/19 上午 09:06:12