WS5
WS5
Operating Systems
Tutorial Worksheet 05
Description. This tutorial worksheet covers the topic of memory management.
c) What are the advantages of dynamically linked libraries over statically linked li-
braries?
e) Explain how a program is transformed from a source code (e.g., main.c) to a binary
executable file (e.g., main.exe). Describe in which phase libraries and header files are
linked and included.
j) Briefly explain what is the different between a segment fault and a page fault? Explain
what happens in each event.
k) Briefly discuss how modern operating systems that use virtual memory allow the
execution of programs that have a size larger than the available RAM (Read Only
Memory).
l) Briefly describe what thrashing is. How can the operating system detect when thrash-
ing occurs? What should the operating system do when thrashing occurs?
4. Single-level paging
(a) Consider a 64-bit computer that uses single-level paging for memory management. It
uses 64KB as page size and 8 bytes per page entry in the page table. Assuming a program
that uses virtual addresses from 0. . .4GB, what is the size of the page table (a.k.a., flat
page table)?
(b) Now consider the same computer from Question 2.4, what would be the size of the
page table for a 4GB process, if the computer operates a 4-level paging scheme with page
number split equally among the 4 levels (i.e., each level uses the same number of bits to
code a page number)?
(c) Consider a 32-bit computer that has a byte-addressed memory of 1MB. It uses single-
paging scheme with 4KB page size. Having the page table below, translate the following
virtual addresses into physical addresses.
Page ♯ Base address Validity
1 0x6C000 V
2 0xB1000 V
3 0xC4000 V
4 0xA8000 V
5 0xE6000 V
6 0xD1000 V
... ... V
A computer uses segmentation with paging. A virtual address consists of six hexadecimal
digits, SSPPEE, where SS is a segment number and PPEE is the offset within the segment.
The segment is paged, with PP as the page number and EE as the page offset. The page
size is 256 bytes. The physical address is on 16 bits. The figure below shows selected parts
of the current memory contents. All numbers are hexadecimal. Segments and page tables
are indexed starting at 0. Two-digit frame numbers are stored in the segment tables, in
the page tables, and in STBR (Segment Table Base Register). These frame numbers are
converted to main memory addresses by appending 0x00. For example, the entry 0F in
a segment table means that the segment’s page table is located at address 0x0F00. A *
means the page is on disk.
STBR=0x06WWWWWWW List of free page frames: 0x1A, 0x08, 0x21, 0x16, 0x0E.
Segment tables:
0x0200 0x0F 0x0600 0x09 0x3000 0x0F
0x13 0x0A 0x09
0x09 0x4C 0x13
* 0x3D 0x4C
4E 0x5D *
Page tables:
0x3D00 0x5C 0x4C00 * 0x0A00 * 0x0900 04
0x1E 0x3B 0x57
0x5A * * XX
59 0X20 *
* * *
(a) The following sequence of virtual memory addresses are generated by the current
process. What are the corresponding main memory addresses? In answering this question,
assume that new pages are brought into main memory using the given list of free page
frames (0x1A, 0x08, 0x21, 0x16, 0x0E). Write changes to the segment or page tables into
the above figure.
XXXXX0x0000B2XXXXXXXXXXXXX XXXXXXXXXXXXXYESXNO
XXXXX0x020216XXXXXXXXXXXXX XXXXXXXXXXXXXYESXNO
XXXXX0x02015EXXXXXXXXXXXXX XXXXXXXXXXXXXYESXNO
XXXXX0x0202A7XXXXXXXXXXXXX XXXXXXXXXXXXXYESXNO
(b) Following the four accesses performed in part (a), the system switches execution to
another process. The value 0x02 is loaded into the STBR. What segments, if any, are
shared between this new process and the previous process?
(c) Describe what happens when the new process (STBR=0x02) references address 0x030142.
Keep using list of free page frames from part (14.1). Write changes to the segment or page
tables into the above figure. Can you determine what main-memory address results after
address translation? If so, state the address. If not, state what additional information is
needed.
8. Multilevel paging
Consider a 32-bit computer that uses paging as a memory management scheme. Each
page table entry occupies 4 bytes.
(a) What is the smallest page size that allows the page table to fit into one page?
(b) A page size of 1KB is chosen. This means that the page table has to be stored in
multiple levels. Describe how the 32 bit virtual address is divided into fields: how many
fields are there, and how many bits are in each field?
0x019, 0x01A, 0x1E4, 0x170, 0x073, 0x30E, 0x185, 0x24B, 0x24C, 0x430, 0x458, 0x364
(a) What is the reference string, assuming a page size of 256 Bytes?
(b) Find the page fault rate for the reference string in part (a): assume that 2 frames of
main memory are available to the program and the FIFO page replacement algorithm is
used. Note that the page fault rate is calculated as “number of page faults” divided by
“number of virtual memory references used to form the reference string”.
(c) Repeat (b) using the LRU (Least Recently Used) page replacement algorithm.
XXXtemp2 := A[500+i];
XXXA[i] := temp2;
XXXA[500+i] := temp1;
Assume that 100 integers fit into a page, so array A occupies 10 pages. Initially all of A
is on disk. How many page faults occur during program execution in cases (a) and (b)?
Use Least Recently Used (LRU) page replacement. [In this problem we only consider page
faults that result from accessing A: assume that there are no page faults from fetching
instructions.]
(a) Five page frames of size 100 integers are allocated to array A.
Consider a main memory with 220 nanoseconds raw access time, and a TLB (Translation
Look-aside Buffer) cache with 120 nanoseconds access time, respectively. Knowing that
the TLB hit ratio is 98%, calculate the effective access time.