Monday, September 1, 2008

tutorial 4

UNIX
Aspect of difference
Windows
The virtual memory handler attempts to preserve a pool of free RAM continuously.
The precise algorithm varies between variants and versions, but in expansive
terms the handler uses three variables to control it's activity;

1) lotsfree: When the free memory pool is above lotsfree the VM handler
is idle. If it drops below the handler will begin scanning for unused pages
to place on the Free List.

2) Desfree: 'Desirable Free'. Below this point the handler will start work
in earnest applying various criteria to reclaim in use pages that (say)
have not be accessed for some time. The effort and priority of this work
increases as the free memory pool drops.

3) Minfree: Things are getting desperate if the Free memory pool reaches
this point. The system may begin thrashing and if the situation is not cleared
desperation swapping.
Implementing virtual memory
All the systems processes use virtual memory addresses which are automatically
translated to real (RAM) addresses by the hardware. Only core parts of the
operating system kernel bypass this address translation and use real memory
addresses directly. All processes running under 32 bit Windows gets virtual
memory addresses (a Virtual Address Space) going from 0 to 4,294,967,295
(2*32-1 = 4 GB), regardless of how much RAM is actually installed on the
computer.

Generally, applications use only a small fraction of the memory allocated
of private address space. The operating system only assigns RAM page frames
to virtual memory pages that are in use.

The translation between the 32 bit virtual memory address used by the code
running in a process and the 36 bit RAM address is handled routinely and
transparently by the computer hardware according to translation tables maintained
by the operating system. Any virtual memory page (32 bit address) can be
associated with any physical RAM page (36 bit address).

When the memory in use by all the presented processes exceeds the amount
of RAM available, the operating system will move pages (4 KB pieces) of
one or more virtual address spaces to the computer’s hard disk, thus
freeing that RAM frame for other purposes. In Windows systems, these “paged
out” pages are stored in one or more files called pagefile.sys in
the root of a partition
To determine the page size at run time, use the system function sysconf().


Support up to eight different page sizes, from 4kB up to 256MB.
Page sizes
To determine the page size at run time, use the system function GetSystemInfo()
from kernel32.dll.
Use signals, such as SIGSEGV, to report these error conditions to programs.
It will typically report these conditions to the user with error messages.
Page fault
Windows uses structured exception handling to report page fault-based
invalid accesses as access violation exceptions. It would report such problems
with less technical error messages.

Resources:
1) http://216.147.18.102/unixfaq/explain_vm.shtml
2) http://en.wikipedia.org/wiki/Page_fault
3) http://www.aumha.org/win5/a/xpvm.php
4) http://support.microsoft.com/kb/555223
5) http://www.aumha.org/win5/a/xpvm.php