This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.
Memory management means variety of techniques and methods that are used to store data and programs in computer memory, especially when there is not enough memory space available to satisfy all requirements at a time. It is used to make resources available to processes and threads in an effective and efficient way. Memory management refers to rules which direct physical and virtual memory for efficient and quick sharing of system resources by users and system processes.
The basic purpose of memory management is to get better output. Memory is the basic component, for every program which is to be executed it has to be first loaded into the main memory so efficiency of memory management has an impact on the efficiency on whole system. As today's computers are used for multiprogramming so memory division is required in which operating system is placed some part of memory while rest of the memory is used by multi tasks.
One user had to use machine at a time. In early times there was no operating system on computers. Programmers had to write codes to interact with computers. After that input/output control system (IOCS) made computer management easy. Users were provided with prewritten codes to manage I/O devices. It was the beginning of today's operating system.
Overlays: In contiguous memory allocation there were limit restrictions for the size of program which had to execute on a system. To overcome this problem concept of overlaying was used in which program was divided into logical sections. In this way only that portion of program would be in memory which had to be executed and programmers not had to write codes themselves. It created larger space then the real space but it also increased program complexity and cost.
Protection in a single user system: A process can destroy operating system while being interfaced. When operating system is damaged then process cannot be processed further. To ensure protection boundary registers are used. They contain memory addresses where programs are started any outside boundary access is inhibited. Programs can access Os memory only on system calls.
Single stream batch processing: early computers required proper time setup for program execution. It wasted time. By developing batch processing system jobs are grouped into batches and then they are loaded consecutively on disks. Job stream processor reads jobs one by one and defines its setup.
Fixed partition multiprogramming:
In fixed partition multi programming main memory is divided into fixed memory partitions each process which is in active state is allotted with a fixed size of memory space. Processor switches between different processes so fast that it creates the illusion of programs being processed at a time. Many boundary registers are used to protect programs from being got damaged. It requires more memory space than that of single batch processing because process sometimes require less memory space and rest of the portion of that fixed partition is wasted. It also requires assemblers, compilers and loaders because here programmers are not manually loading programs in to memory.
Variable partition multiprogramming:
Fixed partition restricts system which causes inefficient use of resources. Variable partition allows process to take only that space which is needed actually.
Characteristics of variable partitioning:
Jobs are placed where they get fit. No space is wasted because partitions are exactly of that size which is needed by the programs so no chance of internal fragmentation.
External fragmentation can occur due to holes which are present b/w partitions but there are many ways to get rid of it like coalescing (adjacent free blocks are combined to get single large block) and compaction (rearrangement of memory into single contiguous block which makes all free space available).compaction is also correlated to garbage collection.
Memory placement strategies:
Variable partition multiprogramming makes choice available for the system to allocate any memory hole for incoming process. Memory placement strategies help and decide where to put incoming program in main memory.
Three different strategies are used for memory placement
First fit strategy
Best fit strategy
Worst fit strategy
First fit strategy: system places upcoming program in first available hole which is large enough to keep that program. It takes less execution time
Best placement strategy: system places incoming program in that hole which is most suitable for the memory and holds program tightly thereby leaving least free space.
Worst fit strategy: system places incoming program in hole which leaves most large unused space. It requires the overhead of finding the worst fit hole and enables to hold a new larger program in the remaining hole.
Multiple programming with memory swapping:
Swapping: when process is inactive its not necessary to keep it in main memory.
In swapping scheme system only puts running program in main memory. In this way available memory space is maximized. When process is completed system swaps out old process and swaps in new process and it takes significant overhead. Swapping led to today's technique of paging.
Virtual memory management:
Why it is needed?
Main memory is more expensive so it is economical to use disk memory to most of the memory requirements of computer. Disk memory is permanent and not gets affected by power loss. In virtual memory management each process seems to have full memory space available because programmer is not limited by the memory space physically connected to computer.
Gives high level multiprogramming.
Programs are not constrained by size virtual memory gives very large memory addresses.
We get large imaginary memory on small physical or real memory.
Virtual memory however can slow down the performance. Hard disk works slower then system memory. Using many programs at once in less memory will cause continuous swapping which is called thrashing.
Virtual memory advantages and disadvantages:
More than once application can run at a time (multitasking).
With less memory larger applications can run.
Applications can be launched faster with the help of file mapping.
There is no need to purchase more real memory.
Applications run slow due to multitasking.
Switching b/w many programs takes more time.
Less space of hard drive for storage.
Types of addresses: two types of addresses are used in virtual memory system
Virtual addresses: those addresses which are being referenced by processes.
Physical addresses: those addresses which are available in main memory.
Memory management unit: it is a computer hardware unit .it is used to locate virtual address in to physical address whenever virtual address is being accessed by a process.
Real address space (R): it is the range of real addresses available for the process.
Virtual address space (V): it is the range of virtual addresses available for the process.
Auxiliary storage: to make virtual address larger than the real address a two level scheme is used. On level one main memory holds instructions and data which is be accessed by the processor in running time of program. On second level secondary storage hold large amount of data which can't get fit in main memory.
Dynamic address translation (DAT): it's a mechanism which converts virtual address into real address during execution of program. Programmer is not concerned with memory placement due to artificial contiguity in which contiguous address in a process's virtual address doesn't need to be contiguous in physical memory.
Implementation of virtual memory:
Block mapping is actually mapping out real address. It indicates where virtual address for a process is present on main memory. Information is divided into blocks in this way system keeps information where in main memory every virtual block is present.
When blocks are of same size each block is called as page and this memory organization is called paging. When blocks are of different sizes each block is called segment and this memory organization is called segmentation.
In paging system a virtual address is in a pair (P, d), p represents the number of pages in virtual memory on which the specific process resides while d is the alternation within the page. When page is transferred from secondary memory to main memory it places it in a block called page frame.
Each process contains its own page table. Page table shows page number and page frame number. Page table is in virtual memory as well when a specific process is running page table is in placed main memory.
Advantages and disadvantages of paging:
Advantage of paging is that for a specific process there is no need to load all pages in memory at the same time. In this way more processes can reside in main memory at the same time. It is beneficial for multitasking.
Disadvantage of paging is that it increases complexity which affects address translation process.
So a process may generate page fault because some pages lie in main memory while some lie in secondary memory a process may reference page that is not currently present at main memory.
Page table entry:
Following figure shows (PTE).
Page resident bit secondary storage address page frame number
P shows frame number and s is secondary storage address and r is page resident bit
r is 0 when no page is residing in main memory and 1 when minimum one page resides in is in main memory.
It makes memory consisting of segments which are not of equal size. Segments consist of contiguous locations and they are not placed adjacent in main memory. It contains logical information.
Segmentation is also paired as (s, d) s for segment number and d for displacement. In pure segmentation segment is transferred from secondary to main memory as a complete unit and incoming segment can be placed anywhere in the memory where there is enough space to hold it.
Advantages and disadvantages:
Each segment is independently located on memory. It is protected separately and it is independent and it can be shared between processes.
A segment can be placed anywhere in memory so it becomes difficult to find holes for it. It is also affected by external fragmentation.
Paging versus segmentation:
Paging is transparent for programmer.
There is no separate protection in paging.
There is no separate compiling in paging.
There is no share code in paging.
Segmentation allows programmer to get involve in memory allocation.
There is separate protection in segmentation.
There is separate compiling in segmentation.
There is share code in segmentation.
Segmentation gets affected by memory fragmentation