Beruflich Dokumente
Kultur Dokumente
Main Memory:
Background
Swapping
Memory allocation:
Contiguous Memory Allocation
- Single partition allocation
- Multiple partition allocation
Non – contiguous allocation
- Paging
- Segmentation
- Segmentation with paging
Fragmentation and defragmentation
Structure of the Page table
Virtual Memory:
Background
Demand Paging
Copy-on-Write
Page Replacement
Allocation of Frames
Thrashing
UNIT – 4
Memory management
The main purpose of a computer is to execute programs.
These programs, together with the data they access, must be in main memory during
execution.
Variety of different memory units are:
1. Internal memory
- Registers
- Cache
- Main memory (RAM)
2. Secondary memory
Many memory management schemes exist, reflecting various approaches, and the effectiveness
of each algorithm depends on situation.
UNIT – 4
Memory hierarchy of the system:
Cache ( Vo )
0.5 – 25 H/W
Main Memory ( Vo )
80 – 250 O/S
User area
User area may try to access (or) write something into OS area leads to system crash.
We must ensure correct operation to protect the OS from access by user processes.
This protection must be provided by hardware and software. [ S/W is slower process]
H/W Solution:
By Using two registers
1. Base Register
Hold the smallest legal physical memory address
2. Limit Register
Specifies the size of range
UNIT – 4
If the base register holds 300040 and the limit register is 120900, then the program
can legally access all addresses from 300040 through 420939
Make sure that each process has a separate memory space and process can access
only these legal space.
UNIT – 4
Protection of memory space is accomplished by having the CPU hardware compare
every address generated in user mode with the registers.
Any attempt by a program executing in user mode to access operating-system
memory or other user’s memory results in a trap to the operating system, which
treats the attempt as a fatal error.
This scheme prevents a user program from modifying the code or data structures of
either the operating system or other users.
UNIT – 4
Address binding:
System allows the user to create user program and store it in secondary memory.
The program must be brought into memory within a process for it to be executed.
During execution of the program passes through different phases such as compilation,
loading, running etc..
Problem is that,
Where should as OS store the results of program after their execution ?
Example:
x = ( a+ b) * ( a – c )
Compute above instruction and store the result in variable x. such address given by
the user,
like x in our example are called as symbolic or logical address.
These address need to be mapped to real physical address in the memory. This
process of mapping logical address to real address in the memory is called as address
binding.
UNIT – 4
This binding addresses of instruction and data to
actual physical address may take place during:
Compile time:
If you know at compile time where the process will
reside in memory, then absolute code can be generated.
Load time:
If it is not know at compile time where the process
will reside in memory, then the compiler must
generate relocatable code.
Execution time:
If the process can be moved during its execution from
one memory segment to another, then binding must be
delayed until run time.
UNIT – 4
Two types of address:
1. Logical address
Generated by CPU also referred to as virtual address.
2. Physical address
Generated by memory unit.
The run-time mapping from virtual to physical addresses is done by a H/W device
called as memory management unit (MMU)
UNIT – 4
User program deals with logical address never sees real physical address.
MMU Memory
The set of all logical address are generated by program is referred to as logical address
space.
The set of all physical address corresponding to these logical addresses is a physical
address space
UNIT – 4
Swapping:
Swapping is a method to improve the main memory utilization.
Two challenges:
1. Os code and data are protected from changes made by the user processes.
2. Protect the user process from one another.
UNIT – 4
Single partition allocation:
OS resides in low memory, remain memory treated as single partition.
Only one process can be loaded in user space.
0
OS
500
P1
4999
Merits:
Simplicity
Demerits:
Poor utilization of memory
UNIT – 4
Multiple partition:
Fixed equal
In this memory management scheme the OS occupies the low memory and rest of memory
available for user.
Memory is divided into fixed single partition each partition can have exactly one process.
Merits:
- Simple and easy implementation.
- This scheme support multi programming.
-It require no special costly hardware.
Demerits:
- This scheme suffer from internal as well as external fragmentation.
[REFER PROBLEM]
UNIT – 4
Fixed variable
Main memory is divided into number of partitions, but the partition sizes are different length.
OS keeps the table indicating which partitions of memory are available called as hole.
Three algorithm are available:
1. First fit
Allocate the first hole that is big enough. [ Search starts from beginning of the hole]
Merits and demerits:
Usually fastest, but not always best use of memory space.
2. Best fit
Allocate the smallest hole that is big enough. [ Search entire list]
3. Worst fit
Search entire partition allocate largest hole.
Merits and demerits:
First and best better than worst in terms of speed and storage utilization. [REFER PROBLEM]
Dynamic
In this method partitions are created dynamically, So that each process loaded into partition of
exactly same size .
UNIT – 4
Fragmentation:
As processes are loaded and removed from memory, the free memory space is
broken into little pieces. It happens after sometimes that processes can not be
allocated to memory blocks considering their small size and memory blocks remains
unused. This problem is known as Fragmentation.
Fragmentation is of two types:
Internal fragmentation Memory block assigned to process is bigger. Some portion
of memory is left unused as it can not be used by another process.
UNIT – 4
External fragmentation Total memory space is enough to satisfy a request or to
reside a process in it, but it is not contiguous so it can not be used.
UNIT – 4
One solution to the problem of external fragmentation is compaction.
UNIT – 4
Another possible solution to the external-fragmentation problem is to permit the logical address space of the
processes to be noncontiguous, thus allowing a process to be allocated physical memory wherever such
memory is available.
Pages of the process are brought into the main memory only when
they are required otherwise they reside in the secondary storage.
Demerits:
Virtual memory is not easy to implement if it is used careless means leads to decrease the
performance of the system.
UNIT – 4
Demand paging: Is the application of virtual memory
Virtual memory can be implemented as a extension of paged memory scheme called as demand
paging [ Similar to swapping]
Pages are only loaded when they are demanded during program execution. Otherwise never
accessed and never loaded into main memory.
UNIT – 4
Page fault:
When the processor needs to execute a page, and if that page is not available in main
memory then the situation is called as “PAGE FAULT”.
When the page fault occurs. The page replacement will be done.
For bringing in the required page into main memory, if the space is not available in
memory then we need to remove the page from main memory for allocating the space
to the new page which needs to be executed.
In this process the page which we need to remove from the main memory is called as
“Victim page”.
For the selection of victim page in main memory different algorithms are available
called page replacement algorithm.
An algorithm having the least page fault rate will be the best one.
UNIT – 4
Some of the widely using page replacement algorithms are as follows:
Optimal algorithm
Algorithm says: Replace a page that will not be used for the longest period
of time. [it requires future knowledge of reference string]
Example two:
Reference string are:
123412512345
With 3 frames, 9 page fault
With 4 frames, 10 page fault