\documentclass[10pt]{article}
\usepackage{times,mathptm}
\pagestyle{myheadings}

\parindent 0in
\setlength{\parindent}{0in}
\setlength{\parskip}{1ex}

\topmargin -0.1in \headheight\baselineskip
\textheight 8.5in         % 1in top and bottom margin
\textwidth 6.5in        % 1in left and right margin
\oddsidemargin 0in
\evensidemargin 0in


% \setlength{\itemsep}{0pt}

\markright{\footnotesize CS 481 Operating Systems Principles, Fall 2000}

\begin{document}

\section*{Homework 5 --- due on Thursday 2 November 2000}

Total number of points available on this homework is 110. Full credit
is equivalent to 100 points.

\begin{enumerate}




\item (10 pts) Consider a process with a logical address space of 16
pages of 1024 words each, mapped onto a physical memory of 64 frames.

\begin{enumerate}
\item How many bits are there in the logical address? 

\item How many bits are there in the physical address?

\end{enumerate}



\item (10 pts) Consider a paging system with the page table stored in
memory.

\begin{enumerate}
\item If a memory reference takes 150 nanoseconds, how long does a
paged memory reference take?

\item If we add associative registers (a TLB), what percentage of page
table references need to hit in the TLB to get an effective access
rate of 155 nanoseconds?
\end{enumerate}






\item (15 pts) Consider a segmented memory system 
with  free memory ``holes'' of size 500K, 200K, 100K,
300K, and 450K (in order). How would each of First-Fit, Best-Fit, and
Worst-Fit place processes of size 212K, 420K, 150K, and 350K (in
order), and what would be the remaining hole sizes?  Which makes the
most efficient use of memory for this example?



\item (15 pts) For First-Fit, Best-Fit, and Worst-Fit, how long does it
take to find a free segment on average with

\begin{enumerate}
\item an unsorted list of free segments, and
\item a list sorted by size.
\end{enumerate}



\item (35 pts) Consider the following  paged
segmentation scheme.

{\footnotesize
\begin{center}
\begin{minipage}{3in}

\begin{center}
\begin{tabular}{|r|r|}\hline
\multicolumn{2}{|c|}{\bf Segment Table} \\ \hline
Segment Number & Page Table \\ \hline \hline
0 &			2  \\ \hline
1 &			0 \\ \hline
2 &			1 \\ \hline
\end{tabular}
\vspace*{2em}

\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{\bf Page Table 0} \\ \hline
Virtual & Page  &       & Read \\ 
Page    & Frame & Valid & Only? \\ \hline\hline
0 	& 10	& Y	&  N \\ \hline
1 	& 17 	& N	&  N \\ \hline
2 	& 89 	& Y	&  N \\ \hline
3 	& 90 	& Y	&  N \\ \hline
4 	& 29 	& Y	&  N \\ \hline
5 	& 47 	& N	&  N \\ \hline
6 	& 55 	& Y	&  N \\ \hline
7 	& 32 	& Y	&  N \\ \hline
8 	& 36 	& Y	&  N \\ \hline
9 	& 9 	& Y	&  N \\ \hline 
\end{tabular} 

\vspace*{.25em}
{\normalsize
\begin{itemize}
\item ``Valid?'' is set to ``Y'' if  the page is in memory.

\item ``Read Only?'' is set to ``N'' if the page is writable.
\end{itemize}}

\end{center}
\end{minipage}\hspace*{3em}
\begin{minipage}{2.5in}
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{\bf Page Table 1} \\ \hline
Virtual & Page  &       & Read \\ 
Page    & Frame & Valid & Only? \\ \hline\hline
0 	& 3 	& N	&  N \\ \hline
1 	& 22 	& N	&  N \\ \hline
2 	& 73 	& Y	&  N \\ \hline
3 	& 74 	& Y	&  N \\ \hline
4 	& 85 	& Y	&  N \\ \hline
5 	& 29 	& Y	&  N \\ \hline
6 	& 63 	& Y	&  N \\ \hline
7 	& 93 	& Y	&  N \\ \hline
8 	& 83 	& Y	&  N \\ \hline
9 	& 15 	& Y	&  N \\ \hline 
10 	& 27 	& Y	&  N \\ \hline 
11 	& 34 	& Y	&  N \\ \hline 
\end{tabular}

\vspace*{2em}
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{\bf Page Table 2} \\ \hline
Virtual & Page  &       & Read \\ 
Page    & Frame & Valid & Only? \\ \hline\hline
0 	& 33 	& Y	&  Y \\ \hline
1 	& 46 	& Y	&  Y \\ \hline
2 	& 54 	& N	&  Y \\ \hline
3 	&  6 	& Y	&  Y \\ \hline
4 	& 99 	& N	&  Y \\ \hline
5 	& 67	& Y	&  Y \\ \hline
6 	& 21 	& Y	&  Y \\ \hline
\end{tabular}
\end{minipage}
\end{center}}
\begin{itemize}
\setlength{\itemsep}{-.5ex}
\item Assume a page size of 1000 bytes using base 10 integer addresses (not
realistic, but it makes the math easier). Thus, the first page of virtual
memory runs from virtual address 0 through virtual address 999.  (All
accesses to memory are for 4-byte words.)
\item The maximum number of page table entries is 100 (0 to 99).
\item Each process is separated into at most 3 segments (1 segment each for
code, heap allocated data, and the stack).
\item If the page is invalid (``Valid = N''), assume the page fault causes
the OS to load the faulting page into the given page frame number; for
example, an access to virtual page 2 in page table 2 causes a page
fault where the OS loads virtual page 2 into page frame 54.
\end{itemize}

\begin{enumerate}
\setlength{\itemsep}{0pt}
\item (10 pts) How many integer digits do we need for the segment number,
page number, and offset? 

\item[(b-f)] What physical address do the following virtual addresses
access? (Assume any missing digits are leading zeroes.)  Indicate if the
access generates an error (invalid segment, invalid page, or protection
violation) or a page fault.  


\item (5 pts) Read from virtual address 211333 

\item (5 pts) Write to virtual address 5345  

\item (5 pts) Read from virtual address 1810627

\item (5 pts) Read from virtual address 104806

\item (5 pts) Read to virtual address 200097


\end{enumerate}






\item (25 pts) Implementors of programming languages Scheme and ML
have expressed a
desire that trap conditions related to virtual memory (page fault,
write to a read-only page),
should not be handled by the operating system,
but instead by specialized routines within the run-time
support of the programming language.
What could be the reason? Provide a detailed answer.




\end{enumerate}

\end{document}

