|
Memory Management in Operating System
|
|
When an operating system manages
the computer's memory, there are two broad tasks to be accomplished:
|
|
1. Each process must have enough
memory in which to execute, and it can neither run into the memory space of
another process nor be run into by another process.
2. The different types of memory in the system must be used properly so that
each process can run most effectively.
|
|
The first task requires the
operating system to set up memory boundaries for types of software and for
individual applications.
|
|
As an example, let's look at an
imaginary small system with 1 megabyte (1,000 kilobytes) of RAM. During the
boot process, the operating system of our imaginary computer is designed to
go to the top of available memory and then "back up" far enough to
meet the needs of the operating system itself. Let's say that the operating
system needs 300 kilobytes to run. Now, the operating system goes to the
bottom of the pool of RAM and starts building up with the various driver
software required to control the hardware subsystems of the computer. In our
imaginary computer, the drivers take up 200 kilobytes. So after getting the
operating system completely loaded, there are 500 kilobytes remaining for
application processes.
|
|
When applications begin to be
loaded into memory, they are loaded in block sizes determined by the
operating system. If the block size is 2 kilobytes, then every process that
is loaded will be given a chunk of memory that is a multiple of 2 kilobytes
in size. Applications will be loaded in these fixed block sizes, with the
blocks starting and ending on boundaries established by words of 4 or 8
bytes. These blocks and boundaries help to ensure that applications won't be
loaded on top of one another's space by a poorly calculated bit or two. With
that ensured, the larger question is what to do when the 500-kilobyte
application space is filled.
|
|
In most computers, it's possible
to add memory beyond the original capacity. For example, you might expand RAM
from 1 to 2 megabytes. This works fine, but tends to be relatively expensive.
It also ignores a fundamental fact of computing -- most of the information
that an application stores in memory is not being used at any given moment. A
processor can only access memory one location at a time, so the vast majority
of RAM is unused at any moment. Since disk space is cheap compared to RAM,
then moving information in RAM to hard disk can greatly expand RAM space at
no cost. This technique is called virtual memory management.
|
|
Disk storage is only one of the
memory types that must be managed by the operating system, and is the
slowest.
|
|
Ranked in order of speed, the
types of memory in a computer system are:
|
|
• High-speed cache
|
|
This is fast, relatively small
amounts of memory that are available to the CPU through the fastest
connections. Cache controllers predict which pieces of data the CPU will need
next and pull it from main memory into high-speed cache to speed up system
performance.
|
|
• Main memory
|
|
This is the RAM that you see
measured in megabytes when you buy a computer.
|
|
• Secondary memory
|
|
This is most often some sort of
rotating magnetic storage that keeps applications and data available to be
used, and serves as virtual RAM under the control of the operating
system.
|
|
The operating system must balance
the needs of the various processes with the availability of the different
types of memory, moving data in blocks (called pages) between available
memory as the schedule of processes dictates.
|
No comments:
Post a Comment