Lecture 10 - Virtual Memory Flashcards

1
Q

What’s the solution to this problem:

Problem: Waste of memory, because a program only needs a small amount of memory at any given time

A

Virtual memory; a program can run with only some of its virtual address space in main memory

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

Explain the principle of locality of reference

A

The key principle is locality of reference, which recognizes that a significant percentage of memory accesses in a running program are made to a subset of its pages. Or simply put, a running program only needs access to a portion of its virtual address space at a given time.

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

With virtual memory, a logical (virtual) address translates to:
(3)

A
  1. Main memory (small but fast), or
  2. Paging device (large but slow), or
  3. None (not allocated, not used, free.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when an executing program references an address that is not in main memory?

A

The page table is extended with an extra bit, present. Initially, all the present bits are cleared (H/W and S/W).

While doing the address translation, the MMU checks to see if this bit is set. Access to a page whose present bit is not set causes a special hardware trap, called page fault (H/W).

When a page fault occurs the operating system brings the page into memory, sets the corresponding present bit, and restarts the execution of the instruction (S/W).

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

Explain how page fault handling works.

A

When a page fault occurs, the operating system:

  1. marks the current process as blocked (waiting for a page),
  2. finds an empty frame or make a frame empty in main memory,
  3. determines the location of the requested page on paging device,
  4. performs an I/O operation to fetch the page to main memory,
  5. triggers a “page fetched” event (e.g., special form of I/O completion interrupt) to wake up the process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Consider the following instruction:

Fetch (instruction);
decrement D0;
if D0 is zero, set PC to “Next” else increment PC.

What if the instruction itself and the address Next are on two different pages and the latter page was not in memory?

From where and how to restart the instruction? (give 3 solutions)

A

Page fault…

  1. Partial effects of the faulted instruction are undone and the instruction is restarted after servicing the fault (VAX-11/780)
  2. The instruction resumes from the point of the fault (IBM-370)
  3. Before executing an instruction make sure that all referenced addresses are available in the memory (for some instructions, CPU generates all page faults!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are 4 policies the operating system implements for virtual memory?

A
  1. Allocation—how much real memory to allocate to each (ready) program?
  2. Fetching—when to bring the pages into main memory?
  3. Placement—where in the memory the fetched page should be loaded?
  4. Replacement—what page should be removed from main memory?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 3 conflicting requirements that Allocation policy deals with?

A

The fewer the frames allocated for a program, the higher the page fault rate.
The fewer the frames allocated for a program, the more programs can reside in memory; thus, decreasing the need of swapping.
Allocating additional frames to a program beyond a certain number results in little or only moderate gain in performance.

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

The number of allocated pages (also known as ___) can be fixed or can be variable during the execution of a program.

A

resident set size
fixed
variable

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

What are the 3 paging methods in Fetching policy?

A
  1. Demand paging (pure)
    Start a program with no pages loaded; wait until it references a page; then load the page (this is the most common approach used in paging systems.)
  2. Request paging
    Similar to overlays, let the user identify which pages are needed (not practical, leads to over estimation and also user may not know what to ask for.)
  3. Pre-paging
    Start with one or a few pages pre-loaded. As pages are referenced, bring in other (not yet referenced) pages too.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are overlays?

A

Additional modules that can be dynamically loaded when a program runs.

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

What are the 4 Replacement policies?

A
  1. FIFO—the frames are treated as a circular list; the oldest (longest resident) page is replaced.
  2. LRU—the frame whose contents have not been used for the longest time is replaced.
  3. OPT—the page that will not be referenced again for the longest time is replaced (prediction of the future; purely theoretical, but useful for comparison.)
  4. Random—a frame is selected at random.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Count the number of page faults in FIFO,
3 frames
Reference string
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

A

9

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

What’s Belady’s Anomaly?

A

Belady’s Anomaly:

in some cases more frames can result in more page faults rather than fewer!

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

Example: LRU algorithm
4 frames
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
# page faults?

A

8 page faults

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

v

A

6 page faults

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

What are the 2 replacement scopes?

A

Global—select a victim among all processes.

Local—select a page from the faulted process.

18
Q

Define frame locking

A

Frame locking—frames that belong to resident kernel, or are used for critical purposes, may be locked for improved performance.

19
Q

Define Page buffering

A

Page buffering—victim frames are grouped into two categories: those that hold unmodified (clean) pages and modified (dirty) pages (VAX/VMS uses this approach.)

20
Q

What is the second chance algorithm?

Run the algorithm on:
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

A

All the frames, along with a used bit, are kept in a circular queue. A pointer indicates which page was just replaced. When a frame is needed, the pointer is advanced to the first frame with a zero used bit. As the pointer advances, it clears the used bits. Once a victim is found, the page is replaced and the frame is marked as used (i.e., its used bit is set to one.)
The hardware, on the other hand, sets the used bit each time an address in the page is referenced.

Check recording nov 20 at the end

21
Q

Some systems also use a “dirty bit” (memory has been modified) to give preference to dirty pages.
Why?

A

It is more expensive to victimize a dirty page.

22
Q

Explain Thrashing

A

When there are far too many processes (i.e., memory is over-committed), the resident set of each process is smaller. This leads to higher page fault frequency, causing the system to exhibit a behavior known as thrashing. In other words, the system is spending its time moving pages in and out of memory and hardly doing anything useful.

23
Q

Define multiple programming level. Why is it useful to know?

When would the possibility of processes being blocked and swapped out be higher?

A

The number of processes that are in the memory determines the multiprogramming (MP) level. The effectiveness of virtual memory management is closely related to the MP level.

When there are just a few processes in memory, the possibility of processes being blocked and thus swapped out is higher.

24
Q

How do we eliminate trashing?

A
The only way to eliminate thrashing is to reduce the multiprogramming level by suspending one or more process(es). Victim process(es) can be the:
lowest priority process
faulting process
newest process
process with the smallest resident set
process with the largest resident set
25
Q

Define working sets.

A

The working set of a program is the set of pages that are accessed by the last Δ memory references at a given time t and denoted by W(t,Δ).

Example (Δ=10):
26157777516234123444434344413234443444233312334

26
Q

Denning’s Working Set Principle states that:

2

A

A program should run if-an-only-if its working set is in memory.

A page may not be victimized if it is a member of the current working set of any runnable (not blocked) program.

27
Q

Give a problem with working sets.

Give a solution to this problem.

A

One problem with the working set approach is that the information about each working set (one per process) must constantly be gathered (i.e., what pages have been accesses in the last Δ seconds?)

A solution (along with the clock algorithm) is:
To maintain idle time value (amount of CPU time received by the process since last access to the page).
Every once in a while (e.g., every few seconds), scan all pages of a process. For each used bit on, clear page’s idle time; otherwise, add process’ CPU time since the last scan to idle time. Turn off all the used bits.
The collection of pages with the lowest idle time is the working set.

28
Q

Define page fault frequency.

When is a frame taken away or added from/to a process?

A

Dealing with the details of working sets usually incurs high overhead. Instead, an algorithm known as page-fault frequency, can be used to monitor thrashing

P = # page faults/ specified time period T
where, T is the critical inter-page fault time.

Dealing with the details of working sets usually incurs high overhead. Instead, an algorithm known as page-fault frequency, can be used to monitor thrashing

29
Q

How does Copy-on-Write work?

When is a page actually copied?

What’s the purpose of Copy-on-Write?

A

Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory

If either process modifies a shared page, only then is the page copied

COW allows more efficient process creation as only modified pages are copied

30
Q

In copy-on-write:

In general, free pages are allocated from a ___ of ___ pages

A

pool

zero-fill-on-demand

31
Q

What’s the difference between vfork and fork?

A

vfork() is a variation on fork() system call that has parent suspend and child using copy-on-write address space of parent

Designed to have child call exec()
Very efficient

32
Q

Explain how kernel memory is allocated.

A

Treated differently from user memory
Often allocated from a free-memory pool
Kernel requests memory for structures of varying sizes
Some kernel memory needs to be contiguous
I.e. for device I/O

33
Q

How does the Buddy system work?

Advantage? (1)
Disadvantage? (1)

A

Allocates memory from fixed-size segment consisting of physically-contiguous pages

Memory allocated using power-of-2 allocator
Satisfies requests in units sized as power of 2
Request rounded up to next highest power of 2
When smaller allocation needed than is available, current chunk split into two buddies of next-lower power of 2
Continue until appropriate sized chunk available

Advantage – quickly coalesce unused chunks into larger chunk
Disadvantage - fragmentation

34
Q

What’s the purpose of prepaging?

What happens when prepaged pages are unused?

Assume s pages are prepaged and α is the fraction of the pages used
What is the formula for determining if prepaging is worth it?

A

To reduce the large number of page faults that occurs at process startup
Prepage all or some of the pages a process will need, before they are referenced

I/O and memory was wasted

Is cost of s * α save pages faults > or < than the cost of prepaging s * (1- α) unnecessary pages?
α near zero -> prepaging loses

35
Q

What are usual concerns of page size selection? (7)

A
Fragmentation
Page table size 
Resolution
I/O overhead
Number of page faults
Locality
TLB size and effectiveness
36
Q

Define TLB reach

A

TLB Reach - The amount of memory accessible from the TLB

TLB Reach = (TLB Size) X (Page Size)

37
Q

What do we ideally want to store in the TLB. Why?

A

Ideally, the working set of each process is stored in the TLB
Otherwise there is a high degree of page faults

38
Q

Name two methods to increase TLB reach, and compare

A
  1. Increase the Page Size
    This may lead to an increase in fragmentation as not all applications require a large page size
  2. Provide Multiple Page Sizes
    This allows applications that require larger page sizes the opportunity to use them without an increase in fragmentation
39
Q

int[128,128] data;
Each row is stored in one page

Program 1
for (j = 0; j <128; j++)
for (i = 0; i < 128; i++) data[i,j] = 0;

Program 2
for (i = 0; i < 128; i++)
for (j = 0; j < 128; j++) data[i,j] = 0;

Which program has lower page faults?

A

Program 1
128 x 128 = 16,384 page faults

Program 2
128 page faults

Because the first program has lower locality, has to load all the j block into the cache just to load a single element from the block.

40
Q

Does linux use segmentation?

A

No

41
Q

What’s the purpose of segmentation?
What’s stored in a segment table?

What’s the LA to address it?

A

Checking for conditions such as limit and base.

column of
limit (offset base value (added to offset)

[ seg # | offset ]