Week 7 Flashcards

1
Q

Suppose we have the following.

010101

What is the virtual address?

What is the virtual page number?

What is the offset?

A

Virtual Address: 21
Virtual page number: 1
Offset: 5

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

What are the steps for converting a virtual address into a physical address?

A
  1. Encode the physical frame number
  2. Encode the physical page offset
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does the OS find a free page?

A

One option is to keep a free list of available pages.

Because the pages are all the same size, the OS can just grab the first page in the list.

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

How does the OS keep track of which process is using which physical page?

A

Using a per process data structure called a page table.

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

What are some pros of paging?

A

We don’t have to allocate a physical page for all virtual pages in the address space. (use a valid bit to keep track)

We can use protection bits to mark pages as readable, writeable or executable.

We can swap pages from memory to disk and back again, allowing us to support address spaces larger than physical memory.

Different processes can share pages.

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

What is a linear page table?

A

Each row in this table is a page table entry describing the mapping for a single page.

Each page table entry stores the information necessary for translation: physical frame number, protection bits, present bit, valid bit, etc.

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

What are some cons of paging?

A

Memory waste. Hundreds of MBs across all processes. We need to put this information in memory.

More memory accesses. Translation is slow. Hardware must look up the correct page table entry before it can translate a virtual address.

Complexity. Swapping pages in and out means more complexity and performance challenges.

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

PAGING PRACTICE

Assume we are given a virtual address. How do we calculate the cirtual page number?

A

Zero out everything but the VPN bits using a logical & operation with a bit mask.

Use a shift to move the VPN over

VPN = (VirtualAddress & VPN_MASK) >> SHIFT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PAGING PRACTICE

How do we calculate offset?

A

Mask out everything but the offset bits

Offset = VirtualAddress & OFFSET_MASK
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we find the correct page table entry in a linear page table?

A

First we find the page table index. This is the same as the virtual page number.

Second we account for the page table entry size and where the page table starts in memory. The page table base register (PTBR) stores the base address of the page table.

PTE_Addr = (VPN * sizeof(PTE) + PTBR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

PAGING PRACTICE

How do we check for error conditions?

A

Raise segmentation fault if PTE is not valid.
~~~
PTE.Valid == False
~~~

Raise protection fault if memory access violates protection bits
~~~
CanAccess(PTE.ProtectBits) == False
~~~

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

PAGING PRACTICE

How can we calculate the physical address now that we know the physical page number?

A
PhysAddr = (PTE.PFN << PFN_SHIFT) | Offset
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the approach for TLBs?

A

Cache recent translations in the translation look aside buffer (TLB) to avoid costly accesses to the page table.

The TLB stores VPN | PFN | other bits

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

What happens on a TLB hit?

A

Fast if the TLB already has the translation for the virtual page number, we can directly access the physical memory.

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

Who handles the TLB miss?

A

Hardware managed. Requires knowledge of page table location and the format of the page table entries.

software (OS) managed: hardware jumps to a trap handler and the OS handles the TLB miss, updating the TLB. (more flexible than just using software).

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

What happens on a TLB Miss?

A

Slow if the TLB does not have translation, then we need to grab, parse the corresponding page table entry, add it to the cache and try again.

17
Q

How do we handle a context switch in a TLB?

A

Option 1: Flush the TLB by removing all TLB entries. Costly if you frequently context switch.

Option 2: Address-space Identifier field. Link TBL entries to a
particular address space. More complex. May reduce the number
of entries that each process can use.

18
Q

Where do we put the cache (TLB)?

A

Make it part of the hardware’s
memory management unit (MMU).

19
Q

The size problem

Suppose that we make the pages larger. That is we Increase the reach of each page table entry by increasing the page size, e.g., 16KB pages instead of 4KB.

What are some pros and cons

A

Pros: Table size decreases by same factor as the page size increases. TLB is now more effective as well. There is support for
this in many architectures (e.g., x86-64).

Cons: increased potential for internal fragmentation. Not great for sparse address spaces

20
Q

What is a multi level page table?

A

> Idea: split the page table into pages. If an entire page table page is
unused, don’t put it in memory.
To track the pages of the page table, we use a hierarchy of page
directory.
We call this design a multi-level page table