Memory Management in UNIX

Unix related systems usually uses very sophisticated memory management algorithms to give an efficient use of memory resources. This create questions “How much memory do we have?” and “How much memory is being used?” This question is answered in this post. Here we have tried to made available Some Questions and Answers on Memory Management in UNIX explaining Swapping and Paging, Kernel in Unix System, Fork and Expansion Swap so that students are able to understand the topic in a better way. It will also help for the exam and interviews preparations.

UNIX Memory Management Questions and Answers

1.(a) What is the difference between Swapping and Paging?

Unix Memory Management

Answer:Swapping: Here the whole process is moved from the swap device to the main memory for execution. Process size should be less than or equal to the available main memory. It is easier to implement and overhead to the system. Swapping systems can not handle the memory more flexibly as the paging systems does.

Paging: In this system only the required memory pages are moved to main memory from the swap device for execution. Here the size of Process does not matter. It gives the virtual memory concept. It also provides greater flexibility in mapping the virtual address space to the physical memory of the machine. It allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than of the available physical memory. Demand paging systems can handle the memory more flexibly.

(b) What is major difference between the Historic Unix and the new BSD release of Unix System V in terms of Memory Management?

Answer: Historic Unix uses Swapping system. Here the entire process from the swap device is transferred to the main memory, whereas the Unix System V uses Demand Paging – only the part of the process is moved to the main memory. Historic Unix usually uses one Swap Device and Unix System V allow multiple Swap Devices.

(c) What is the main goal of the Memory Management?

It always decides which process should reside in the main memory,

It Manages the parts of the virtual address space of a process which is non-core resident,

It Monitors the available main memory and periodically write the processes into the swap device for providing more processes fit in the main memory simultaneously.

(d) What is a Map?

Answer: A Map is an Array, which includes the addresses of the free space in the swap device which are allocatable resources, and the number of the resource units is available there.

Address Units 1 10,000

This allows First-Fit allocation of contiguous blocks of a resource. Initially the Map contains one entry – address and the total number of resources.Kernel treats each unit of Map as a group of disk blocks. On the allocation and freeing of the resources Kernel updates the Map for accurate information.

(e) What scheme does the Kernel in Unix System V follow while choosing a swap device among the multiple swap devices?

Answer:Round Robin scheme is followed by kernel for choosing a swap device among the multiple swap devices in Unix System V.

(f) What is a Region?

Answer: A Region is a continuous area of a process’s address space . The kernel in a “Region Table” i.e local to the process maintains region. Regions are usually sharable among the process.

(g) What are the events done by the Kernel after a process is being swapped out from the main memory?

Answer: When Kernel swaps the process out of the primary memory, it performs the according the following :

Reference Count of each region of the process is decrements by Kernel . If the it becomes zero, swaps the region out of the main memory,

Kernel also allocates the space for the swapping process in the swap device,

Kernel also locks the other swapping process while the current swapping operation is going on,

In the region table the Kernel saves the swap address of the region.

(h) Is the Process before and after the swap are the same? Give reason.

Answer: Process before swapping is remains in the primary memory in its original form. The regions may not be occupied fully by the process, there also may be few empty slots in any of the regions & while swapping Kernel do not bother about the empty slots while swapping the process out.

After swapping the process remains in the swap device. The regions swapped out must be present but only the occupied region slots but the empty slots that were present before assigning are not. While in swapping condition the process once into the main memory, the Kernel referring to the Process Memory Map, it usually assigns the main memory accordingly taking care of the empty slots in the regions.

(i) What do you mean by u-area (user area) or u-block?

Answer:u-area contains the private data that is manipulated by the Kernel only. This is local to the Process, that is each process is allocated a u-area.

(j) What are the entities that are swapped out of the main memory while swapping the process out of the main memory?

Answer:All memory space occupied by the process, process’s u-area, and Kernel stack are theoretically swapped out,.If the process’s u-area contains the Address Translation Tables for the process then Kernel implementations will not swap the u-area.

2. What is Fork swap?

Answer:It is a system call which create a child process. When “fork()” system call is called by the parent process , the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. When the memory will be available the child process must be swapped into the main memory.

3. What is Expansion swap?

Answer: At the time when any process requires more memory than it is currently allocated, the expansion swap is performed by Kernel . for doing this Kernel reserves enough space in the swap device. Then the address interpretation mapping is adjusted for the new virtual address space but the physical memory is not allocated. At the end Kernel swaps the process into the assigned space in the swap device.And later on when the Kernel swaps the process into the main memory this assigns memory according to new address translation mapping.

4. How the Swapper works?

Answer:It is the only process that swaps the processes. The Swapper operates only in the Kernel mode and it usually not uses System calls instead it uses internal Kernel functions for swapping. It is the archetype for all kernel process.

5. What are the processes that are not bothered by the swapper? Give Reason.

Zombie process which do not take any up physical memory.

Processes locked in memories are updating the region of the process.

Kernel rather than the ‘ready-to-run’ processes swaps only the sleeping processes , as they have the higher probability of being scheduled than the Sleeping processes.

6. What are the requirements for a swapper to work?

Answer:The swapper works on the highest scheduling priority. Initially it will look for any sleeping process, if not found then it will look for the ready-to-run process for swapping. But the major requirement for the swapper to work the ready-to-run process must be core-resident for at least 2 seconds before swapping out. And for swapping in the process must have been resided in the swap device for at least 2 seconds. If the requirement is not fulfilled then the swapper will go into the wait state on that event and it is awaken once in a second by the Kernel.

7. What are the criteria for choosing a process for swapping into memory from the swap device?

Answer:The time of resident the processes in the swap device, the processes priority & the amount of time the processes had been swapped out.

8. What are the criteria for choosing a process for swapping out of the memory to the swap device?

The process’s memory resident time,

The Priority of the process and

Nice value.

9. What do you mean by nice value?

Answer: It is the value that controls the priority of the process. This value that is returned by the nice()is called by system . The equation for using nice value is:Priority = (base- priority) + (“recent CPU usage”/constant) + (nice value) Only the nice value can supply by the administrator.

10. What are states that the page can be in, after causing a page fault?