ARTICLE: Operating System- Memory Management

Operating System is system software which manages numerous software resources and computer hardware. The component of the system software holds various functions to operate on the computer system. One of them is the management of the memory. In this piece of writing, we will have a word on the memory management role.

In the management of memory, the operating system handles the primary memory as well as takes its processes back and forth. The host and the destination of the processes are the main memory and the disk. The operating system moves the processes from one place to the another during the execution. Also, keeping track of the location of the memory without considering its nature of the state. It can either be free or be allocated to some process; the operating system can check its location. In addition to keeping track of the location of every memory, it also decides which process to assign memory and at what time. It does by keeping a look at the time at which any memory of the system gets freed. It updates its status correspondingly.

Here are some basic concepts which you can learn in simple and easy words. Let us get started.

Process Address Space

Every process references code in it. The set of the logical addresses of that code is called as the process address space. The task of taking care of the mapping the logical addresses to the other physical addresses when the program is being allocated the memory completes the OS.

Symbolic addresses, relative addresses, physical addresses are the three types of addresses used in a program. These addresses become active before and after the allocation of memory.

1. Symbolic Addresses-

These are the addresses which are used in the source code. The list of the basic elements of such addresses is extensive. The elements of the symbolic address space are variable names, constants, instruction labels.

2. Relative Addresses-

The compiler of the operating system converts the symbolic addresses into the relative addresses. It happens during the time of compilation.

3. Physical Addresses-

When a program is loaded into the main memory, the physical addresses are generated. The loader is the creator of such addresses.

The compilation time of the virtual and the physical addresses is same. Also, they are same in the load time as well. The element which differentiates them is the execution time.

Logical Address Space

Logical address space is the set of all the logical addresses which a program executes.

Memory Management Unit

The mapping to the physical address from the virtual memory is one of the tasks of the MMU (memory management unit). To do this, there is a mechanism which the unit uses. This is as follows-

  • The value of the base register which the user has generated is added to every address. Moreover, at the time at which it is sent to the memory, it is treated as an offset.
  • The use program never sees the physical addresses. That is why it has to deal with the virtual addresses.

Now comes the concept of loading. We will then shift towards discussing the linking and swapping

Static vs Dynamic Loading

The user program has to choose between the two types of loading. It has to do at the time when the development of the computer program is ongoing.

Static Loading

If you want a static loading of the program, then the system sees the compilation of the computer programs. Also, they would be linked without any module dependency or leaving any external program. The job of the linker is to combine the object program with the other necessary object modules. The destination of the linking is an absolute program. These types of programs include the logical addresses. The absolute program is loaded in the into the memory to start the execution. It is done at the loading time only.

Dynamic Loading

If you have to load a program dynamically, then the program will be compiled by the compiler. In case of the modules, only the references will be provided to include the program dynamically. But, the rest of the work is done at the time of the execution of the program. In this form of loading, the disk stores the library in the relocatable form. When the program needs the dynamic routines, then they are loaded in the memory.

Static Vs Dynamic Linking

Static Linking

Under this, all the modules which are needed by the program are combined by the linker. The program needs them into a single executable program as well as to avoid the runtime dependency.

Dynamic Linking

When there is the need of dynamic linking, the requirement of linking the actual module or library with the program diminishes. In this place, the dynamic module is referenced and provided at the linking and compilation time. The examples of the libraries which work dynamically are Dynamic Link Libraries in windows and the shared objects.

Swapping

When a process is swapped from the main memory to the secondary storage or the disk, then this mechanism is called swapping. In addition to the movement of the process from one memory location to the other, it also makes the memory available to other processes. The task of swapping does not end here. It has to back the process from the secondary storage to the main memory. Yes, there is an effect of the mechanism of swapping on the performance of the computer system, but it is also helpful in the running more than one processes. The best thing is that the size of the processes does not matter here with the swapping technique. They can move in parallel. This is the reason the other name of the mechanism is the “technique of memory compaction.”

Total time of the swapping process= Time taken to move the process to a secondary disk and copying it back to the memory+ time taken to process it to regain the main memory.

Allocation of memory

There are two partitions of the main memory. These are a low memory and the high memory. In the low memory, there is the operating system. And in the other memory, there is the space for the user processes in this memory. There are further two ways in which the memory is allocated to the processes. These are the single-partition and the multiple-partition memory.

  1. Single-partition= The relocation register scheme of the memory protects the user processes from each other. In this type of allocation, another important requirement is fulfilled. It is the change of the code and the data of the operating system. The registers which relocate have the value of the smallest physical addresses. On the other hand, the limit register includes the range of the logical addresses. Remember one thing; every logical address is less than the limit register.
  2. Multiple-partition allocation= There is a division of the main memory into a substantial number of fixed-sized partitions in this type of memory allocation. In this, every partition should have only one process. There is a selection of a process from the input queue every time a partition is free. After this, it is loaded into the free partition. After the completion of the process, the partition of the memory is allocated to another process.

There are several other concepts related to the memory allocation of the computer system. These are fragmentation, paging and many more. Keep on reading.