Memory Management
Original Scanned PDF – View Notes
Memory Hierarchy
- In the computer system design, memory hierarchy is an enhancement to organize the memory such that it can minimize the access time.
- The memory hierarchy was developed based on a program behaviour known as locality of reference.
- Locality of reference also known as principle of locality is the tendency of processor (CPU) to access the same set of memory locations repetitively over a short time period.
Types of Memory in Memory Hierarchy
This memory hierarchy design is divided into 2 main types:
1. Internal or Primary Memory
This is directly accessible by processor. It consists of main memory, cache memory and CPU register.
2. External or Secondary Memory
Peripheral storage devices which are accessible by the processor via I/O module. It consists of magnetic disk, magnetic tape, optical disk etc.
Uses of Memory
- Memory is the electronic holding place for the instruction and data a computer needs to reach quickly.
- Where information is stored for immediate use.
- Without it, a computer would not be able to function properly.
- We can call it a temporary storage device.
- The OS determines how much memory the program requires and allocates enough pages to hold it and its documents.
Characteristic of Memory Hierarchy
1. Capacity
It is the global volume of information memory can store. As we move from the top to bottom in the hierarchy, the storage capacity increase.
2. Access Time
It is the time interval between the read/write request and the availability of the data. As we move top to bottom in the hierarchy, the access time increase.
3. Performance
When the earlier computer system was design without memory hierarchy design, the speed gap increase between the CPU register due to large difference in access time. This result in lower performance of the system and thus enhancement was required. This enhancement was made in the form of memory hierarchy design because of which the performance of the system increase.
4. Cost Per Bit
As we move bottom to top in the hierarchy memory cost increases, i.e. internal memory is costlier than external memory.
Monoprogramming Model
- In monoprogramming, memory contains only one program at any point of time.
- When CPU is executing the program and an I/O operation is encountered, then the program goes to I/O devices; during that time CPU sits idle.
- Thus in monoprogramming CPU is not effectively used, i.e. CPU utilization is poor.
- In monoprogramming, CPU sits idle while I/O operation is performed.
Multiprogramming Model
- In multiprogramming, memory contains more than one user program.
- In this model when one user program contains I/O operations, CPU switches to the next user program. Thus CPU is made busy at all times.
- Hence, it increases CPU utilization by organizing jobs (programs).
- The OS picks one of the jobs from job pool and loads it into memory for execution. When an I/O operation is encountered in that job, CPU switches to another job and waits until the next job is executed.
Advantages of Multiprogramming
- CPU utilization is high.
- Higher job throughput.
Throughput: amount of time CPU is utilized / total time for executing the program.
Difference Between Monoprogramming Model and Multiprogramming Model
| S.N. | Monoprogramming Model | S.N. | Multiprogramming Model |
|---|---|---|---|
| 1. | 1. | ||
| 2. | 2. | ||
| 3. | 3. | ||
| 4. | 4. |
Memory Fragmentation
- Memory fragmentation is a phenomenon that occurs when memory of computer is allocated and de-allocated in a way that leaves small gaps of unused memory scattered throughout the available space.
- As memory allocated and deallocated over time, these gaps can become smaller, creating fragmentation where there may not be enough continuous memory available to satisfy a particular allocation request.
- It can occur in both physical memory (RAM) and virtual memory.
- It leads reduced system performance, increased memory usage and even crashes or other errors.
In another word, when the processes are loaded and removed from the memory, they create free space or hole in the memory and these small blocks can not be allocated to new upcoming processes and results in inefficient use of memory.
Two types of Memory fragmentation:
- Internal Fragmentation
- External Fragmentation
1. Internal Fragmentation
- Process is allocated a memory block of size more than size of the process.
- Due to this, some part of memory is left unused and this causes internal fragmentation.
Example
- Suppose fixed partitioning, i.e. memory blocks are fixed size of RAM.
- Sizes are 2MB, 4MB, 4MB, 8MB.
- Some part of RAM is occupied by OS.
- Now suppose a process P1 of size 3MB comes and it gets a memory block of size 4MB.
- So, 1MB is free in this block is wasted and this space can’t be utilized for allocating memory to some other process.
- This is called internal fragmentation.
2. External Fragmentation
- In this fragmentation, space required for process to allocate in main memory is still available.
- But, process can not be allocated because available space is not continuous.
- This is called External fragmentation.
Example
- Suppose four process P1, P2, P3 and P4 come of size 3MB, 2MB, 3MB and 4MB respectively.
- Memory sizes are 2MB, 4MB, 4MB and 8MB.
- Now, these processes get memory blocks of size 4MB, 2MB, 4MB and 8MB respectively.
- Process P1 (1MB unused) are causing internal fragmentation.
- Still available space 6MB.
- Now, let a new process of 6MB comes.
- Though we have total space of 6MB still we can not allocate this memory to process.
- This is external fragmentation.
Memory Partition
- Division of physical memory of computer into multiple sections / partitions.
- Each partition is capable of storing different types of data.
Two types of partition:
- Static partition
- Dynamic partition
1. Static Partition
- Fixed size partition scheme.
- In this technique, main memory is pre-divided into fixed partitions during boot time by OS.
- The size of each partition is fixed and can not be changed.
- Each partition is allowed to store only one process.
- Fixed the degree of multiprogramming.
- Support internal fragmentation.
- Example: IBM/360, DOS and OS/MFT (multiprogramming with fixed no. of task).
2. Dynamic Partition
- Variable size partitioning scheme.
- Using this scheme OS can create, resize and destroy partitions.
- OS decide the size of partition according to the size of process.
- Size of partition can be changed when it is assigned to any next process.
- Degree of multiprogramming is varying.
- Supports external fragmentation.
- Allocation and deallocation is complex.
- Example: IBM, OS/MFI.
Discussion
Share a helpful question, idea, or explanation with other students.