Lecture 27: OS II – Systems Tools and Virtual memory
Objectives of this lecture
q Learn some of the utility tools provided by operating
systems
q Learn how OS handle programs that are larger than RAM
–Virtual memory
Systems tools
q Most OS offer tools to help in application
development, some of these are discussed below:
q Text Editors: These are utility program that are used to
create and edit textual documents such as programs source code. e.g. edit in MSDOS and vi in UNIX.
q Debugger:
This is a utility for finding logical errors in programs.
They allow programmers to execute programs in steps (stop at intervals)
and allow values of variables to be visualized.
q The programmer can choose the points at which the
program should stop by specifying break points or he can choose to stop after executing each
statement – single-step.
q Assembler, Compilers and Interpreters: Many OS also provide facility for translating
programs from source code to machine language (object code). For example, MSDOS provides Quick Basic interpreter and most UNIX systems provide a C compiler.
q An Assembler converts an assembly language code into
object code.
q A compiler also converts a source code from a
high-level programming language into an object code after checking for syntax errors.
q An interpreter is however different in that it does
not produce an object code. It simply
translates and executes statements in sequence. Thus, if there is any error,
only the current statement needs
to be corrected and re-translated. With
compilers, if there is any error, the entire process has to be repeated from
the beginning.
q Linkers and Loaders: After compiling an object
code, it has to be liked with other modules (such as I/O modules) from the
system library for the program to be complete.
Thus a linker generates an integrated executable program, called the load module.
q The loading of a program into memory is done by
another utility program called the loader.
Virtual Memory
q Programs are often too large to fit into the primary
memory.
q To solve this problem, computer scientist came up with
the idea of virtual memory – where part of the
storage on the secondary memory (hard disk) is considered as part of the main
memory (RAM).
q The actual memory required by a program -- logical memory, is considered to be
independent of the physical memory of the computer.
q The following explains how OS implements this idea:
Ø
Let the physical memory be of size M.
Ø
M is partitioned into r equal parts
each of size M/r.
Ø
Each of these partitions
is called a page frame.
Ø
Let the logical Memory be L.
Ø
L is portioned into p equal parts each
of size s=M/r.
Ø
Each of these partitions
is called a page.
q Notice that page frames and pages must be of the same
size.
q Parts of the pages that cannot fit into the physical
memory are placed on the virtual memory.
q As the program executes, and more page frames become
available, the pages are swapped into page frames. This process is called paging.
Example:
Suppose the physical
memory of a computer is 256KB and is partitioned into 8 page frames. If the logical memory required by a program
is 5MB, what is the number of pages needed in the virtual memory.
q Solution:
page
size, s = M/p = 256KB/8 = 32KB
therefore,
number of pages, p = L/s
= 5MB / 32KB
= 5 * 2^10KB / 2^5KB
= 5 * 2^5
= 5 * 32
= 160.
Thus,
160 pages are needed in the virtual memory.
Page Table
q When a program is using virtual memory, the system
keep tracks of which part is in memory and which part is in virtual memory
through the page table.
q The table consists of at least three columns as shown
below:
frame reference
|
page address
|
page frame address
|
1
|
|
|
0
|
|
|
1
|
|
|
0
|
|
|
q The frame reference is a single bit flag indicating whether the page is
in memory (1) on in virtual memory (0).
The page address is the location of the
page if it is on the disk and the page frame address is the location of the
page if it has been transferred to memory.
q At least one page is loaded into a page frame before
the execution begins.
q When the program demands access to the address of an
instruction, the system first checks if it is in a page frame, if it is not, an
OS interrupt called page fault occurs. This
forces the OS to search for the next logical page and put it into a page frame.
Thrashing:
q Virtual memory presents the problem of thrashing – high paging activity, which reduces the speed of a
program.
q If the size of a page is small, too many page faults can
result which cause thrashing.
q On the other hand, if the size of a page is too big,
it can result in waste of memory. For
example, if a page is 32KB, a 3KB program has to be stored in 32KB, wasting 29KB. However, if
the size of a page is 4KB, then only 1KB is wasted.
q Designers of OS often have to tradeoff between these
two factors.
q The greatest problem of thrashing is under-use of the CPU as it remains idle waiting for pages to be
transferred into page frames.