Chapter Three: Memory Management
Chapter Three: Memory Management
Chapter 3
Memory Management
3.1. Introduction
- Memory is one of the most important resources of the computer system that is used to store
data and programs temporarily.
- Part of the operating system that manages memory is called the Memory Manager (MM).
- The main functions of the Memory Manager (MM) are the following:
Keeping track of which part of memory are in used and which parts are free
Allocating and de allocating memory to processes
Managing swapping between memory and disk when memory is not big enough to
hold all the processes
- A good memory manager has the following attributes
It allows all processes to run
Its memory (space used for the management activity) overhead must be reasonable
Its time overhead (time required for the management activity) is reasonable
Summary
Advantage
- Dynamic memory allocation provides better memory utilization
Disadvantage
- Management is more complex
- Includes memory compaction overhead
3.2.2. Relocation and Protection
- Multiprogramming introduces two essential problems that must be solved – relocation and
protection
A. Protection
- Programs in other processes should not be able to reference memory locations in a process
for reading or writing purposes without permission.
- A user program shouldn’t be able to address a memory area which is not in its partition
o A user process must not access any portion of the OS
o Usually a program in one process cannot branch to an instruction in another process
o Without permission, a program in one process cannot access the data area of another process.
B. Relocation
- Location of a program in main memory is unpredictable due to loading, swapping and compaction
- There are two types of addresses:
o Logical address
It is a reference to a memory location independent of the current assignment of data to memory
Logical address is generated during compilation
o Relative address
It is a particular example of logical address in which the address is expressed as a location relative
to some known part, usually the beginning of the program
Translation must be made first
o Physical/absolute address
An actual locator in the main memory
Relocation techniques
- There are two possible solutions for relocation problems – static relocation and dynamic relocation
i. Static Relocation
- When a process is first loaded, all relative memory references are replaced by an absolute address
based on the base address of the loaded process
- It can be applied for processes which are always assigned to the same partition, for instance in the
case of unequal size fixed partitions scheme with multiple process queue.
- It doesn’t solve the protection problem. A malicious program can always construct a new
instruction and jump to it.
ii. Dynamic Relocation
- When a process is assigned for running, a special processor register (base register) is loaded
with the starting address of the program and a limit register is loaded with ending address of
the partition
Limit and base registers are protected by the hardware not to be modified by user programs
- Hardware mechanisms are used for translating relative addresses to physical addresses at the
time of execution of the instructions that contains the reference.
The value in the base register is added to the relative address to produce an absolute address
- The absolute address is compared to the value in the limit/bound register
- If the address is within bounds, the instruction execution can proceed, otherwise an interrupt is
generated to the OS
- Dynamic relocation provides solution to both relocation and protection problems.
Paging vs segmentation
Segments are variable size while pages are fixed size
Segmentation requires more complicated hardware for address translation than paging
Segmentation suffers from external fragmentation whereas paging only yields a small internal
fragmentation.
3.5 working set and thrashing
The set of pages that a process is currently using is called its working set. If the entire working
set is in memory, the process will run without causing many faults until it moves into another
execution phase (e.g., the next pass of the compiler).
– WS(t,w) = {pages P such that P was referenced in the time interval (t, t-w)}
Example: Working set
If the available memory is too small to hold the entire working set, the process will cause many
page faults and run slowly. program causing page faults every few instructions is said to be
thrashing.
3.5.1 Thrashing
If a process cannot maintain its minimum required number of frames, then it must be
swapped out, freeing up frames for other processes. This is an intermediate level of
CPU scheduling.
But what about a process that can keep its minimum, but cannot keep all of the frames
that it is currently using on a regular basis? In this case it is forced to page out pages
that it will need again in the very near future, leading to large numbers of page faults.
A process that is spending more time paging than executing is said to be thrashing.
when the system spends most of its time servicing page faults, little time doing useful
work
Fig: - Thrashing