Page 367 - DCAP103_Principle of operating system
P. 367
Principles of Operating Systems
Notes 256 MB are available for the process’ code and data; the upper 2 GB map onto kernel memory
in a protected way. The virtual address space is demand paged, with a fixed page size (4 KB
on the Pentium).
Figure 12.9: Virtual address space layout for three user processes. The white areas
are private per process. The shaded areas are shared among all processes
Process A Process B Process C
4GB
Nonpaged pool Nonpaged pool Nonpaged pool
Paged pool Paged pool Paged pool
A’s page tables B’s page tables C’s page tables
Stacks, data, etc Stacks, data, etc Stacks, data, etc
HAL+OS HAL+OS HAL+OS
2GB
System data System data System data
Process A’s Process B’s Process C’s
private code private code private code
and data and data and data
0
Bottom and top
64 KB are invalid
The virtual address space layout for three user processes is shown in Figure 12.9 in slightly
simplified form. The bottom and top 64 KB of each process’ virtual address space is normally
unmapped. This choice was made intentionally to help catch programming errors. Invalid pointers
are often 0 or -1, so attempts to use them on Windows 2000 will cause an immediate trap instead
of reading garbage or, worse yet, writing to an incorrect memory location. However, when old
MS-DOS programs are being run in emulation mode, they can be mapped in.
Starting at 64 KB comes the user’s private code and data. This extends up to almost 2 GB. The
last piece of the bottom 2 GB contains some system counters and timers that are shared among
all users read only. Making them visible here allows processes to access them without the
overhead of a system call.
The upper 2 GB contains the operating system, including the code, data, and the paged and
nonpaged pools (used for objects, etc.). The upper 2 GB is shared among all user processes, except
for the page tables, which are each process’ own page tables. The upper 2 GB of memory is not
writable and mostly not even readable for user-mode processes. The reason for putting it here
is that when a thread makes a system call, it traps into kernel mode and just keeps on running
in the same thread. By making the whole operating system and all of its data structures (as well
as the whole user process) visible within a thread’s address space when it enters kernel mode,
there is no need to change the memory map or flush the cache upon kernel entry. All that has
to be done is switch over to the thread’s kernel stack. The trade-off here is less private address
space per process in return for faster system calls. Large database servers already feel cramped,
which is why the 3-GB user space option is available on Advanced Server and Datacenter Server.
Each virtual page can be in one of three states: free, reserved, or committed. A free page is not
currently in use and a reference to it causes a page fault. When a process is started, all of its
pages are in free state until the program and initial data are mapped into its address space.
360 LOVELY PROFESSIONAL UNIVERSITY