Swapping in Memory management - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Swapping in Memory management

Share This

With timesharing systems or graphically oriented personal computers, sometimes there is not enough main memory to hold all the currently active processes, so excess processes must be kept on disk and brought in to run dynamically.

There are two general methods for managing memory that can be applied, depending on the hardware at hand. The simplest method, known as swapping, entails loading each process into memory in its entirety, letting it run for a time, and then putting it back on the disk. The other method, known as virtual memory, enables programs to function even if they only take up a small portion of the main memory.

When swapping creates multiple holes in memory, it is possible to combine them all into one big one by moving all the processes downward as far as possible. This technique is known as memory compaction. It is usually not done because it requires a lot of CPU time.

A point that is worth making concerns how much memory should be allocated for a process when it is created or swapped in. If processes are created with a fixed size that never changes, then the allocation is simple: the operating system allocates exactly what is needed, no more and no less.

The problem arises whenever a process tries to grow if, however, processes' data segments can expand, for instance, by dynamically allocating memory from a heap, as in many programming languages. 

If there is a hole close by, it can be assigned, and the process is then permitted to expand into the hole. 

The expanding process, on the other hand, will need to be transferred to a hole in memory big enough for it, or one or more processes will need to be switched out to make a big enough hole if the process is next to another process. Processes must wait or be terminated if they are unable to grow in memory and the swap area on the disk is full.

In order to avoid the overhead of moving or switching processes that can no longer fit in their assigned memory, it is probably a good idea to allocate a little extra memory whenever a process is swapped in or moved if it is anticipated that most processes would grow as they run. 

However, only the memory that is currently in use should be swapped when moving processes to disk; doing otherwise would be wasteful. 

The memory setup in the accompanying figure shows how two processes have been given space for expansion.



Happy Exploring!

No comments:

Post a Comment