Managing System Resources


5
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 48 THE
part of Windows Vista that you seethe Vista desktopis just part of the operating system. Behind this inter-
face (under the hood, if you will) is the guts of the beast. Vista is more than just a pretty interface; its a robust engine
that makes all the components of your computer system run.
The Windows Vista engine works by managing the data flow to all the different pieces of hardware (including
key subsystems) of your PC. Vista manages the instructions that are fed to the central processing unit; the applications
and drivers that are stored in system memory; the external and internal devices that are connected to your computer;
and the disk drives that your computer uses to store your data. Think of Windows as a virtual traffic cop, managing
the flow of data and instructions; its all quite complex, yet Windows handles any given operation in the blink of
an eye.
Consider, for example, the simple act of clicking your mouse to open a dialog box. When you press your finger
down on that mouse button, it sends an electric signal from the mouse to your computer. That signal is translated into
a specific instruction in binary code, thanks to a small software program called a device driver, which is part of the
Windows operating system. Windows takes the instruction from the device driver, interprets what it means, and then
forwards the instruction to your computers CPU. The CPU processes the instruction, and then feeds the result back to
Windows. Windows then accesses the currently running program, which is temporarily stored in system memory,
and tells it to open the dialog box. The program does as its told, and feeds back to Windows the necessary informa-
tion about what dialog box to open, and where. Windows takes that instruction, processes it as necessary, and then
feeds the graphic information about the dialog box to a different device driverthis one for your PCs video card.
The video device driver translates Windows instruction into the appropriate electronic signal, and the dialog box
appears on your computer monitor screen. This whole process occurs in the blink of an eye.
Although this sounds rather complicated, its actually an example of a very simpleand very commonopera-
tion. Windows manages dozens, if not hundreds, of these operations every hour, all in the background, all without
you knowing whats going on behind the scenes. The operating system just does its thing, routing the proper instruc-
tions to the proper devices and systems, making sure that no one operation gets in the way of any other one. Theres
a lot of interrupting and pausing and restarting, but thats the nature of the gameand it all happens behind the
scenes, without troubling you, the user.
Its all in a days work, as far as Windows Vista is concerned.
C H A P T E R 5
M A N A G I N G S Y S T E M R E S O U R C E S
49
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 49 How Windows Manages
the CPU
PA RT 2
B A S I C O P E R AT I O N S
50
All operations that your computer undertakes are broken
down into processes that perform some individual action. In
the case of an application, such as Microsoft Word or Internet
Explorer, several processes are typically involved. The appli-
cation itself may contain one or more processes, but also
cause several other processes to begintypically for related
tasks, such as accessing the modem, activating the printer,
and so on. Your systems central processing unit (CPU) man-
ages these processes. At any given time, Windows is running
dozens of background processes to handle your systems
memory management, disk management, networking, virus
checking, and so on.
Windows is a multitasking operating system. This
means that multiple processes are run at virtually
the same time; this is how you can simultaneously
surf the Web, listen to digital music, and print a
document. Windows job is to arrange the execu-
tion of all these processes so that they seem to be
running concurrentlywhen in fact, theyre being
processed sequentially.
2
When multiple processes are running at the
same time, Windows assigns each process a
slice of the CPUs time. It starts by allotting a
certain number of CPU execution cycles to the
first process and sends that process to the CPU.
3
1
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 50 C H A P T E R 5
M A N A G I N G S Y S T E M R E S O U R C E S
51
After the specified number of cycles is up, Windows
pauses the execution of the first process. It saves whatever
the processor was doing to memory, and notes the point in
which the process was paused.
4
After the specified number of cycles
is up, Windows now pauses the
second process. It saves whatever
the processor was doing to mem-
ory and notes the point that the
process was paused.
6
Windows then moves to the second
process in line. It allots a certain
number of CPU cycles to the sec-
ond process and sends that
process to the CPU.
5
Windows now returns to the first process and
reads the saved information from memory. It
uses this information to resume the process from
the point at which it was stopped, and re-sends
the process to the CPU. This process-swapping
procedure is then repeated over and over until
both processes end.
7
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 51 How Windows Manages
Memory with SuperFetch
PA RT 2
B A S I C O P E R AT I O N S
52
When Windows first starts up, the Windows kernel (that part of the operating sys-
tem responsible for securely managing running programs) is the first item loaded
into system memory. The kernel loads at the very top of the available system mem-
ory, backing up far enough to meet the needs of the operating system. This
area of memory is called the
system space or kernel space.
After loading the kernel, Windows now moves to the
bottom of the pool of system memory and starts load-
ing the various device drivers needed to control your
computers hardware subsystems.
2
The remaining memory between the device drivers and the Windows kernel is free
for the loading of software applications. In Windows Vista, SuperFetch technology
automatically loads your most-used applications into memory when Windows first
launchesinstead of waiting for you to open the program manually. By pre-loading
a program into a memory, it starts up much quicker when you later open the pro-
gram. SuperFetch uses an intelligent prioritization scheme to understand which
programs you use most often, and it can even differentiate which programs youre
likely to use at different times.
3
1
Kernel
space
Loaded device
drives
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 52 C H A P T E R 5
M A N A G I N G S Y S T E M R E S O U R C E S
53
Each application is subdivided into smaller blocks of memory, each about 2 kilobytes in
size; each block is loaded separately, into an individual location. The blocks are sepa-
rated by small (4 or 8 byte) boundaries, which ensure that the applications wont be
loaded on top of each other by mistake.
4
The blocks for application memory are loaded into random addresses in
memory, using Address Space Layout Randomization (ASLR). This helps
prevent most remote execution attacks from malicious programs, as the
programs have no advance knowledge of which memory addresses con-
tain a specific program.
5
The location of each memory block is detailed in a
page table. The Windows memory manager function and
your computers CPU use the page table to map the location of memory blocks. After the memory manager
finds a specific page table entry, it can then locate and access that memory block in physical memory.
6
Memory
block
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 53 How Windows Manages
System Devices
PA RT 2
B A S I C O P E R AT I O N S
54
To manage all the hardware not on your PCs motherboard, Windows uses a special soft-
ware program, called a
device driver. The driver functions as a translator between the
instructions issued by Windows (and Windows applications) and the electrical signals that
run the hardware subsystems. Without device drivers, all the instructions for managing
every possible hardware device would have to be hard-coded into the Windows operating
system. Because of the driver architecture, you only need to load those drivers necessary
for the hardware on your specific computer system.
1
When a new device is added to your computer
system, Windows installs a device driver for that
item. If its a common driver, it may be included with
Windows itself; however, it may instead be included
on the devices installation CD; or it may have to be
downloaded from the manufacturers website.
2
Once installed, each driver is added to the Windows Vista
Driver Store. This component, new to Vista, is a repository of
all installed driver packages for your particular installation of Windows. The Driver Store ensures that if you need to repair
or reinstall a particular device driver, you wont need to locate and use the original installation disk; Windows will auto-
matically access the original driver stored in the Driver Store.
3
07_0789735857_CH05.qxd 12/6/06 9:38 AM Page 54 C H A P T E R 5
M A N A G I N G S Y S T E M R E S O U R C E S
55
In regular use, all installed device drivers are loaded into system mem-
ory when Windows starts up. Once loaded, the driver passes informa-
tion to Windows on which device its talking to and what that device
can do. It then become