Example Questions

Solutions

Problem 1

There are many possible possibilities to assign the process pages to
physical frames:

Physical Memory

0:

A

1:

B

2:

Data1

3:

Data2

4:

Data3

Page Table P1:

0:

2 (private data)

1:

0 (shared data A)

Page Table P2:

0:

3 (private data)

1:

0 (shared data A)

2:

1 (shared data B)

Page Table P3:

0:

4 (private data)

0:

1 (shared data B)

After swapping out all pages assigned for process P1 we don't
need a page table for P1 any longer. Also, we need to
invalidate the entry for page A in page table for P2.

Physical Memory

0:

----

1:

B

2:

----

3:

Data2

4:

Data3

Page Table P2:

0:

3 (private data)

1:

invalid

2:

1 (shared data B)

Page Table P3:

0:

4 (private data)

1:

1 (shared data B)

Once, you've swapped P1 back into memory, we have to update all
page tables which are sharing data with this process. Observe that the memory
allocation might be different from the initial one:

Physical Memory

0:

Data1

1:

B

2:

A

3:

Data2

4:

Data3

Page Table P1:

0:

0 (private data)

1:

2 (shared data A)

Page Table P2:

0:

3 (private data)

1:

2 (shared data A)

2:

1 (shared data B)

Page Table P3:

0:

4 (private data)

0:

1 (shared data B)

In order to maintain coherence between page tables the operating
system needs to invalidate all page table entries which are refering
to a page once that page gets swapped out. Whenever a shared page is
swapped back into memory, all the processes sharing this page need to
update their page tables.

This can be efficiently implemented using pointers as aliases for shared
pages: Store in a page table the usual pointer to the physical memory for
non-shared pages. For shared pages, keep a pointer to a special shared node.
This nodes contains either a pointer to the location of the shared page in
physical memory, NULL if that page isn't contained in memory.

The diagramm below shows such a structure for a shared page between process
1 and process 2. (Logical page 1 of process 1 and logical page of process
2 are aliassed.)

Whenever we need to invalidate a shared page, we set the shared node
pointer to NULL. Whenever we swap back a shared page into the memory,
we set the shared node pointer to the new memory location.

Problem 2

Page Faults

The following things happen at a page fault:
1) checking the TLB: page not in TLB (+ t_tlb)
2) checking the Page Table: page not in memory (+ t_memory_access)
3) Transfer page from disk and update both,
the TLB and the page table (+ t_access_transfer)
The time for all of this is accummulated as access/transfer time.
4) check TLB successfully (+ t_tlb)
5) get memory entry. (+ t_memory_access)

Access Frequency

page in TLB: 80% of all accesses

page not in TLB: 20% of all accesses

page in page table: 18% of all accesses

page not on page table, but on disk: 2% of all accesses
(10% of the 20% accesses not served by TLB)

Access Time in micro seconds [us]

page in TLB:time for TLB + time for memory =
0.1us + 1us = 1.1 us

page not in TLB:

page in page table:
time for TLB
+ time for page table
+ time for memory =
0.1us + 1.0us + 1.0us = 2.1 us

page not on page table, but on disk:
time for TLB
+ time for page table
+ time for disk
+ time for TLB
+ time for memory =
0.1us + 1us + 20 000us + 0.1us + 1us = 20 002.2 us

Effective Access Time

We compute the effective access time as sum of the access times weighted by
their frequency: