Tuesday, September 2, 2008

Virtual Memory Management



Untitled Document






SHES2300

Tutorial 4




The key to using memory efficiently is virtual memory management. Consider both
Windows and a UNIX/Linux operating system. Compare and contrast how each implements
virtual memory. Describe how each one handles page faults, page sizes and how
it reconciles thrashing issues. Cite your sources.




Windows is Microsoft's operating system for high-end personal
and server use; it is shipped in several variants that can all be considered
the same for our purposes. All of Microsoft's operating systems since the demise
of Windows ME in 2000 have been NT-based; Windows 2000 was NT 5, and Windows
XP (current in 2003) is NT 5.1. NT is genetically descended from VMS, with which
it shares some important characteristics.



Unix (officially trademarked as UNIX®) is a computer operating
system originally developed in 1969 by a group of AT&T employees at Bell
Labs including Ken Thompson, Dennis Ritchie and Douglas Mcllroy. Today's Unix
systems are split into various branches, developed over time by AT&T as
well as various commercial vendors and non-profit organizations. Unix operating
systems are widely used in both servers and workstations. The Unix environment
and the client-server program model were essential elements in the development
of the Internet and the reshaping of computing as centered in networks rather
than in individual computers.



Virtual memory is a means of allowing our computer to act as
if it has more RAM than it really does and runs applications requiring more
memory than there is available RAM on the system. This is because the segments
of RAM are swapped out to a reserved portion of the disk and back again when
required. It happens when we load up the memory with more than it can physically
hold.



Only those parts of the program and data that are currently in active use need
to be held in physical RAM. Other parts are then held in a swap file (as it’s
called in Windows 95/98/ME: Win386.swp) or page file (in Windows NT versions
including Windows 2000 and XP: pagefile.sys). When a program tries to access
some address that is not currently in physical RAM, it generates an interrupt,
called a Page Fault.



Thrashing is a degenerate case that occurs when there is insufficient
memory at one level in the memory hierarchy to properly contain the working
set required by the upper levels of the memory hierarchy. This can result in
the overall performance of the system dropping to the speed of a lower level
in the memory hierarchy. Therefore, thrashing can quickly reduce the performance
of the system to the speed of main memory or, worse yet, the speed of the disk
drive.



Windows vs UNIX/LINUX




























Windows   UNIX/LINUX
- 2GB are kept for each process and kernel

 

- Windows divides the list of  pages into 4 lists:

  a) Modified Page List

  b) Stand-bye Page list

  c) Free Page list

  d) Zeroed Page List

 

-  Leaves too much memory free that could be cached and runs its caching
procedure at inopportune times as well as trying to swap memory out at any
and every opportunity.
Virtual memory implementation -   Usally 3GB is kept for the process and 1GB given to the
kernel

 

-  Linux divides the virtual pages into 4 lists:

   a) Active list

   b) Inactive-dirty list

   c) Inactive-clean list

   d) Free list

 

-  Uses memory like it should be used. Virtually all of the available
memory is used for both programs and disk caching. Fast changing temporary
files are written to virtual directories mounted in memory. Swap disks are
only used when needed and how aggressively those swap disks are used can
be set in a simple configuration file.

 

-  Linux supports virtual memory, that is, using a disk as an extension
of RAM so that the effective size of usable memory grows correspondingly.
The kernel will write the contents of a currently unused block of memory
to the hard disk so that the memory can be used for another purpose. When
the original contents are needed again, they are read back into memory.
-  The clock algorithm used by Windows is local.

 

-  Windows uses clustered demand paging for fetching pages, and the
clock algorithm for the page replacement.

 

-  The pages are only brought to memory when they are required. Also,
instead of bringing 1, Windows often brings a cluster of them of 1-8 pages,
depending on the current state of the system.

 

-  The  system is required to retrieve the 4 KB page containing
the address from the page file (or in the case of code possibly from the
original program file). This is a valid page fault which happens quite invisibly 
normally. Sometimes, through program or hardware error, the page is not
there either. The system then has an ‘Invalid Page Fault’ error.
This will be a fatal error if detected in a program: if it is seen within
the system itself (perhaps because a program sent it a bad request to do
something), it may manifest itself as a ‘blue screen’ failure
with a STOP code

 

-  Win 2000 uses the working set model. Minimal (min) and maximal (max)
number of pages are allocated to each process. Initially they are the same
for all processes, but they change through time according to the number
of page faults caused by the process. At page fault a new page is added
to the working set. if the working set is bigger than max, then a page of
that process is evicted first. The balance manager periodically checks the
number of free pages. If it is too low, the working set manager evicts unreferenced
pages belonging to processes with working sets above min.
Page faults -   Linux uses a Least Recently Used page aging technique to
choose pages (swapping)

 

-   Linux uses a demand paged system with no prepaging.

 

-   Paging is implemented by the kernel and the paging daemon.
The daemon periodically checks the list of free frames. If the number of
free page frames is below min free, then it initiates action to free up
pages so that there would be lotsfree available page frames.

 

-   Page replacement is done by the two-handed clock algorithm
using global page allocation. The first hand clears the reference bit. If
the second hand finds the reference bit clear,  then the page is evicted,
and the frame is included in the list of free frames. The parameters scanrate
and handspread determine the speed of page eviction.

 

-   If the paging rate is too high, then the swapper evicts some
processes that have not been used recently. It also brings in (page tables
of) processes from disk - it prefers small processes that have been waiting
for long.
Windows will expand a file that starts out too small and may shrink it
again if it is larger than necessary, so it pays to set the initial size
as large enough to handle the normal needs of your system to avoid constant
changes of size. This will give all the benefits claimed for a ‘fixed’
page file. But no restriction should be placed on its further growth. As
well as providing for contingencies, like unexpectedly opening a very large
file, in XP this potential file space can be used as a place to assign those
virtual memory pages that programs have asked for, but never brought into
use.
Page size Operating system divides its main memory into page to allow better utilization
of memory. A page is a fixed length block of main memory, that is contiguous
in both physical memory addressing and virtual memory addressing. Kernel
swap and allocates memory using pages.
There are a few ways to deal with thrashing when it occurs:

a)     Increase the amount of RAM in the system to eliminate
the cause of thrashing

b)     Reduce the amount of RAM needed by reconfiguring
the applications, removing unneeded system services (like network protocols
that aren't being used), or running fewer applications at a time

c)      Try to optimize the paging file's activity

Thrashing issue Linux implements a thrashing protection patch in Linux kernels, which
makes replacement policy responsively resolve excessive memory paging by
temporarily helping one of the active processes quickly build up its working
set. Consequently, thrashing could be eliminated at the level of page replacement,
so that load controls at a higher level, such as process suspensions/swapping
can be avoided or delayed until it is truly necessary.





Reference:

http://en.wikipedia.org/wiki/Talk:Virtual_memory

http://www.cs.montana.edu/~halla/aos/index.html

http://widefox.pbwiki.com/Memory

http://209.85.175.104/search?q=cache:5SatjDQ826AJ:www.itwire.com/index2.php%3Foption%3Dcom_content%26do_pdf%3D1%26id%3D19553+virtual+memory+-+window+-+linux&hl=en&ct=clnk&cd=112&gl=my

http://www.zeroc.com/faq/iceMemoryUsage.html

http://people.richland.edu/dkirby/172vmo.htm

http://www.linuxshowcase.org/2001/jiang.html

http://www.aumha.org/win5/a/xpvm.php



No comments: