心得分享

Card image cap

鍾同學 報告/作業 分享經驗 5/22 5/19 OS作業

5/22 5/19 OS作業
名稱 5/19 OS作業
日期 5/22
課程名稱 作業系統
指導教師 劉艾華

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.

Answer:

Page table:
Address generated by CPU is divided into:
(1) Page number (p): used as an index into a page table which contains base address of each page in physical memory.
(2) Page offset (d): combined with base address to define the physical memory address that is sent to the memory unit.

TLB:
When presented with an item, it is compared with all keys simultaneously.
If the page number is found in the TLB, its frame number is immediately available and used to access memory.
If the page number is not in the TLB, a memory reference to the page table must be made.

The differences between page table and TLB are that page table can directly find physical address through the page number while TLB uses the method which compared with all page numbers simultaneously.

If the page number is not in the TLB, and it will go to page table. Because page table is in the main memory, we should use TLB to avoid taking much time to search.



2. What is the purpose of paging the page table?

Answer:

In certain situations the page tables could become large enough that by paging the page tables, one could simplify the memory allocation problem (by ensuring that everything is allocated as fixed-size pages as opposed to variable-sized chunks) and also enable the swapping of portions of page table that are not currently used.



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.

Answer:

The size of each page is 2K (2^11 bytes).
Total number of pages is 2^32/2^11=2^21 pages.
Since each entry is 4 bytes, we require 4x2^21 = 2^23 bytes = 8 MB to hold this table.



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

Answer:

Contiguous memory allocation scheme suffers from external fragmentation as address spaces are allocated contiguously and holes develop as old processes dies and new processes are initiated. It also does not allow processes to share code, since a process’s virtual memory segment is not broken into non-contiguous fine grained segments.

Pure segmentation also suffers from external fragmentation as a segment of a process is laid out contiguously in physical memory and fragmentation would occur as segments of dead processes are replaced by segments of new processes.
Segmentation, however, enables processes to share code;for instance, two different processes could share a code segment but have distinct data segments.

Pure paging does not suffer from external fragmentation, but instead suffers from internal fragmentation. Processes are allocated in page granularity and if a page is not completely utilized, it results in internal fragmentation and a corresponding wastage of space.Paging also enables processes to share code at the granularity of pages.

更新日期:2016/5/22 下午 04:38:38