UNIT IV Memory Management
UNIT IV Memory Management
UNIT – IV
MEMORY MANAGEMENT
• Partitioned Allocation
• Relocatable Partitioned Memory Management
• Paged Memory Management
Introduction
• In computing, memory refers to a device that is used to store information for immediate
use in a computer or related computer hardware device.
• The memory management modules of an Operating System are concerned with the
management of primary memory.
• Primary memory we mean the memory that the processors directly access for instructions
and data.
• The term "memory" is often synonymous with the term “primary storage".
Types of Memory:
Memory is the most essential element of a computing system because without it computer can’t
perform simple tasks. Computer memory is of two basic types – Internal Memory (Primary
memory) and External Memory (Secondary memory).
• Determining allocation policy for memory. i.e. deciding to whom it should allocates, how
much, when, and where.
2. All of the remaining memory is available and allocated to the single job being processed.
• Bit map keeps track of free blocks in memory, it has one bit for one memory block, bit 0
shows that the block is free and bit 1 shows the block is allocated to some file or a process.
• If the operating system uses buffered I/O during processing, then contiguous memory
allocation can enhance processing speed.
• Improve using Multilevel page tables and variable page sizes (super-pages)
• Guarded page tables
• Page Table Length Register (PTLR) to limit virtual memory size.
• Internal fragmentation.
Fragmentation:
• Fragmentation is an unwanted problem in the operating system in which the processes are
loaded and unloaded from memory, and free memory space is fragmented. Processes
can't be assigned to memory blocks due to their small size, and the memory blocks stay
unused.
Types of Fragmentation
1. Internal Fragmentation
2. External Fragmentation
When a process is allocated to a memory block, and if the process is smaller than the amount
of memory requested, a free space is created in the given memory block. Due to this, the free
space of the memory block is unused, which causes internal fragmentation.
External fragmentation happens when a dynamic memory allocation method allocates some
memory but leaves a small amount of memory unusable. The quantity of available memory is
substantially reduced if there is too much external fragmentation. There is enough memory
space to complete a request, but it is not contiguous. It's known as external fragmentation.
• A computer can address more memory than the amount physically installed on the
system. This extra memory is actually called virtual memory.
• Similarly, main memory is divided into small fixed-sized blocks of (physical) memory
called frames.
• The size of a frame is kept the same as that of a page to have optimum utilization of the
main memory and to avoid external fragmentation.
• Page address is called logical address and represented by page number and the offset.
Logical Address = Page number + page offset
• Frame address is called physical address and represented by a frame number and
the offset. Physical Address = Frame number + page offset
• A data structure called page map table is used to keep track of the relation between a page
of a process to a frame in physical memory.
• When the system allocates a frame to any page, it translates this logical address into a
physical address and create entry into the page table to be used throughout execution of the
program.
• When a process is to be executed, its corresponding pages are loaded into any available
memory frames. When a computer runs out of RAM, the operating system (OS) will
move idle or unwanted pages of memory to secondary memory to free up RAM for other
processes and brings them back when needed by the program.
Advantages :
1. It solves the fragmentation problem without physically moving the pages in memory.
2. This allows a higher degree of multiprogramming.
3. The compaction in relocatable partitioned allocation is eliminate.
Dis-Advantages :
1. Page address mapping hardware increase the cost of the computer system.
2. Extra core or extra registers needed for page map tables.
3. There is a possibility of internal fragmentation (or) page breakage may occur.
4. Some memory will still unused if the number of available page frames are not sufficient
for the Job's page.
• In the above fig. Job address space consists of 10,000B of programs called page
and we have only 3000B of memory available. This 10,000B program run in 3000B
of memory by using demand paging.
Advantages :
1.Fragmentation is eliminated.
2.Large Virtual memory is available.
3.More efficient use of memory.
4.Demand paging is valuable in time sharing, systems.
Dis-Advantages :
1. Page address mapping hard ware increases the cost of the computer system
2.Extra memory, extra register needed for page map table.
• The page map table consists of a page number, page frame number, status and judgement
field. Initially the allocation algorithm places the first three pages of a program in the main
memory. The job starts execution in one of these pages. Suppose in page O there isa
transfer instruction to the location 9055. The hard ware mechanism uses 9 as index tothe
page lable that is page 9 is required in the execution. then the pagemap table is checked to
find whether the page in the main memory job not if the required page is not in the main
memory then the page fault occurs, then the hard ware generates interrept to
the operating system then the operating system searches the secondary storage device
for page 9 and brought into the memory by replacing one of the pages in the memory It
may use a page remove algorithms like FIFO(First in first out) LRU(Least Recently Use)
for removing a page. The decision which page has to replace it with judgement field in the
page map table. It is desirable to keep highly used pages in the memory.
• A demand paging system is quite similar to a paging system with swapping where
processes reside in secondary memory and pages are loaded only on demand, not in
advance.
• When a context switch occurs, the operating system does not copy any of the old
program’s pages out to the disk or any of the new program’s pages into the main
memory Instead, it just begins executing the new program after loading the first page
and fetches that program’s pages as they are referenced.
• While executing a program, if the program references a page which is not available in the
main memory because it was swapped out a little ago, the processor treats this invalid
memory reference as a page fault and transfers control from the program to the operating
system to demand the page back into the memory.
Advantages:
1. It eliminates fragmentation.
2. It avoids virtual memory.
3. It helps in dynamic linking.
Dis-Advantages:
1. There is a difficulty in managing segments of different sizes on secondary storage
device.
2. The maximum size of the main memory.
3. Memory compacting is required.
4. Increases the hardware cost.
Definition
Block Size
In Pagination the size of blocks is In Segmentation the size is not dependent on system
dependent on system memory and gets memory and is all up to user's choice that of what
assigned accordingly. size blocks are needed.
Performance
Data Load
In case of Pagination pages get loaded in In case of Segmentation all the sections get loaded
main memory at runtime when user at the time of compilation.
demands it.
Data Record
In case of Pagination Page map table in In case of Segmentation, Segment map table in
demand paging manages record of pages segmentation demonstrates every segment address
in memory. in the memory.