W8 - Memory Management (Part II) Flashcards

(52 cards)

1
Q

What does os.exec() do?

A

Replaces current process image with new process. Process ID remains the same, but orginal code does not resume (function doesn’t return). This is done using one of the os.exec*() functions like os.execv() or os.execl().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Up to how many bytes are addressable with 32 bit addresses?

A

2^32 bytes = 4 gigabytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Up to how many bytes are addressable with 64 bit addresses?

A

2^64 bytes = 16 exabytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the formula for physical address?

A

Frame Number X 2^P + P-Bit Offset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What part of the computer uses page tables to translate pages to frames

A

CPU and Memory Management Unit (MMU)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Since each process gets its own page table, what happens to the current page table after a context switch?

A

You change which page table is active. A specific pointer points to the start of the page table. This will change in a context switch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Imagine consecutive virtual addresses. Are they on consecutive pages? Are they on consecutive frames?

A

They are on consecutive pages, however they can be on any frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does the CPU/MMU know where to find the process’s page table?

A

A register in the CPU points to the start of the page table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How are page tables built? Why is it efficient?

A

An array where indices correspond to page number, and each index is a page table entry containing the frame number (and some flags). This is efficient compared to only storing entries for pages in use because we can jump to a page number and get the corresponding frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where are page tables stored?

A

In memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do flat (one level) page tables work?

A

One page table entry for each of the 2^n page numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Translation Lookaside Buffer (TLB). What is it?

A

Operates as a cache for page number to frame number translations. Super fast.

If we find the page number in TLB, we get a TLB hit and we immediately know the frame number. If we don’t, we get a TLB miss and need to actually check page tables, then write to TLB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Page Fault: When does it occur? What happens?

A

If we get a TLB miss, and the page table tells us it isn’t in memory.

We have to switch to the kernel and execute page fault handling code that lets us load the page to a frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s a page file / swap file?

A

Where we track pages that have been placed into disk. It’s protected by the OS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In practice, do most processes need all their pages on hand in memory?

A

No. Certain features of programs are rarely used. Error handling code is not needed unless that specific error occurs (some errors are very rare). Arrays are often oversized, and we don’t need the entire array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Benefits of loading portions of processes that are actually needed (and only when they are needed):

A

You can write programs for a much larger address space (virtual memory space) than physically exists on computer (so more efficient use of main mem). This is because each process is only using a fraction of its total address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

We check the page table, and the page isn’t in memory. What happens?

A

We have a page fault. This leads to an exception. This leads to the OS page fault handler being executed. We end up needing to perform a context switch for disk access. Page gets put on main memory, and page table is updated. We go back to the scheduler, which may reattempt to access the page, which should work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Once the OS page fault handler loads the page from disk into memory, what crucial step must be performed?

A

Updating the page table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do we tell if a PTE corresponds to a page that isn’t in main memory)

A

One of the flags (a single bit) tells us. If the P bit says “page is not present in memory”, the remaining 31 bits can be used as a pointer for how to find the page in the ‘page file’ on disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the two types of page fault?

A

Minor: Page already in memory but not mapped to process’s address space.
Major: Page not in memory and must be loaded from disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What do we need to do if we’re trying to load a page from disk into main memory, but main memory is full?

A

Page replacement.

22
Q

General Protection Fault

A

A program violates memory access rules enforced by CPU, resulting in a crash.
Core dump (current state written to file).

23
Q

User mode GPF vs Kernel mode GPF

A

User mode GPF => Kernel terminates process
Kernel mode GPF => No way to recover. Blue screen of death or kernel panic. OS restarts.

24
Q

Main cause of Kernel mode GPF

25
Two main issues with page tables
1) Page tables can be large, and you need one for every process. 2) Memory access slow
26
What does sparse mean
Memory efficient
27
Modern systems can address each _ of memory.
Byte
28
Motivations for virtual memory
- Protection between processes - Code mobility - Contiguous addresses in virtual address space - Flexible memory management.
29
What does multi level page tables solve?
PTEs that don't point to a frame taking up unnecessary space. We don't need a million of them for small processes. For example, two level paging uses a page table to tell us which parts of a second page table contains pages. We can avoid creating page tables (and therefore page entries) for sections of the overall page table that don't contain any pages. Up the level again, and you're making a page table of page tables pointing to page tables with page table entries, reducing memory usage further (but increasing number of lookups).
30
What does a 36 bit page number look like when using four level page tables.
123 * 2^27 + 456*2^18 + 789*2^9 + 012
31
Temporal locality vs Spatial locality
Temporal (locality in time) - If a location in memory is accessed, that same location will likely be referenced again soon. Spatial (locality in space) - If a location in memory is accessed, locations close by tend to be referenced soon.
32
Locality of reference
A subset of the addresses in a program's address space has a much higher probability of being accessed again.
33
How does page size affect page faults?
Too small - TLB barely gets hits. - Large number of pages in memory. - Low number of page faults. Too large - Few pages / everything on few/one page(s). - Pages contain locations further from any recent reference. - Page faults rise.
34
Working Set
Set of pages a process is currently using.
35
How does working set vary over time
There can be stable periods (execution of loop/function). In general, it is variable (e.g. one function exits and another is called).
36
Why is it important to have an estimate of the working set?
We can reduce page faults.
37
What is the optimal amount of frames to allocate to a process? idk if this card makes sense
Close to the number of frames/pages in the working set. idk if this card makes sense
38
Thrashing
A process that spends more time paging than executing is said to be thrashing.
39
How do we prevent thrashing?
Provide processes with as many frames as they really need in the current moment.
40
What is locality?
The tendency of a process to access a relatively small set of memory locations repeatedly over a short period of time.
41
Demand paging
Bring pages into memory when a reference is made to the page. Many page faults when process first started.
42
Pre-paging
Bring in more pages than demanded. More efficient to bring in pages that reside contiguously on the disk.
43
Page replacement: FIFO
The oldest page is thrown out. It doesn't consider whether the page is useful or not.
44
LRU (Least Recently Used) Page replacement: Clock page replacement algorithm
Cycle through loaded pages. The clock hand points to the oldest page. On page fault, if the 'used' bit is unset, replace it. Otherwise, unset the used bit and advance clock hand to next page.
45
Page replacement: Frame locking
Some pages are locked to prevent replacement. Use a lock bit to achieve this.
46
Examples of locked frames
Kernel of OS (imagine if code for page replacement was replaced) Control structures I/O buffers.
47
Three techniques for dealing with pages selected for replacement.
Demand cleaning Pre-cleaning Page buffering
48
Demand cleaning
A page is written out only when it has been selected for replacement.
49
Pre-cleaning
Pages are written out in batches.
50
Page buffering
Replaced pages are placed in two lists. Modified page list: Written out in batches Unmodified page list: Reclaimed or lost.
51
What does load control refer to.
How many processes resident in main memory.
52
If there are too many processes, what do we do?
Suspend one. This could be: - Lowest priority process. - Faulting process - Last process activated - Largest process