Virtual Memory Flashcards
VM was created to allow running ____.
processes with memory requirements larger than available RAM to run in the computer.
Currently, VM is used mainly to give each process its own address space.
True/False
True
VM only keeps in RAM the memory that is currently in use.
The remaining memory is kept in disk in a special file called ___.
Swap space
VM implementations:
Process swapping: The entire memory of the process is ___.
swapped in and out of memory
VM implementations:
Segment swapping:
___ are swapped in and out of memory (libraries, text, data, bss etc).
Entire parts of the program (process)
There are 3 VM implementations:
___ swapping
___ swapping
___
process; segment; paging
Which of the following about paging is false?
A. Paging is used by modern operating.
B. The unit of memory that is swapping in and out is a page.
C. Paging divides the memory in pages of different sizes.
D. Usually the size of a page is 4KB in x86.
C.
Paging divides the memory in pages of fixed size.
Paging:
The virtual memory system will keep in memory ___.
It will leave in disk ___.
the pages that are currently in use; the memory that is not in use
Each page in the address space is backed by a file in disk, called ___.
backing-store
Name the backing store for the following memory section: Text ROData Data BSS Stack Heap
Exe file; exe file; exe file (not modified), swap space (modified); swap space; swap space; swap space
Name the permissions (RWX) for the following memory section: Text ROData Data BSS Stack Heap
RX; R; R, RW; RW; RW; RW
Any section in memory that is not persistent and will go away when the process exits is stored in ___.
Swap space
___ translates virtual memory addresses to physical memory addresses.
Memory Management Unit (MMU)
___ memory addresses: the address that the CPU is using. Addresses used by programs are of this type.
Virtual
___ memory addresses: The addresses of RAM pages. This is the hardware addresses.
Physical
The MMU has a ___ that points to the current page table that will be used for the translation.
page table register
Every process shares a page table.
True/False
False.
Each process has its own page table.
The page table register is updated during ___.
The page table has the information of ___.
a context switch from one process to the other.
the memory ranges that are valid in a process.
Consecutive pages in virtual memory are consecutive pages in physical memory.
True/False
False.
Consecutive pages in virtual memory may correspond to non-consecutive pages in physical memory.
To prevent looking up the page table at every memory access, the most recent translations are stored in ___.
Translation Look-Aside buffer (TLB)
The TLB ___ the translation from ___ to ___ memory addresses.
speeds up; virtual; physical
A page fault is an interrupt generated by ___.
MMU
The VM address is divided into 2 parts:
- ___ (higher 20 bits)
- offset (lower 12 bits)
Page number; offset
Both the page number and the offset is translated.
True/False
False.
Only the page number is translated. The offset remains the same.
Modern architectures use a ____ page table to reduce the space needed.
Multi-level
In a two level page table, the page number is divided into 2 parts: ___ page number and ___ page number.
First level; second level
Which of the following about two level page tables is false?
A. Process always have a 1st level page table
B. Process always have a 4KB 2nd level page table
C. Both the 1st and 2nd level page tables use 4KB
B.
Second level page tables are allocated as needed.
Page bits: The remaining __ bits are used to store the characteristics of the page.
12
Describe the bit:
Resident bit
Modified bit
Access bit
Page is resident in RAM instead of swap space/file.
Page has been modified since the last time the bit was cleared. Set by MMU.
Page has been read since the last time the bit was cleared. Set by MMU.`
If a CPU operation exceeds the permissions of a page, the MMU ____.
The interrupt may be translated into ___.
generate an interrupt (page fault). a signal (SEGV, SIGBUS) to the process.
If a page is accesss and the page is not resident in RAM, the MMU ___. Then the kernel ___.
generates an interrupt to the kernel.
loads that page from disk.
Types of page faults:
___ : page not in physical memory, it is in disk
___ : write or access permission violated
Page not resident; protection violation
Sequence of processing a page fault:-
1. A program tries to read/write a location in memory that is in a ___ page.
non-resident
Sequence of processing a page fault:-
2. The MMU tries to ___, and finds that ___. MMu generates ___.
look up the VM address; page is not resident using the resident bit; a page fault
Sequence of processing a page fault:-
3. The CPU save ____ and ___ in the stack.
return address; register
Sequence of processing a page fault:-
4. The CPU looks up the ___ that corresponds to the page fault in the ___ and jumps to this ___.
interrupt handler; interrupt vector; interrupt handler
Sequence of processing a page fault:-
5. In the page fault handler, if the VM address corresponds to a page is not valid for this process, then generate ___.
Otherwise, the page has to be ___.
a SEGV signal to the process.
Loaded from disk.
The default behavior for SEGV is to ___.
kill the process and dump core
Sequence of processing a page fault:-
6. Find ___ in physical memory.
If there are no free pages, use ___.
free page;
One that is in use and write to disk if modified.
Sequence of processing a page fault:-
7. Load the page from disk and ___.
Clear ___ and ___ bits.
Set ___ to 1.
update the page table with the address of the page replaced.
modified and access; resident bit
Which of the following is false?
A. The page fault handler retries the offending instruction at the end of the page fault
B. the program knows that the page fault occurred
B.
The page fault is completely transparent to the program. The program will have no knowledge that the page fault occurred.
The mmap() function established a mapping between ___ and ___.
process’s address space; a file or shared memory object
Mmap returns ___ and it will be always aligned to a ___.
address of the memory mapping; page size
If NULL is passed in the address parameter in mmap(), the OS will choose the address of the mapping.
True/False
True
The mmaped file should have a length of smaller or the program gets a SEGV on access.
True/False
False.
The mmaped file should have a length of larger or the program gets a SEGV on access.
Flags in mmap:
MAP_SHARED : changes in memory will be ___
MAP_PRIVATE : changes in memory will be ___ (__)
MAP_FIXED : force to use ___
MAP_NORESERVE : do not ___ in advance
MAP_ANON : do not use any ___
done in the file; kept private and not reflected in the file (copy on write); "addr" as is without changing; reserve swap space; fd
Mmap parameters:
Offset has to be a multiple of ___.
a page size
Which of the following about mmap is false?
A. Writing in memory of a memory-mapped file will always update the file in the disk.
B. Updating the disk will not happen immediately.
C. The OS will cache the change until it is necessary to flush changes.
A.
Writing in memory of a memory-mapped file will update the file in the disk (only with MAP_SHARED).
VM also speeds up the execution of programs:-
- Mmap the ___ segment of an executable or shared library
- Mmap the ___ segment of the program
- Use of VM during ___ to copy memory of ___ into ___
- Allocate ___ and space for bss, stack and sbrk()
- ___`
text; data; fork, parent , child; zero-initialized memory; shared memory
Initialily, mmap does not ___. Any pages will be loaded on ___.
Startup time is ___ because ___.
It also saves ___ because only the portions of the program that are needed will be in ___.
read any pages; on demand when they are accessed; fast, only the pages needed will be loaded instead of the entire program; RAM, RAM
Physical pages where the text segment is stored is shared by multiple instances of the same program.
True/False
True
During the oading of a program, the OS mmaps the data segment of the program.
Multiple instances of the same program will share ___ where the data segment is mapped as long as ___.
If a page is modified, the OS ___.
the same physical memory pages, the page is not modified;
will create a copy of the page and make the change in the copy
After forking, the child gets a copy of ___.
Both parent and child share the same ___ as long as they are not modified.
When a page is modified by either parent or child, the OS ___.
memory of the parent; RAM pages (physical memory); creates a copy of the page in RAM and will do the modifications on the copy
The copy on write in fork is accomplished by ___.
The OS will catch the modifications. During the page fault, the OS will ___.
Then it will ___.
Making the common pages read only; create a copy and update the page table of the writing process;retry the modify instruction
Which of the following is false?
A. VM is used to allocate space for bss, stack and sbrk()
B. When allocating memory using sbrk or map with the MMAP_ANON falg, all the VM pages in this mapping will map to a single page in RAM that has 0s and is read only
C. When a page is modified, the OS will directly write into the page
D. Fast allocation; saves RAM
C.
When a page is modified, the OS creates a copy of the page (copy on write) and retries the modifying instruction.
Processes may communicate using ___.
Both processes share the same ___.
A modification in one page by one process will be reflected by a change in ___.
shared memory; physical pages; the same page in the other process