All about Memory and Memory Management

Bvk Bhattarai
9 min readAug 13, 2020

Memory Management is the process that control and coordinate computer memory assigning portions called blocks to various running programs for optimizing overall performance of the system. Memory management is the functionality of an operating system that handles or manage primary memory and moves processes back and forth between main memory and disk during execution.Memory management one of the most important function of an operating system that manages primary memory. Memory management can be done in different ways or technique, in this research report we will be researching in memory management.

Aims and Objectives

Aims:

· To get the knowledge of memory management process of computer system, with the help of research.

Objectives:

· To get the knowledge of different memory used in the computer system.

· To perform research on various topic of memory management.

· To understand how computer system / operating system manage memory.

Hierarchy of Memory Management (Locality of reference)

Memory hierarchy is the hierarchy of memory and storage devices found in a computer system. Memory hierarchy is an enhancement to organize the memory such that it can minimize the access time. The memory hierarchy was developed based on a program behaviour known as locality of references. Memory used in the computer system is divided into five hierarchies based on the speed as well as use. It has different levels of memory with different performance rates. In computer system processor and large amount of memory of different types are used to complete the process according to the input given by the user. Generally, memory or storage is classified into two types:

v Volatile Memory: Data get erased when the power is switched off. It stores data temporary.

v Non-volatile Memory: This type of memory stores data permanently, data did not get erased when power is switched off.

The memory hierarchy designed is divided into 2 main types: -

v Primary or Internal memory: The primary memory is the main memory of the computer system which are also known as internal memory. Accessing data from primary memory is faster because it is directly accessible by the processor of the computer system. Primary memory is the volatile memory. It is expensive as compared to the secondary memory or external memory and the capacity of the primary memory is very limited and smaller as compared to the secondary memory. E.g. RAM, cache memory and CPU register

v Secondary or External memory: The secondary memory is also known as external memory and this is accessible by the processor through an input/output module. So, it is comparatively slow than primary memory but it can store large amount of data permanently. E.g. Magnetic disk, optical disk.

The characteristics of memory hierarchy is given below:

1) Capacity: The capacity refers to the amount of data or files that computer memory can store. As we move from top to button in the hierarchy / in the figure given above the capacity increases.

2) Performance: Earlier when the computer system was designed without memory hierarchy design, the speed gap increases between the CPU registers and main memory due to large difference in access time. Which result in lower performance of the system and because of this enhancement was mandatory, and this enhancement was made in the form of memory hierarchy design, due to this action performance of the system increases. One of the best ways to increase system performance is minimizing how far down the memory hierarchy one has to go to manipulate data.

3) Access time: Access time is the time interval between the read and write request and the availability of data. As we move from top to button in the hierarchy/ in the figure given above, the access time increases or we can say that more time is required to access the data.

Access time of different memory are given below: -

4) Per unit cost: Per unit cost is the amount of money that cost to the unit amount of memory. As we know that internal memory is expensive than that of secondary or external memory. So, as we move from top to button in the hierarchy per unit cost decreases.

The memory hierarchy in computers mainly includes the following types of memory and they are classified in the level we are going to discuss in the following ways:

1) CPU Registers (Level 0): Registers are at level-0 which are contained inside the CPU. As they are inside the CPU, they have least access time and they are the most expensive memory the seize of the memory is also small in size (in KB). Registers are built from fast multi-ported memory cell. Registers are normally measured by the number of bits they can hold. There are several other classes of registers too like Accumulator, General purpose registers, Special purpose registers.

2) Cache Memory (Level 1): At level-1 cache memory are present, cache memory stores the segments of those program that are frequently accessed by the processor. This memory is smaller in size and they are expensive too. They are available in MB. The cache holds the chunk of data which are frequently used from main memory. The processor can easily access the data in shorter time. Whenever the CPU requires accessing memory, it first checks the required data into the cache memory and if the data is found in the cache memory, it read from the fast memory if not found in the cache memory it moves to the main memory. Those processors which have a single core will have two or more cache levels rarely. Where as multi-core processor have three, 2-levels for each one core and one level is shared.

3) Main Memory (Level 2): At level-2, Main memory is present, Random access memory (RAM) and Read only memory (ROM) is the main memory of the computer system. This main memory can communicate directly with the CPU and with other secondary memory through input output process. This memory is fast as well as it is comparatively less expensive than cache memory and registers, they are available in few GB

Types of RAM:

o Dynamic-RAM

o Static-RAM

o Non-volatile RAM

Types of ROM:

o Programmable ROM

o Erasable PROM

o Electrically Erasable PROM

4) Magnetic Disk (Level 3): At level-3 secondary storage devices are present. The re used to store large amount of data and they are cheaper also they are available in larger in size in TB. They are not directly accessible to the CPU but they are accessed using input/output channels. So, they are not faster. That is why they are known as lowest-cost, highly-capacity and slowest-access storage in a computer system. Magnetic disk uses magnetization process to write, rewrite and access data. E.g.:- hard drives, floppy disks.

5) Optical disk/ Magnetic tape (Level 4): This storage is designed for the purpose of data backup. They can store large amount of data in peta byte range, although they can store large amount of data but they are very slow.

Advantage of memory Hierarchy are as follow: -

o Memory distributing is simple

o Memory distributing is economical

o Increases the speed of the system.

o Increase the performance of the system.

o Increase the capacity of the computer

o Removes external destruction.

Memory Allocation

Memory allocation is a process by which computer programs and services are assigned with physical or virtual memory space. Memory is required for the execution of program and process. Memory allocation is achieved through a process known as memory management. Memory allocation is managed through operating system and software applications. Program and services are assigned with a specific memory as per their requirement by the computer system or operating system when they are executed. Once the process or operation is completed or become idle the assigned memory is released and allocated to another program or merged within the primary memory.

Memory allocation are of two types, they are as follow: -

1) Static Memory Allocation: The program is allocated memory at compile time.

2) Dynamic Memory Allocation: The program is allocated with memory at run time.

First Fit: Allocate the first hole that is big enough which can accommodate the process. It finishes after finding the first suitable free partition. It scans from the beginning of ta available memory to the end, until the first free space which is at least big enough to accept data is found.

Advantage

Ø Simple.

Ø Fastest algorithm because it searches as little as possible.

Disadvantage

Ø If the data to be allocated is bigger than the biggest free space, the request cannot be met, and an error is generated.

Ø External fragmentation

Best fit: The Best fit deals with allocating the smallest free partition which meets the requirement of the requesting process. This algorithm first searches the entire list of free partitions and considers the smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed.

Advantage

Ø Memory utilization is much better than first fit because it searches the smallest free partition.

Ø Works well when most allocation are of small size.

Disadvantage

Ø It is slower, allocation as well as deallocation is slower.

Ø May tens to fill up memory with useless holes.

Worst fit: In worst fit approach is to locate largest possible free portion which is bigger than that of data or file to be store so, that the portion left after storing the data will be big enough to be useful. It is the reverse of best fit.

Advantage

Ø Production of small gaps will be reduced.

Ø Works fine if the available allocation are of medium size.

Disadvantage

Ø External fragmentation

Ø Tends to break large free blocks in such a way that large partition cannot be allocated.

Paging and Segmentation

Paging and Segmentation are both Non-contiguous memory allocation technique. Non-contagious memory allocation allocates the separate block of memory to a process. This technique has advantage of reducing memory wastage but it increases the overheads due to address translation.

Paging

Paging is one of the storage mechanisms that allows operating system used in computer to retrieve process from the secondary storage into the main memory in the form of pages. Paging allows a process to be stored in a memory in non-contagious manner which helps to solve the problem of external fragmentation. The CPU cannot directly access storage disk, so the MMU emulates memory by mapping pages to frames that are in RAM. Paging is a fixed size partitioning scheme so the secondary memory and main memory are divided into equal fixed size partitions and such partitions of secondary memory are called pages and the partitions of the main memory are called as frames. In paging, processes are divided into different parts where the size of each part is same as the size of page and the pages of process are stored in the frames of main memory according to their availability.

Advantages and disadvantages of paging are as follow: -

Advantages

Ø No external fragmentation

Ø No internal fragmentation on updated operating system.

Ø Frames do not have to be contiguous.

Ø Easy to use memory management algorithm.

Ø Swapping is easy.

Disadvantages

Ø Internal fragmentation on older system.

Ø Longer memory lookup times than segmentation.

Ø In may cause internal fragmentation

Ø Complex memory management algorithm

Ø Memory reference overhead due to multi-level paging.

Segmentation

Segmentation is also one of a memory management scheme or storage mechanism and this segmentation method also works almost similarly like paging, only difference between the segmentation and paging is that segmentation is of variable-length whereas, in paging method pages are always of fixed size. The size of partitions depends in the length of modules. Such variable size segments divided by segmentation are loaded to the logical memory address space. Each segment has its name and length. For the execution, the segments from logical memory space are loaded to the physical memory space.

Advantage and disadvantage of segmentation are as follows: -

Advantages

Ø Tables consumes less space than that of page tables.

Ø Less processing overhead

Ø Segment tables are smaller so it required less memory.

Ø No internal fragmentation

Disadvantages

Ø Due to unequal size it is not suitable for swapping.

Ø External fragmentation occurs.

Ø Require programmer intervention.

Ø Uses legacy technology in x86–64 servers.

--

--

Bvk Bhattarai

Bibek Bhattrai is currently studying bachelor in information technology and education