Lecture 28-33
Lecture 28-33
Concepts
LECTURE 28 TO 33 – MEMORY MANAGEMENT
Introduction
The main storage has been viewed as an expensive resource. As such, it has demanded the
attention of systems designers; it has been necessary to squeeze the maximum use out of
this costly resource. OS are concerned with organizing and managing main storage for
optimal use.
By storage organization we mean the manner in which the main storage is viewed.
Do we place only a single user several users in it at the same time?
If several user programs are in main storage at the same time, do we give each of them the same
amount of space, or do we divide main storage into portions, called partitions, of different sizes?
Do we partition the main storage in a rigid manner with partitions defined for extended periods of
time, or do we provide for a more dynamic partitioning allowing the computer system to adapt
quickly to changes in the needs of user jobs?
Do we require that user jobs be designed to run in a specific partition, or do we allow jobs to run
anywhere they will fit?
Do we require that each job be placed in one contiguous block of storage locations, or do we allow
jobs to be parceled up into separate and placed in any available slots in main storage?
Systems have been built implementing each of these schemes.
Storage Management
Main memory
Should store currently needed program instructions and data only
Secondary storage
Stores data and programs that are not actively needed
Cache memory
Extremely high speed
Usually located on processor itself
Most-commonly-used data copied to cache for faster access
Small amount of cache still effective for boosting performance
Due to temporal locality
Storage Hierarchy
Programs and data need to be in main storage in order to be executed or referenced. Programs
or data not needed immediately may be kept on secondary storage. Main storage is generally
accessed much faster than secondary storage.
In systems with several levels of storage, a great deal of shuttling goes on in which programs
and data are move back and forth between the various levels. This shuttling consumes systems
resources such as CPU time.
In the 1960s it became clear that the storage hierarchy could be extended by one more level
with dramatic improvements in performance and utilization. This additional level, the cache, is a
high-speed storage that is much faster than the main storage. Cache storage is extremely
expensive compared with main storage and therefore only relatively small caches are used. The
following figure shows the relationship between cache, primary storage, and secondary storage.
Cache storage imposes one more level of shuttling on the system. Programs in the main storage
are shuttled to very high-speed cache before being executed. In the cache, they may be
executed much faster than in main storage. The hope of designers using the cache concept is
that the overhead involved in shuttling programs back and forth will be much smaller than the
performance increase obtained by the faster execution possible in the cache.
STORAGE MANAGEMENT STRATEGIES
Fetch strategies are concerned with when to obtain the next piece of
programs or data for insertion into main storage.
Demand Fetch in which the next piece of program or data is brought in to the main
storage when it is referenced by a running program.
+ Easy to implement
- Process is un-runnable until block is brought into memory
Anticipatory Fetching in which OS predicts what blocks a process is likely to refer
to and brings it in memory before it is referenced
+ Process doesn't always need to be suspended that is If 100% correct, process would never
be suspended, an OS would give impression of infinite memory
- Behavior of process is unpredictable, so OS could pre-load redundant blocks
Placement and Replacement
Strategies
Internal fragmentation
Process does not take up entire partition, wasting memory
Storage fragmentation occurs in every computer system regardless of its
storage organization. In fixed partition multiprogramming systems,
fragmentation occurs either because user jobs don’t completely fill their
designated partitions or when a partition remains unused if it is too small to
hold a waiting job.
Potential for processes to be too big to fit anywhere
Contd.
Coalescing Holes
Combine adjacent free blocks into one
large block
Often not enough to reclaim
significant amount of memory
Compaction
Sometimes called garbage collection (not
to be confused with GC in object-oriented
languages)
Rearranges memory into a single
contiguous block free space and a single
contiguous block of occupied space
Makes all free space available
Significant overhead
Compaction Drawbacks
It consumes system resources that could otherwise be used productively.
The system must stop everything while it performs the compaction. This can
result in erratic response times for interactive users and could be devastating in
real-time systems.
Compaction involves relocating the jobs that are in storage. This means that
relocation information, must now be maintained in readily accessible form.
With a normal, rapidly changing job mix, it is necessary to compact frequently.
The consumed system resources might not justify the benefits from compacting.
Memory Placement Strategies
When program loaded into memory the actual (absolute) memory locations
are determined
A process may occupy different partitions which means different absolute
memory locations during execution as a result of may be
Swapping or
Compaction
Hence, there must be an abstraction of addresses that is independent of
main memory (i-e. Logical Addresses)
Addresses
Logical
Reference to a memory location independent of the current assignment of data to
memory.
Relative
Address expressed as a location relative to some known point.
Physical or Absolute
The absolute address or actual location in main memory.
A translation must be made from both Logical and Relative addresses to arrive
at the Absolute address
MMU – Memory Management Unit is a hardware component responsible
for translating logical/relative address to physical address
Address Translation in Contiguous
Allocation Schemes
Base register
Starting address for the process
Bounds/Limit register
Ending location of the process
These values are set when the process is
loaded or when the process is swapped in
The value of the base register is added to a
relative address to produce an absolute
address
The resulting address is compared with the
value in the bounds register
If the address is not within bounds, an
interrupt (trap) is generated to the operating
system
Simple Paging
Partition memory into small equal fixed-size chunks and divide each
process into the same size chunks
The chunks of a process are called pages
The chunks of memory are called frames
Can suffer from internal fragmentation but its is comparatively very less
from that caused by fixed partition scheme as page size and frame size
is relatively very small.
Simple Paging
A.0
A.1
A.2
A.3
D.0
B.0
D.1
B.1
D.2
B.2
C.0
C.1
C.2
C.3
D.3
D.4
Page Table
Paging – Address Translation
Operating would make a segment table for each process and a list of
free blocks of main memory. Each segment table entry would have to
give
the starting address in main memory of the corresponding segment.
the length of the segment, to assure that invalid addresses are not used.
Segmentation – Address Translation
s – Segment Number
d – Offset
Logical Address = <s,d>
Offset(d) is compared with the limit/size in
the segment table
If it is less than the limit then base
corresponding to the segment number
and offset(d) are added to calculate
physical address otherwise an interrupt is
generated to show that the address trying
to be accesses belongs to another
segment
Physical Address = Base + d
Protection and sharing