0% found this document useful (0 votes)
21 views

Memory Management

Operating System- Memory Management
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Memory Management

Operating System- Memory Management
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Memory management

Memory management is the functionality of an operating system which handles or manages


primary memory and moves processes back and forth between main memory and disk
during execution. Memory management keeps track of each and every memory location,
regardless of either it is allocated to some process or it is free. It checks how much memory
is to be allocated to processes. It decides which process will get memory at what time. It
tracks whenever some memory gets freed or unallocated and correspondingly it updates
the status.
Process address Space
1. Symbolic addresses
The addresses used in a source code. The variable names, constants, and instruction labels
are the basic elements of the symbolic address space.
2. Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative addresses.
3. Physical addresses
The loader generates these addresses at the time when a program is loaded into main
memory.
Swapping

Swapping is a mechanism in which a process can be swapped temporarily out of main


memory (or move) to secondary storage (disk) and make that memory available to other
processes. At some later time, the system swaps back the process from the secondary
storage to main memory.
Though performance is usually affected by swapping process but it helps in running
multiple and big processes in parallel and that's the reason Swapping is also known as a
technique for memory compaction.
Memory Allocation
Main memory usually has two partitions −
 Low Memory − Operating system resides in this memory.
 High Memory − User processes are held in high memory.
Operating system uses the following memory allocation mechanism.
1. Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user processes from
each other, and from changing operating-system code and data. Relocation register
contains value of smallest physical address whereas limit register contains range of logical
addresses. Each logical address must be less than the limit register.
2. Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized partitions
where each partition should contain only one process. When a partition is free, a process is
selected from the input queue and is loaded into the free partition. When the process
terminates, the partition becomes available for another process.
Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into
little pieces. It happens after sometimes that processes cannot 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 −
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 cannot be used.
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process.

Paging

A computer can address more memory than the amount physically installed on the system.
This extra memory is called virtual memory and it is a section of a hard that is set up to
emulate the computer's RAM. The paging technique plays an important role in
implementing virtual memory.
Paging is a memory management technique in which process address space is broken into
blocks of the same size called pages (size is the power of 2, between 512 bytes and 8192
bytes). The size of the process is measured in the number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory
called frames and 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.
A data structure called a 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 creates an entry into the page table to be used throughout the
execution of the program.
When a process is to be executed, its corresponding pages are loaded into any available
memory frames. Suppose you have a program of 8Kb but your memory can accommodate
only 5Kb at a given point in time, then the paging concept will come into the picture.
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.
This process continues during the whole execution of the program where the OS keeps
removing idle pages from the main memory and write them onto the secondary memory
and bring them back when required by the program.
Benefits of Paging
The benefits of Paging are:
1. In Paging, there is no need for external fragmentation.
2. In Paging, the swapping between the equal-size pages and page frames is easy.
3. Paging is a simple technique that we use for memory management.

Drawbacks of Paging
The Drawbacks of Paging are:

1. In Paging, there may be a chance of Internal Fragmentation.


2. In Paging, the Page table consumes extra memory.
3. Due to Multi-level Paging, there may be a chance of memory reference overhead.

Segmentation

Segmentation is a technique of memory management. It is just like the Paging technique


except for the fact that in segmentation, the segments are of variable length but, in Paging,
the pages are of fixed size. In segmentation, the memory is split into variable-length parts.
Each part is known as a segment. The information which is related to the segment is stored
in a table which is called a segment table.
There are two types of information stored in the segment table:
1. Limit
2. Base

Limit: – The limit is the length or size of the segment


Base: – The base is the base address of the segment.
A segment of the program comprises the utility function, data structure, and the main
function of the program for each process. The operating system preserves a segment map
table for mapping. The table consists of segment number, list of the memory blocks which
are free along with its size, and its memory location in the virtual memory or the main
memory.
The CPU generates a logical address that comprises of two parts:

1. Segment Number
2. Segment Offset

Segment Number: – Segment Number is defined as the number of bits that are needed to
represent the segment.
Segment Offset: – Segment Offset is defined as the number of bits that are needed to
represent the size of the segment.
Benefits of Segmentation
The benefits of Segmentation are:

1. Internal fragmentation is not present in the segmentation.


2. Less overhead.
3. In segmentation, the segment table size is less than the page table size.
4. In segmentation, the relocation of the segment is easier than the whole address
space.
Drawbacks of Segmentation
The drawbacks of segmentation are:

1. In segmentation, there may be a chance of external fragmentation.


2. The segmentation technique is expensive.
3. In Segmentation, it is tough to allocate memory in a contiguous manner to a
variable-sized partition.

You might also like