Memory Virtualization


ADDRESS SPACE:

An address space is a range of valid addresses in memory that are available for a program or process. That is, it is the memory that a program or process can access. The memory can be either physical or virtual and is used for executing instructions and storing data.

ADDRESS TRANSLATION:

What is the address translation scheme in os?

In order to translate a logical address into a physical address, the system allocates a frame to each page and creates an entry in the page table to be used throughout the program’s execution.

What is the address translation mechanism?

Each memory access (e.g., memory access) is transformed by address translation. In the case of an instruction that fetches, loads, or stores information, the address provided by the instruction is changed to a physical address where the desired information is actually located.

Why does os need Address Translation?

In addition to this extra address space, the kernel can allocate far more memory than it can handle, and it can swap pages between applications that aren’t running. Memory fragmentation is prevented by virtual address translation. A program that allocates and deallocates large objects, such as a memory page, would be similar to this.

What is Address Translation in virtual memory?

A virtual address translation is a process of finding out which physical page corresponds to which virtual page. We only deal with the page number when we translate a virtual address into a physical address.

What is Address translation in paging?

In user mode, logical addresses are generated by the machine. Physical addresses are translated into these addresses by the paging hardware. The Page Table is used to translate addresses.

How Address Translation happens in segmentation?

A two-dimensional logical address is translated into a one-dimensional physical address. Segment number (s): Number of bits needed to represent a segment in the address generated by the CPU. The segment offset (d) is the number of bits needed to represent the segment’s size.

What is address translation in memory?

When workloads access data in memory, they need to know the physical memory address that matches the virtual address in order to translate it. Memory translations or mappings are what we call them. A page table is used to map virtual memory addresses to physical memory addresses.

What do you understand by address translation?

An address translation (AT) method is used to identify devices over the Internet by manipulating the IP addresses. In this way, private IP addresses within networks are mapped to public addresses that are routed over the Internet.

What do you mean by page translation mechanism?

Physical addresses are translated from protected linear addresses into segmentation units through the paging mechanism. This translation scheme can be seen in the figure below. Memory management and protection are both provided by segmentation. A descriptor is an 8-byte data structure that stores all information about segments.

Why does os need to address translation logical address to physical address conversion?

However, if we increase the size of memory, the access time will also increase, and, as we know, the CPU always generates addresses for secondary memory, i.e., the memory that is larger. A logical address is one that is not arbitrary. In order to access the main memory, we need to translate the logical address into a physical address, so we need Address translation.

SEGMENTATION:

In Operating Systems, Segmentation is a memory management technique in which the memory is divided into variable size parts. Each part is known as a segment that can be allocated to a process.

The details about each segment are stored in a table called a segment table. The segment table is stored in one (or many) of the segments.

The segment table contains mainly two pieces of information about the segment:

1. Base: It is the base address of the segment
2. Limit: It is the length of the segment.


Translation of logical address into a physical address by segmentation table:

CPU generates a logical address that contains two parts:

1. Segment Number
2. Offset

Example:

Suppose a 16 bit address is used with 4 bits for the segment number and 12 bits for the segment offset so the maximum segment size is 4096 and the maximum number of segments that can be refereed is 16.

When a program is loaded into memory, the segmentation system tries to locate space that is large enough to hold the first segment of the process, space information is obtained from the free list maintained by memory manager. Then it tries to locate space for other segments. Once adequate space is located for all the segments, it loads them into their respective areas.

The operating system also generates a segment map table for each program.


With the help of segment map tables and hardware assistance, the operating system can easily translate a logical address into a physical address during the execution of a program.

The Segment number is mapped to the segment table. The limit of the respective segment is compared with the offset. If the offset is less than the limit then the address is valid otherwise it throws an error as the address is invalid.

In the case of valid addresses, the base address of the segment is added to the offset to get the physical address of the actual word in the main memory.

The above figure shows how to address translation is done in case of segmentation.

Advantages of segmentation:

  1. No internal fragmentation
  2. Average Segment Size is larger than the actual page size.
  3. Less overhead
  4. It is easier to relocate segments than entire address space.
  5. The segment table is of lesser size as compared to the page table in paging.

Disadvantages of segmentation:

  1. It can have external fragmentation.
  2. it is difficult to allocate contiguous memory to variable sized partition.
  3. Costly memory management algorithms.

FREE SPACE MANAGEMENT IN OS

The system keeps tracks of the free disk blocks for allocating space to files when they are created. Also, to reuse the space released from deleting the files, free space management becomes crucial. The system maintains a free space list which keeps track of the disk blocks that are not allocated to some file or directory. The free space list can be implemented mainly as:

1. Bitmap or Bit vector :

A Bitmap or Bit Vector is series or collection of bits where each bit corresponds to a disk block. The bit can take two values: 0 and 1: 0 indicates that the block is allocated and 1 indicates a free block.
The given instance of disk blocks on the disk in Figure 1 (where green blocks are allocated) can be represented by a bitmap of 16 bits as: 0000111000000110.
FIGURE - 1    

Advantages:

  • Simple to understand.
  • Finding the first free block is efficient. It requires scanning the words (a group of 8 bits) in a bitmap for a non-zero word. (A 0-valued word has all bits 0). The first free block is then found by scanning for the first 1 bit in the non-zero word.
The block number can be calculated as:
(number of bits per word) *(number of 0-values words) + offset of bit first bit 1 in the non-zero word.

For the Figure-1, we scan the bitmap sequentially for the first non-zero word.
The first group of 8 bits (00001110) constitutes a non-zero word since all bits are not 0. After the non-0 word is found, we look for the first 1 bit. This is the 5th bit of the non-zero word. So, offset = 5.
Therefore, the first free block number = 8*0+5 = 5.

2.Linked List:

In this approach, the free disk blocks are linked together i.e. a free block contains a pointer to the next free block. The block number of the very first disk block is stored at a separate location on disk and is also cached in memory.
              FIGURE - 2
In Figure-2, the free space list head points to Block 5 which points to Block 6, the next free block and so on. The last free block would contain a null pointer indicating the end of free list.
A drawback of this method is the I/O required for free space list traversal.

3. Grouping:

This approach stores the address of the free blocks in the first free block. The first free block stores the address of some, say n free blocks. Out of these n blocks, the first n-1 blocks are actually free and the last block contains the address of next free n blocks.
An advantage of this approach is that the addresses of a group of free disk blocks can be found easily.

4. Counting:

This approach stores the address of the first free disk block and a number n of free contiguous disk blocks that follow the first block.

Every entry in the list would contain:
1. Address of first free disk block
2. A number n

For example, in Figure-1, the first entry of the free space list would be: ([Address of Block 5], 2), because 2 contiguous free blocks follow block 5.