- What are overlays? How and why were they created?
overlay is also named swapping.
Overlaying means replacement of sections of stored instructions or data".
This is achieved by treating main memory as a cache of hard disk.
Overlays are created since the size of main memory is limited. To allow
memory-consuming program to proceed, we have to swap out the data or
instructions that are not used any more and swap in those to be used.
- What causes a page fault? What is the end result for the running process?
Cache miss causes a page fault.
The running process will proceed after the required data is loaded from
virtual space to physical space.
- Sam P. Hacker is a Head Guru in a software company known for operating systems with very poor quality. Hacker suggested a trick to reduce the pressure on the swap space.
Instead of swapping out pages that belong to code texts into the swap area, the operating system could just take away the memory frames. If the code page is needed later, it could be paged directly from its binary file. Hacker’s argument is that the operating system will save time by not storing the code page into the swap space, and will save space in the swap area. The code text exists on disk anyway, and could be fetched from there. Would
you approve of this design? Why or why not?
这道题的意思是说,磁盘上反正有二进制的代码文本文件,所以干脆不把内存中的代码文件交换到磁盘,不够的时候,直接删除。然后需要的时候再从磁盘拿。
不同意 这种方法,因为忽视了一个问题。
如果在程序在内存执行的过程中,磁盘上放的那个二进制的可执行文件发生变化了,怎么办?比如,我删除了它,或者 我更改了它,那重新加载的代码就是错误的。
除非,在内存执行某个可执行文件的时候,直接锁定这个二进制文件,不允许重新覆盖这个文件。
- Name two advantages of using small pages and two advantages of using large pages in a paging mechanism. Why are page sizes growing in paging memory systems?
Small Pages: Less internal fragmentation. 但是,小page size需要更多数量的page,而这也就需要更多的page table,更多的内存。
Large pages can be used for program instructions. Small pages can be used for threads. Most operating system support only one page size.
选大页面还是小页面需要经过权衡:
Size of the page table - to keep it relatively small, we need bigger pages).
Memory utilization - better with smaller pages because of less internal fragmentation.
I/O time - latency / throughput characteristics call for bigger pages.
选大页面的原因:
内存越来越便宜,利用率不用太在乎。但是I/O是比较慢的,所以页面的size越来越大。而且现在越来越使用多线程,每个程序都不小。
Memory is cheap so we care less about utilization.
Disk access advances in slower pace compared with memory/CPU so I/O factor is most important.
- In a 32-bit machine we subdivide the virtual address into 4 segments as follows:
We use a 3-level page table, such that the first 10-bits are for the first level and so on.
1.
What is the page size in such a system?
The page size depends on the bits used for representing page offset.
The former three sections of address identifies a particular page.
Assume it is a byte-addressible system, that is
2^8 = 256 bytes
2.
What is the size of a page table for a process that has 256K of memory starting at address 0?
256 KB / 256 bytes = 1024 pages
One first-level page table points to 1024 second-level page tables.
One second-level page table points to 256 third-level page tables.
One third-level page table points to 64 pages in virtual memory.
Thus 1024 pages require 1024 / 64 = 16 second-level page table entries.