Midterm Examination #2 |
COP 4610 - Operating Systems & Concurrent Programming |
This is a closed-book examination. You are not allowed to use any notes,
other references, or a caculator, during the exam. You are You will have 75 minutes to answer
all the questions. Answer on this paper. Write as much of your answer as
will fit in the space provided. If your answer does not fit entirely in
the space below the question, use the blank paper provided to you to complete
your answer. If you believe a question is ambiguous or a multiple-choice
question has other than one correct answer, please write a note on the paper,
explaining what you think is wrong with the question. The exam will be graded
on a scale where 100 pts earns a grade of 'A' (4.0), but it is possible to achieve
a score of up to 130. You will probably find some questions are easier for
you than others. Therefore, it is important to budget your time. Do not
miss the chance to answer some easier questions later in the exam by puzzling
too long over one of the earlier questions. Remember to write your name
on the exam, and on every page if you remove the staple.
On short answer questions that require computation or reasoning, you may
receive some credit for an incorrect answer if you show your intermediate
results and they are partially correct.
The median score as 89.5 and the average was
86.75. The maximum achieved was 117 and the minimum was 31. The
standard deviation was 18.36.
I. True/False: 20 questions, at one point each.
Answer each question by marking a "T" or "F" inside
the parentheses on the left side of the statement.
- ( F )
External fragmentation may occur with the fixed partitioning
model of process memory management.
- ( F )
Internal fragmentation may occur with the simple segmentation
model of process memory management.
- ( T )
Memory compaction takes time proportional to the size of the memory.
- ( F )
Memory compaction is done whenever a region of memory is allocated.
- ( T )
Memory compaction requires that the hardware support dynamic relocation.
- ( T )
Paging provides a mechanism for dynamic relocation.
- ( F )
The buddy system eliminates the need for a list of free storage blocks.
- ( F ) With the buddy system there is no need
to store the size of a block in the block header, because the size of
the block can be computed from the block's address.
- ( F )
Most systems lock all page tables into main memory.
- ( T )
When the working set of a process grows the page fault frequency
will go up.
The objective of the question was to test your
knowledge of the principle behind the Page Fault Frequency (PFF)
algorithm for managing the resident set size, which uses a sustained
increase in the page fault frequency as an indicator that the resident
set needs to grow. However, the PFF is a page replacement scheme with
local scope. During the in-class review of this question, some
students expressed the belief that the page fault frequency need not
go up when the working set grows, so long as the page replacement
scheme has variable allocation and global scope, and the system has
plenty of free page frames. That is at least partly true, if you
assume variable allocation and global scope, and the question would
have been less ambiguous if it had specified local scope. However,
any change in the size of the working set size is likely to be
accompanied by a change in the working set membership. If the page
replacement scheme is successful, the OS will eventually swap pages to
match changes in the working set with changes in the resident set, but
the OS is not prescient, so there will be a bit of a lag. During the
lag, the page fault rate will go up temporarily. Therefore,
I believe the best answer to the question is still "T".
- ( F )
Thrashing is unlikely to occur so long as the mean time between page faults
does not exceed the mean time required to process a page fault.
This is reversed. Thrashing is likely to occur
if the mean time between page faults
is less than or equal to ("does not exceed") the mean time required
to process a page fault.
- ( T )
One way to avoid thrashing is to adjust the multiprogramming level of the system
to keep the utilization of the paging device at 50%.
The objective of this question was to test your
understanding of the principle behind the "50% criterion", which
Stallings says "attempts to keep utilization of the paging device at
approximately 50%". The question would have been better if it had
said "at or below" 50%.
.
- ( F )
Load control is concerned with determining which page to load next into memory
when there is a page fault.
- ( F )
The multiprogramming level of a system is the number of CPUs in the system.
- ( T )
In Unix, the sbrk() system call is used to increase the
size of the data segment.
At least one student had a print-out of an early version of a sample
examination question with a typo, showing the answer to this as "F".
When I checked the web pages after the exam, the answer showed up as "T". I
don't remember for certain, but I guess it was one of those typos that
I caught during class and corrected later, but not before some people
had printed out copies. For this reason, the question is thrown
out of the exam.
- ( F )
Given an interactive SMP system
with assuming round robin (RR) scheduling, the average
response time will be shorter if we assign each user to a unique CPU
at login time (one ready queue per processor) than if we allow the
processes of all users to compete dynamically for the processors
(shared ready queue).
- ( F )
The difference in average throughput between
RR and FCFS scheduling policies becomes greater
as the number of processors goes up.
- ( F )
In a real-time system, the operating system
may (is likely to) sacrifice scheduling predictability in order to achieve higher average throughput.
- ( T )
In a real-time system, fairness in processor scheduling is considered less important
than satisfying the timing constraints of processes.
- ( )
Demand paging is a placement policy.
II. Multiple choice:
20 questions, at two points each.
Answer each question by marking an "X" over the dot to the left of the
best answer.
- Shifting the contents of the regions of memory allocated to processes, so that all
the free memory forms one contiguous region is called
- external fragmentation
- internal fragmentation
- compaction
- swapping
- coalescing
-
With an absolute loader, the time at which the
absolute address of the entry point of a subprogram is bound is
- programming time
- compile or assembly time
- link time
- load time
- run time
- none of the above
-
Combining of multiple object modules into a load module is done by a
- compiler or assembler
- absolute loader
- relocating loader
- dynamic loader
- linker
- none of the above
-
With the Buddy System, the address of the buddy of the block of size 256 bytes with byte address 0111001011011100 would be
- 1111001011011100
- 0111001011011101
- 1000110100100011
- 0111001111011100
0111001101011100
- 0111001011111100
- none of the above
-
Which of the following is not true of paging?
- It enables the possibility of virtual memory
- It requires special hardware support
- Pages are kept in a page table
- It eliminates the problem of external fragmentation
- It may be implemented without virtual memory
- A page table entry is requred for each page
- none of the above
-
An algorithm that chooses which of the
free regions of memory should be allocated to satisfy a given request is called a
- dynamic partitioning algorithm
- relocation algorithm
- placement algorithm
- replacement algorithm
- loading algorithm
- garbage collection algorithm
- none of the above
-
In a multiprogramming system with dynamic partitioning, the algorithm
that chooses which process to swap out of main memory to make room for
a new process is called a
- placement algorithm
- garbage collection algorithm
- memory configuration algorithm
- fragmentation algorithm
- relocation algorithm
- partitioning algorithm
- replacement algorithm
- none of the above
-
Which of the following functions is not served by a base register and a
bounds register?
- map logical to physical addresses
- perform dynamic relocation
- protect the memory of a process from other processes
- perform dynamic linking
- protect the kernel memory from processes
- none of the above
-
Which of the following is true of the Buddy System?
- It is free from internal fragmentation
- It is free from external fragmentation
- It is a compromise between fixed and dynamic partitioning
- It is used for process memory allocation in virtual memory
operating systems
- It requires support for memory compaction
- none of the above
-
Which of the following is true of the first-fit algorithm, as applied
to the allocation of memory to processes in a non-virtual memory OS
with dynamic partitioning?
- the largest block of free memory is quickly broken up into small
fragments
- it will search the entire list of free blocks
- it may litter the front end of memory with small free partitions
- it tends to produces slightly worse results than next fit
- it will frequently lead to an allocation from a free block
at the end of memory
- none of the above
-
Which if the following is not one of the motivations
for implementing virtual memory?
- more processes may be maintained in main memory
- the processor may be used more efficiently,
due to a higher degree of multiprogramming
- a process may be larger than all of main memory
- the implementation of memory management is simplified
- none of the above
-
Which of the following is not one of the advantages of segmentation?
- it simplifies the handling of growing data structures
- it allows handling larger programs
- it allows programs to be altered and recompiled independently
- it lends itself to sharing among processes
- it lends itself to protection
- none of the above
-
Given a fixed number of TLB entries, using a larger page size has the
effect of
- worsening TLB performance
- reducing the page fault rate
- improving TLB performance
- causing more page faults
- none of the above
The TLB has nothing to do with page faults. Using a larger page size
will mean the TLB covers a wider range of virtual addresses, decreaseing
the TLB miss rate.
-
If it were necessary to have a page table entry for every page of
virtual memory, multi-level page tables would take more memory than
single-level page tables. Why is this not a problem?
- A process does not need to have all of its pages in real memory at one time.
- Processes do not use all of their virtual address space.
- The page tables are kept on secondary storage.
- Main memory is getting cheaper every year.
- none of the above
Note that paging the page table (putting it on secondary storage) does
not solve the problem with single-level page tables and large virtual address spaces.
For example, with a 64-bit address and 4Kbyte pages, one would need at least 253
bytes to hold a complete page table. There is no disk drive made that would
hold that much.
-
The function implemented by the TLB is called
- paging
- segmenting
- associative mapping
- direct mapping
- hashing
- chaining
- none of the above
-
What is the reason for having multi-level page tables?
- To reduce the amount of virtual memory occupied by page tables
- To reduce the amount of disk I/O that is needed to handle a page fault
- To reduce the page fault frequency
- To handle larger processes
- none of the above
There was a similar quiz question where the answer was to reduce the amount of real
memory occupied by page tables. The answer here is also correct,
and better. Using multi-level page tables primarily reduces
the need for large contiguous ranges of virtual memory to hold page tables.
Generally that also will mean the page table occupies more real memory.
However, one might quibble that since the page table itself can be paged,
only the portion that is used needs to be kept in real memory, and so
using multi-level page tables may not reduced real memory usage.
-
Which of the following takes the least amount of time to handle?
- hardware interrupt
- cache miss
- page fault
- TLB miss
- disk read operation
-
Which of the following signals is generated by Unix when a process
attempts to reference an operand in memory at a virtual address that is
not aligned properly for the size of the operand?
- SIGSEGV
- SIGBUS
- SIGALGN
- SIGALRM
- SIGMAP
- SIGPGF
- none of the above
-
Which of the following signals is generated by Unix when a process
attempts to reference an operand in memory at a virtual address that is
not mapped?
- SIGSEGV
- SIGBUS
- SIGALGN
- SIGALRM
- SIGMAP
- SIGPGF
- none of the above
- The term "aging" is sometimes used for the policy of promoting a process
to a higher-priority queue (in a feedback queue scheduling scheme) after it
spends a certain amount of time waiting for service in its current queue.
The purpose of this policy is to
- raise the average multiprogramming level
- shorten average response time
- increase average throughput
- prevent deadlock
- prevent starvaton of long-running jobs
none of the above
III. Short answer: 20 questions, at two points each.
Answer each question by writing in one word in each blank space.
- Given a paged memory system with page size 2048,
the page number of logical address 4100 is page number = 2052 % 2048 = 2. (Assume pages and
page frames are numbered starting from zero, in this and all other
questions.)
- Given a paged memory system with page size 2048,
if logical address 4100 maps to page frame 1 the physical
address would be offset = 4100 % 2048 = 4, physical address = 1 * 2048 + 4 = 2052.
- For a machine with 32-bit logical addresses and 4096-byte pages,
the size of the offset part of a logical address
is 4096 = 212, so offset is 12 bits bits.
- In a paged memory system with 32-bit logical addresses, page size
of 2048 bytes, and page table entry size of two bytes, if single-level
paging were used, a page table for the entire virtual address space of
a process would occupy 2048 = 211, so offset is 11 bits, and we need
232 / 211 = 221 page table entries, at two bytes each, so the total
space for the page table is 222 bytes.
- A(n) inverted page table is
a form of hashing scheme in which the hash table
entries point to descriptors each containing a triple (page #, frame
#, link to next item in the hash chain).
- The condition where the system spends most of its time swapping
data between main memory and secondary storage, to the extent that
most of the CPU time is wasted waiting for the swapping device, is
called thrashing.
- The expectation that a program will access again in the future
memory locations that have been accessed recently in the past is
called temporal locality.
- The expectation that a program will access in the future memory
locations close to the locations that it accessed recently in the past
is called spatial locality.
- The abbreviation TLB stands for translation lookaside buffer.
- Consider the page table below, where numbers are in decimal and
everything is numbered starting from zero, all addresses are memory
byte addresses, and the page size is 1024 bytes.
virtual page number | valid bit | page frame number |
0 | 1 | 5 |
1 | 0 | - |
2 | 1 | 4 |
3 | 1 | 1 |
4 | 0 | - |
5 | 0 | - |
6 | 1 | 3 |
7 | 1 | 2 |
Which physical address, if any, would the virtual address 2066
correspond to? (If a page fault would occur, just write "page fault".)
page is 2066 / 1024 = 2, offset = 2066 % 1024 = 18, page frame is 4,
physical address is 4096 + 18 = 4114
- Consider the same page table as above.
Which physical address, if any, would the virtual address 3100
correspond to? (If a page fault would occur, just write "page fault".)
page is 3100 / 1024 = 3, offset is 3100 % 1024 = 28, page frame is 1,
physical address is 1024 + 28 = 1052
- Consider the same page table as above.
Which physical address, if any, would the virtual address 4097
correspond to? (If a page fault would occur, just write "page fault".)
page is 4097 / 1024 = 4, which is not valid, so there is a page fault
- Consider the page frame table below, where numbers are in decimal and
everything is numbered starting from zero.
page frame number | virtual page number | time loaded | time referenced | R bit | M bit |
0 | 6 | 50 | 220 | 1 | 0 |
1 | 2 | 100 | 100 | 0 | 1 |
2 | 3 | 90 | 130 | 0 | 0 |
3 | 0 | 210 | 210 | 1 | 1 |
Suppose a page fault to virtual page 4 has occurred.
Which page frame will have its contents replaced if the FIFO algorithm is used?
frame 0 has the earliest time loaded
- In the same situation as for the question above,
which page frame will have its contents replaced if the LRU algorithm is used?
frame 1 has the earliest time referenced
- In the same situation as for the question above,
which page frame will have its contents replaced if the version
of the Clock algorithm that uses only the (R) bit is used?
the scan visits frames 3, 0, 1, and finds frame 1 has R = 0
- In the same situation as for the question above,
which page frame will have its contents replaced if the version
of the Clock algorithm that uses both the use (R) and modify (M) bits is used?
the scan visits frames 3, 0, 1, and 2, and finds frame 2 has (R, M) = (0, 0)
- In the same situation as for the question above,
and assuming the page reference string 4, 6, 3, 3, 4, 4, 2, 5, 0, 5, 2,
which page frame will have its contents replaced by the optimal
algorithm?
the last referenced page among those in memory is 0, which is in frame 3
- The set of pages a process has referenced in the last t virtual time units
is called the
working set with parameter t.
- The set of pages a process has in main memory
is called the resident set of the process.
- The preemptive scheduling algorithm that minimizes average response time is
shortest remaining process.
Also acceptable were synonyms, such as "shortest remaining processing time first".
Not correct, but allowed to slide, were "shortest process next", "shortest processing time first", etc.
The latter are described in your text as nonpreemptive policies, but some references also
use those names for preemptive policies.
A wrong answer would be "shortest response time", since you don't know the response time
until you have scheduled the job.
IV. Other questions -- 6 questions, at five points each.
- Consider the following program.
#include <stdio.h>
int main (int argc, const char *argv[]) {
char a[5 * sizeof(int)] = {1, 2, 3, 4, 5};
printf ("%d %d %d %d %d\n",
(int) a, *a, (int)(a + 4), *(a + 4), *((int *) ((char *) a + 4)));
return 0;
}
Describe the five output values. If a value consists of a small integer,
give the exact integer value. If the value consists of
a memory address you are not expected to give the exact address; just
describe it in words. If the value is garbage, just state that it is
garbage. If the expression would cause a segmentation fault or other exception,
just say so.
- (int) a address of a[0]
- *a 1
- (int)(a + 4) address of a[4]
- *(a + 4) 5
- *((int *)((char *) a + 4)) "garbage", or 5 on a 32-bit LSB-first machine
The objective of this question was to test whether
you understand the relationship between arrays and pointers and between
characters and integers, and the effects of pointer type conversions.
The value for part (e) is fairly predicable.
The actual output from this program on linprog is:
-1073743280 1 -1073743276 5 5
The last value 5 happens
because the four bytes stored starting at a[4] are 5, 0, 0, and 0,
and the program was run on an Intel Pentium machine, which stores
integers in a format with the least significant bit first. On a 32-bit machine that
stores the most significant bit first, the value would be 0x05000000.
- Explain why the LRU page replacement algorithm is not used in practice.
The overhead of keeping track of the last reference time for each page
frame is too high. To keep it in memory, we would first need to solve the problem
of "recursion" for the page reference that writes the timestamp into memory.
If that is solved, we still have doubled the number of memory cycles, unless
we have special hardware support in the MMU. If the MMU could keep the reference
time along with the other information in the TLB, we would only need to write
the timestamp to memory when there is a TLB fault, but that is still very costly,
since it about doubles the size of the memory and logic needed in the TLB (timestamps are as
big as adddresses), and still requires a double memory reference for every
TLB miss.
Little's Law states that N = lambda * W, where
N is the average number of jobs in the system,
lambda is the average arrival rate of jobs, and
W is the average time a job spends in the system.
Apply Little's Law to solve the following problem, showing
the steps by which you arrive at the answer.
Suppose that, during the morning rush hour,
an average of 100 vehicles back up waiting to get through the traffic light
at Thomasville Road and 7th Avenue, the traffic light cycle takes 5 minutes, and
each cycle allows and average of 20 vehicles to pass through.
What is the average number of minutes a vehicle spends waiting?
N = 100 vehicles; lambda = 20 vehicles / 50 minutes;
W = N / lambda = 100 vehicles / (20 vehicles / 5 minutes) = 100 / 4 = 25 minutes.
Draw the shape of the curve you will get if you plot the
average response time of a job against the average processor
utilization, for an M/M/1 queueing system with average response time
10 milliseconds. Plot the processor utilization on the X axis and the
response time in milliseconds on the Y axis. Obviously, you are not expected to
provide an exact plot, but you are expected to be able to show the
exact response time for a utilization of zero (1 pt), the behavior of the
curve for utilization 1 (1 pt), and the general shape of the curve
(3 pt).
The critical features in the figure are:
- The curve starts low on the left, at some nonzero value less than 10.
The average response time at utilization zero should be equal to the
average service time, which must be less than 10 and greater than zero.
- The curve is asymptotic to a vertical line at utilization 1, since
as the utilizaiton approaches 1 the queue length grows without bound.
- The curve starts out nearly flat and then bends upward.
- Consider the following execution profile of a set of periodic real time tasks:
task | worst-case execution time (ms) | period (ms) |
A | 20 | 100 |
B | 30 | 120 |
C | 100 | 200 |
- What is the total CPU utilization? (1pt) 95% = 20/100 + 30/120 + 100/200 = 20% + 25% + 50%
(2 significant digits is close enough)
- Show the schedule that would be produced by Rate Monotonic Scheduling (RMS), assuming
all the tasks are initially released at the same time, by marking in the letter of the task
that is executing for each of the 10 ms boxes in the Gantt chart below. (2 pt)
0 | 100 | 200 |
A | A | B | B | B | C | C | C | C | C |
A | A | B | B | B | C | C | C | C | C |
A | A | C | C | B | B | B | C | C | C |
The most frequent errors here were: (1) not recognizing that the tasks are periodic;
(2) not computing the release times correctly, especially for task B.
- Show the schedule that would be produced by Earliest Deadline First Scheduling (EDF), under the same assumptions.
In addition, assume that the deadline for completion of each task is the next arrival time of the same task. (2 pt)
0 | 100 | 200 |
A | A | B | B | B | C | C | C | C | C |
C | C | C | C | C | A | A | B | B | B |
A | A | C | C | B | B | B | C | C | C |
There are some acceptable variations on the correct answer for this part, depending on how you treated
jobs with equal deadlines. My solution assumes service order among jobs with equal
deadliens is FIFO, and ties among jobs with equal arrival time and deadline are broken
by alphabetical order.
Suppose a region of 30 words (Yes, that is ridiculously small,
but this is just an exam question.) of storage is managed using boundary
tags and an implicit free list, where memory is allocated only in
whole blocks, and a boundary tag is represented by an integer whose
absolute value gives the block size and whose sign indicates whether
the block is free. Show the values of the boundary tags at
each of the following points in the execution of the system, assuming
the operations in the five parts are performed in order, with
no other operations intervening.
Assume a first-fit placement algorithm is applied and that coalescing of
adjacent free regions is always performed at the earliest possible
moment. For parts (b) through 3), you only need to show the values that
are different from the preceding part.
There are four acceptable answers for this
question, depending on whether you:
- used negative sizes for allocated blocks, or for deallocated blocks
- recorded the user size (excluding tags), or the total size (including tags)
Common errors included:
- not including the right tags
- not allocating enough space to hold the tags without reducing the user
space
- nesting blocks (multiple levels of tags)
- allocating when the question said to free, or vice versa/li>
- Initially, when the entire region is free.
- After blocks of size 3, 5, 4, and 6 (the sizes of the user space) have been allocated, in that order.
- After the block of size 4 has been freed.
- After the block of size 5 has been freed.
- After a block of size 6 has been allocated.
T. P. Baker