Open In App

Working Set in Paging

Last Updated : 08 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

When pages are exchanged in and out of main memory too frequently for a process, slowing down its execution, it is called Thrashing. A process generally requires a lot of pages. But in a certain span of time, only a certain subset of these pages is used repeatedly. This is called the locality model of execution and has been widely observed. The required subset keeps changing over different periods of time.

If no. of allocated frames to a process is less than the number of pages needed for a locality, thrashing occurs. The working set model tries to avoid this condition, and hence prevents thrashing.

The Working Set Model

The working set model finds out the number of unique pages in a locality, and maintains those many frames for the process. Hence all the required pages can be in the main memory for a certain locality. This prevents thrashing and reduces page faults. As the locality changes, the number of frames allocated is also made to change.

A working set window is maintained of some x no. of pages (x is generally denoted by delta: Δ). At every instance, this window examines the past Δ references made by the process and determines the working set. The working set is the set of unique pages from these past Δ references. The working set the size of a process ‘i’ is denoted as WSSi and is used to determine the number of frames to allocate to the processi.

Summation of all WSSi is the total frames required by all processes, denoted by D. If the no. of total frames in the main memory is less than D, thrashing is inevitable for some process as it won’t have adequate frames.

Example of a working set model sampling at 3 time instances with delta = 7

Example of a working set model sampling at 3 time instances with delta = 7

If for a period T, the locality of reference is just 3 pages, then the process can be allocated 3 frames for time T, and there will be no thrashing as all currently required pages will be in the main memory. If the locality then increases to 5 pages, 2 more frames can be given to the process. If the locality decreases to 2 pages, 3 frames can be released for other processes. (Refer to figure) If WSS is greater than available frames, that process is suspended till frames are available.

Application in Pre-Paging

When a process is allowed execution only when all of its required pages/locality pages have been brought into main memory, it is called pre-paging. The working set model can enable pre-paging by using the determined working set.

FAQs on Working Set in Paging

1. What is the purpose of the working set model?

The purpose of the working set model is to decide the number of frames allocated to each process. This is done in a way that all pages of a locality needed for the process at a time can be ready in the main memory. This prevents excessive page faults and thrashing.

2. What is the main idea behind the working set model?

The main idea of the working set model is to maintain a window to examine the recent-past page references. With this, the model gets an idea of the current locality of the process. This is the working set. The number of unique pages in a working set is used to determine the no. of frames allocated to the process.

3. Is frame allocation in the working set model static or dynamic?

Frame allocation in the working set model is dynamic. If the no. of required pages in a locality of a process decreases at a certain point in time, the frames allocated to that process can be decreased as well. These frames can then be used for some other process. Alternatively, the frames can also be increased if required.

4. What happens if there are no available frames for a process?

If such a case arises for a process, then that process is suspended till frames become available. When the frames become available, the process is restarted. If the process was a high-priority process, a currently active, lower-priority process could be suspended. Its frames will be deallocated and given to the higher priority process so that it can run first.

5. What happens when the sum of the working set sizes of all processes exceeds the total no. of frames in main memory?

This clearly means that in the list of considered processes, there will be at least one process that wouldn’t get sufficient available frames/no frames at all. For such processes, the procedure of suspension/priority decision will occur, as mentioned above.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads