Memory Management Unit-4
Memory Management
Memory management mostly involves management of main memory. In a
multiprogramming computer, the Operating System resides in a part of the main
memory, and the rest is used by multiple processes. The task of subdividing the
memory among different processes is called Memory Management. Memory
management is a method in the operating system to manage operations between
main memory and disk during process execution. The main aim of memory
management is to achieve efficient utilization of memory.
Why Memory Management is required?
Allocate and de-allocate memory before and after process execution.
To keep track of used memory space by processes.
To minimize fragmentation issues.
To proper utilization of main memory.
To maintain data integrity while executing of process.
Memory Management Techniques
Memory management techniques are methods used by an operating system to
efficiently allocate, utilize, and manage memory resources for processes. These
techniques ensure smooth execution of programs and optimal use of system memory
Bare Machine
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 1
Memory Management Unit-4
A Bare Machine is a computer system that operates directly with its hardware. It
executes programs in machine language without the need for an operating system.
Before the development of operating system, the only drawback was that it
accepted instructions in only machine language due to which only people with
sufficient knowledge about Computer field are able to operate a computer. Hence,
after the development of the operating system, Bare machine is considered as
inefficient.
Working of Bare Machine
The processor executes machine language instructions provided by the user.
There is no abstraction between the user and the machine. Hence, the system
is highly dependent on the knowledge of machine code.
Each instruction is processed by the hardware without the help of an operating
system which results in a basic, raw computing environment.
Advantages of Bare Machine
1. Direct Control: Users can directly control the hardware without any
interference from an operating system which can be beneficial in low-level
tasks or specialized applications.
2. Efficiency in Simple Tasks: For basic, single-task operations, Bare Machines
can be faster than using an operating system as there is no overhead.
3. Low Resource Requirement: Bare Machines do not require resources or
memory needed by an operating system which makes them useful in
environments with limited resources.
Disadvantages of Bare Machine
1. Lack of User-Friendliness: Bare Machines only accept machine language.
Users must have understanding of low-level programming.
2. No Multitasking: Unlike systems with operating systems, Bare Machines
cannot handle multiple tasks simultaneously which makes them inefficient for
most general-purpose use cases.
3. Limited Scope: Bare Machines are inefficient for complex applications as
they lack the abstraction and multitasking features provided by modern
operating systems.
Resident Monitor
The Resident Monitor is program that runs on Bare Machines. The resident
monitor works like a primitive operating system that controls the instructions and
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 2
Memory Management Unit-4
performs all necessary functions such as job scheduling, memory management,
and interrupt processing.
Parts of Resident Monitor
It is divided into 4 parts as:
Control Language Interpreter: The first part of the Resident monitor is
control language interpreter which is used to read and carry out the instruction
from one level to the next level.
Loader: The second part of the Resident monitor which is the main part of the
Resident Monitor is Loader which Loads all the necessary system and
application programs into the main memory.
Device Driver: The third part of the Resident monitor is Device Driver which
is used to manage the connecting input-output devices to the system. So
basically it is the interface between the user and the system. it works as an
interface between the request and response. Request which user made, Device
driver responds that the system produces to fulfill these requests.
Interrupt Processing: The fourth part as the name suggests, it processes the
all occurred interrupt to the system.
Working of Resident Monitor
It works like job sequencer as it sequences job and sends them to the
processor.
After scheduling the job Resident monitors loads the programs one by one into
the main memory according to their sequences.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 3
Memory Management Unit-4
It controls the execution of instructions and ensures that programs are
executed without any interruption in between.
The Interrupt Processing feature allows the system to handle signals or
requests from the hardware during execution, ensuring smooth operations.
Advantages of Resident Monitor
1. Job Sequencing: The Resident Monitor handles job sequencing and memory
management.
2. Faster Execution: There is no time gap between job scheduling and
execution, making the system faster compared to manual job handling.
3. No OS Overhead: The Resident Monitor allows program execution without
the overhead of operating system, making it lighter in terms of resource
consumption.
4. Basic System Control: It provides a minimal, yet effective level of control
over hardware resources.
Disadvantages of Resident Monitor
1. Limited Functionality: The Resident Monitor provides only basic control
over the system, and lacks the extensive features of a modern operating
system.
2. No Multitasking: Like the Bare Machine, Resident Monitors cannot handle
multiple programs running simultaneously, which limits their use in more
complex environments.
3. Not Scalable: The Resident Monitor is not scalable for larger applications or
systems that require more advanced management.
4. Error Handling: As with Bare Machines, error handling is more difficult
because there is no higher-level operating system to catch and handle errors
gracefully.
Multiprogramming with fixed partitions
Multiprogramming with fixed partitions is a memory management technique where
main memory is divided into a fixed number of partitions, each of which can hold
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 4
Memory Management Unit-4
a single process. This method is straightforward to implement but can lead to
inefficiency due to internal fragmentation.
How it Works:
1. Partitioning:
The main memory is divided into a predetermined number of fixed-size
partitions. These partitions can be of equal or unequal sizes.
2. Allocation:
When a process needs memory, it's allocated to a free partition that is large
enough to hold it.
3. Waiting:
If no suitable partition is available, the process waits until one becomes free.
4. Contiguous Allocation:
Processes are allocated memory in contiguous blocks within their assigned
partition.
5. Fixed Size:
The partition sizes are fixed and cannot be changed.
Key Characteristics:
Simple Implementation: Fixed partitioning is relatively easy to implement
because the memory layout is established during system initialization.
Internal Fragmentation: Processes might not fully utilize their assigned partition,
leading to unused space within the partition (internal fragmentation).
External Fragmentation: As processes are loaded and terminated, free space can
become fragmented, making it difficult to allocate large partitions to incoming
processes.
Limited Multiprogramming: The degree of multiprogramming (the number of
processes that can be running simultaneously) is limited by the number of available
partitions.
Contiguous Allocation: Processes can only be loaded into contiguous blocks of
memory.
No Spanning: Processes cannot span multiple partitions.
Advantages:
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 5
Memory Management Unit-4
Simple to implement: fixed partitions are easy to manage.
Easy to understand: The concept is straightforward, making it easier to grasp for
beginners.
Disadvantages:
Internal Fragmentation: Unused space within partitions can lead to memory
waste.
Limited Multiprogramming: The number of concurrently running processes is
limited by the number of partitions.
External Fragmentation: Free space can become fragmented, making it difficult
to allocate memory to large processes.
Multiprogramming with fixed partitions is a simple memory management
technique that can be efficient in some scenarios, but it also has limitations related
to fragmentation and the degree of multiprogramming.
Multiprogramming with Variable partitions
Variable Partitions is a contiguous memory management technique in which the
main memory is not divided into partitions and the process is allocated a chunk of
free memory that is big enough for it to fit. The space which is left is considered
as the free space which can be further used by other processes. It also provides
the concept of compaction. In compaction the spaces that are free and the spaces
which not allocated to the process are combined and single large memory space is
made.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 6
Memory Management Unit-4
Advantages of Variable Partitioning
Efficient Memory Utilization: Memory is allocated dynamically; this means
that it can be used sparingly thus avoiding the use of much space on the
available memory.
No Process Size Limitation: One advantage of this is an absence of sharp
partitions because memory is allocated as per the processes requirements.
Higher Degree of Multi-programming: It also stated that process flexibility
for memory can be suitable for more process.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 7
Memory Management Unit-4
Disadvantages of Variable Partitioning
External Fragmentation: Any time memory space is granted and then
recalled for someone else to free, space of maximum un-utilized portions of
memory are created termed as external fragmentation leading to poor memory
utilization.
Complexity: Fixed partitioning and its related concepts are far simpler to
handle and control as compared to variable partitions and external
fragmentation.
Need for Compaction: To avoid this fragmentation, compaction is needed, in
which the free areas are grouped together to form bigger spaces in the
memory, but this takes a lot of time and consumes many resources.
Difference between Fixed Partitioning and Variable
Partitioning
Fixed Partitioning Variable Partitioning
Memory is divided into fixed-sized Memory is allocated dynamically in
partitions. varying sizes.
Only one process can be placed in A process is allocated a chunk of free
each partition. memory as needed.
Inefficient memory utilization due to More efficient memory utilization with
internal fragmentation. less internal fragmentation.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 8
Memory Management Unit-4
Fixed Partitioning Variable Partitioning
Internal and external fragmentation
Only external fragmentation occurs.
occur.
Higher degree of multi-programming due
Limited degree of multi-programming.
to flexible allocation.
Easier to implement. More complex to implement.
Restricts process size based on
No size limitation on processes.
partition size.
Paging
Paging is the process of moving parts of a program, called pages, from secondary
storage (like a hard drive) into the main memory (RAM). The main idea behind
paging is to break a program into smaller fixed-size blocks called pages.
To keep track of where each page is stored in memory, the operating system uses
a page table. This table shows the connection between the logical page numbers
(used by the program) and the physical page frames (actual locations in RAM).
The memory management unit uses the page table to convert logical addresses
into physical addresses, so the program can access the correct data in memory.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 9
Memory Management Unit-4
Important Features of Paging
Logical to physical address mapping: Paging divides a process's logical
address space into fixed-size pages. Each page maps to a frame in physical
memory, enabling flexible memory management.
Fixed page and frame size: Pages and frames have the same fixed size. This
simplifies memory management and improves system performance.
Page table entries: Each logical page is represented by a page table entry
(PTE). A PTE stores the corresponding frame number and control bits.
Number of page table entries: The page table has one entry per logical page.
Thus, its size equals the number of pages in the process's address space.
Page table stored in main memory: The page table is kept in main memory.
This can add overhead when processes are swapped in or out.
Advantages of Paging
Eliminates External Fragmentation: Paging divides memory into fixed-size
blocks (pages and frames), so processes can be loaded wherever there is free
space in memory. This prevents wasted space due to fragmentation.
Efficient Memory Utilization: Since pages can be placed in non-contiguous
memory locations, even small free spaces can be utilized, leading to better
memory allocation.
Supports Virtual Memory: Paging enables the implementation of virtual
memory, allowing processes to use more memory than physically available by
swapping pages between RAM and secondary storage.
Ease of Swapping: Individual pages can be moved between physical memory
and disk (swap space) without affecting the entire process, making swapping
faster and more efficient.
Improved Security and Isolation: Each process works within its own set of
pages, preventing one process from accessing another's memory space.
Disadvantages of Paging
Internal Fragmentation: If the size of a process is not a perfect multiple of
the page size, the unused space in the last page results in internal
fragmentation.
Increased Overhead: Maintaining the Page Table requires additional memory
and processing. For large processes, the page table can grow significantly,
consuming valuable memory resources.
Page Table Lookup Time: Accessing memory requires translating logical
addresses to physical addresses using the page table. This additional step
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 10
Memory Management Unit-4
increases memory access time, although Translation Look aside Buffers
(TLBs) can help reduces the impact.
I/O Overhead During Page Faults: When a required page is not in physical
memory (page fault), it needs to be fetched from secondary storage, causing
delays and increased I/O operations.
Complexity in Implementation: Paging requires sophisticated hardware and
software support, including the Memory Management Unit (MMU) and
algorithms for page replacement, which add complexity to the system.
Segmentation
A process is divided into Segments. The chunks that a program is divided into
which are not necessarily all of the exact sizes are called segments. Segmentation
gives the user's view of the process which paging does not provide. Here the
user's view is mapped to physical memory.
Types of Segmentation in Operating Systems
Virtual Memory Segmentation: Each process is divided into a number of
segments, but the segmentation is not done all at once. This segmentation may
or may not take place at the run time of the program.
Simple Segmentation: Each process is divided into a number of segments, all
of which are loaded into memory at run time, though not necessarily
contiguously.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 11
Memory Management Unit-4
Advantages of Segmentation in Operating System
Reduced Internal Fragmentation : Segmentation can reduce internal
fragmentation compared to fixed-size paging, as segments can be sized
according to the actual needs of a process. However, internal fragmentation
can still occur if a segment is allocated more space than it is actually used.
Segment Table consumes less space in comparison to Page table in paging.
As a complete module is loaded all at once, segmentation improves CPU
utilization.
The user's perception of physical memory is quite similar to segmentation.
Users can divide user programs into modules via segmentation. These
modules are nothing more than separate processes' codes.
The user specifies the segment size, whereas, in paging, the hardware
determines the page size.
Segmentation is a method that can be used to segregate data from security
operations.
Flexibility: Segmentation provides a higher degree of flexibility than paging.
Segments can be of variable size, and processes can be designed to have
multiple segments, allowing for more fine-grained memory allocation.
Sharing: Segmentation allows for sharing of memory segments between
processes. This can be useful for inter-process communication or for sharing
code libraries.
Protection: Segmentation provides a level of protection between segments,
preventing one process from accessing or modifying another process's
memory segment. This can help increase the security and stability of the
system.
Disadvantages of Segmentation in Operating System
External Fragmentation: As processes are loaded and removed from
memory, the free memory space is broken into little pieces, causing external
fragmentation. This is a notable difference from paging, where external
fragmentation is significantly lesser.
Overhead is associated with keeping a segment table for each activity.
Due to the need for two memory accesses, one for the segment table and the
other for main memory, access time to retrieve the instruction increases.
Fragmentation: As mentioned, segmentation can lead to external
fragmentation as memory becomes divided into smaller segments. This can
lead to wasted memory and decreased performance.
Overhead: Using a segment table can increase overhead and reduce
performance. Each segment table entry requires additional memory, and
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 12
Memory Management Unit-4
accessing the table to retrieve memory locations can increase the time needed
for memory operations.
Complexity: Segmentation can be more complex to implement and manage
than paging. In particular, managing multiple segments per process can be
challenging, and the potential for segmentation faults can increase as a result.
Paged Segmentation
Paged Segmentation is a memory management technique that divides a
process's address space into segments and then divides each segment into
pages. This allows for a flexible allocation of memory, where each segment
can have a different size, and each page can have a different size within a
segment.
Advantages of Paged Segmentation
1. No external fragmentation
2. Reduced memory requirements as no. of pages limited to segment size.
3. Page table size is smaller just like segmented paging,
4. Similar to segmented paging, the entire segment need not be swapped out.
5. Increased flexibility in memory allocation: Paged Segmentation allows for a
flexible allocation of memory, where each segment can have a different size,
and each page can have a different size within a segment.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 13
Memory Management Unit-4
Disadvantages of Paged Segmentation
1. Internal fragmentation remains a problem.
2. Hardware is complexes than segmented paging.
3. Extra level of paging at first stage adds to the delay in memory access.
4. Increased complexity in memory management: Paged Segmentation
introduces additional complexity in the memory management process, as it
requires the maintenance of multiple page tables for each segment, rather than
a single page table for the entire process's memory.
5. Increased overhead in memory access: Paged Segmentation introduces
additional overhead in memory access, as it requires multiple lookups in
multiple page tables to access a single memory location.
6. Reduced address space: Paged Segmentation can result in a reduced address
space, as some of the available memory must be reserved for the storage of the
multiple page tables.
Virtual Memory
Virtual memory is a memory management technique used by operating systems
to give the appearance of a large, continuous block of memory to applications,
even if the physical memory (RAM) is limited. It allows larger applications to run
on systems with less RAM.
The main objective of virtual memory is to support multiprogramming, The
main advantage that virtual memory provides is, a running process does not
need to be entirely in memory.
Programs can be larger than the available physical memory. Virtual Memory
provides an abstraction of main memory, eliminating concerns about storage
limitations.
A memory hierarchy, consisting of a computer system's memory and a disk,
enables a process to operate with only some portions of its address space in
RAM to allow more processes to be in memory.
Types of Virtual Memory
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 14
Memory Management Unit-4
In a computer, virtual memory is managed by the Memory Management Unit
(MMU), which is often built into the CPU. The CPU generates virtual addresses
that the MMU translates into physical addresses.
There are two main types of virtual memory:
Paging
Segmentation
Paging
Paging divides memory into small fixed-size blocks called pages. When the
computer runs out of RAM, pages that aren't currently in use are moved to the
hard drive, into an area called a swap file. The swap file acts as an extension of
RAM. When a page is needed again, it is swapped back into RAM, a process
known as page swapping. This ensures that the operating system (OS) and
applications have enough memory to run.
Segmentation
Segmentation divides virtual memory into segments of different sizes. Segments
that aren't currently needed can be moved to the hard drive. The system uses a
segment table to keep track of each segment's status, including whether it's in
memory, if it's been modified, and its physical address. Segments are mapped
into a process's address space only when needed.
Virtual Memory vs. Physical Memory
Feature Virtual Memory Physical Memory (RAM)
An abstraction that extends The actual hardware (RAM) that
Definition the available memory by stores data and instructions
using disk storage currently being used by the CPU
Location On the hard drive or SSD On the computer's motherboard
Speed Slower (due to disk I/O Faster (accessed directly by the
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 15
Memory Management Unit-4
Feature Virtual Memory Physical Memory (RAM)
operations) CPU)
Larger, limited by disk Smaller, limited by the amount of
Capacity
space RAM installed
Lower (cost of additional
Cost Higher (cost of RAM modules)
disk storage)
Data Indirect (via paging and Direct (CPU can access data
Access swapping) directly)
Non-volatile (data persists Volatile (data is lost when power is
Volatility
on disk) off)
Advantage of Virtual Memory
Many processes maintained in the main memory.
A process larger than the main memory can be executed because of
demand paging. The OS itself loads pages of a process in the main memory as
required.
It allows greater multiprogramming levels by using less of the available
(primary) memory for each process.
It has twice the capacity for addresses as main memory.
It makes it possible to run more applications at once.
Users are spared from having to add memory modules when RAM space runs
out, and applications are liberated from shared memory management.
When only a portion of a program is required for execution, speed has
increased.
Memory isolation has increased security.
It makes it possible for several larger applications to run at once.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 16
Memory Management Unit-4
Memory allocation is comparatively cheap.
It doesn't require outside fragmentation.
It is efficient to manage logical partition workloads using the CPU.
Automatic data movement is possible.
Dis-advantage of Virtual Memory
It can slow down the system performance, as data needs to be constantly
transferred between the physical memory and the hard disk.
It can increase the risk of data loss or corruption, as data can be lost if the hard
disk fails or if there is a power outage while data is being transferred to or
from the hard disk.
It can increase the complexity of the memory management system, as the
operating system needs to manage both physical and virtual memory.
Prepared by:[Mrs. Ankita Tripathi(KCNIT College of Education,Banda)] Page 17