17. Swapping Flashcards

1
Q

What two things happen when we run out of physical memory?

A
  1. Fail and either don’t load the process (exec()), don’t create a new process (fork()), refuse to allocate more heap (sbrk()), or kill the process if it is trying to allocate more stack.
  2. Create more space, preserving the contents of memory for later use.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the requirements for having the kernel remove memory from a process “behind its back”?

A
  1. The last time the process used the virtual address, it behaved like memory.
  2. The next time the process uses the virtual address, it behaves like memory.
  3. In between, whatever data was stored at that address must be preserved.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is swapping?

A

The process of moving data back and forth from memory to disk in order to improve memory usage

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

What is the goal of swapping?

A

The system feels like it has memory that is as large as the size of the disk but as fast as actual RAM

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

When the OS goes to borrow memory from a process, what does it typically do with the data stored in that memory?

A

The OS moves the memory onto disk for safe keeping until the memory is given back to the process

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

What are the two kinds of memory-related faults we can expect to deal with?

A

TLB faults and page faults

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

What is a TLB fault?

A

A required virtual to physical address translation is not in the TLB

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

What is a page fault?

A

The contents of a virtual page are either not initialized or not in memory

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

What is the logical relationship between page fault occurrences and TLB fault occurrences?

A

Every page fault is preceded by a TLB fault, but not every TLB fault generates a page fault.

If the contents of the virtual page are not in memory, a translation CANNOT exist for it. By contrast, if a page is in memory and the translation is the page table, the TLB fault can be handled without generating a page fault.

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

What three things need to happen to swap a page to disk?

A
  1. Remove the translation from the TLB (if it exists).
  2. Copy the contents of the page to disk.
  3. Update the page table entry to indicate that the page is on disk.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Break down the three steps of swapping in terms of relative speed.

A

Removing the translation from the TLB is fast. Copying the contents of the page to disk is super slow. Updating the page table entry to indicate that the page is on disk is fast.

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

When must we swap in a page?

A

When the virtual address is used by the process.

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

How can we set up the swap out function to be faster?

A

Give each page a dedicated place on disk and then, during idle periods, have the OS write data from active memory pages to their space on disk.

Pages with matching data between active memory and disk are called clean, so they can be overwritten immediately.

Pages that do not match their swap disk content are called dirty and need to be saved to disk before being overwritten in memory.

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

Why must we remove the TLB entry first before swapping out?

A

Because if another process tries to access information at that virtual address, the TLB will happily map that process to physical memory, but that location is currently or about to be loaded with new information after the swap finishes. Remove the translation entry so no other process can grab data that is not currently there.

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

What 7 steps must we take to translate a virtual address used by a process (that points to a page that has been swapped out)?

A
  1. Stop the instruction that is trying to translate the address until we can retrieve the contents.
  2. Allocate a page in memory to hold the new page contents.
  3. Locate the page on disk using the page table entry
  4. Copy the contents of the page from disk.
  5. Update the page table entry to indicate that the page is in memory.
  6. Load the TLB.
  7. Restart the instruction that was addressing the virtual address we retrieved.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is on-demand paging?

A

If the process says to load a bunch of memory, make a note in an area of the page table to allocate space for the load, but don’t do the load until you need to. There is a good chance the memory will never be used, so why waste time loading it in?

17
Q

What happens the first time a process does a load or store to an uninitialized heap, stack, or data page?

A

The kernel allocates a new page filled with zeros and the instruction is restarted.

18
Q

What happens the first time a process does a load or store to an uninitialized heap, stack, or data page?

A

The kernel allocates a new page filled with zeros and the instruction is restarted.