GeekInterview.com
Series: Subject: Topic:
Question: 585 of 589

What is page thrashing?

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk space to simulate RAM (random-access memory). In the 80386 and higher Intel CPU chips, and in most other modern microprocessors (such as the Motorola 68030, Sparc, and Power PC), exists a piece of hardware called the Memory Management Unit, or MMU. The MMU treats memory as if it were composed of a series of pages. A page of memory is a block of contiguous bytes of a certain size, usually 4096 or 8192 bytes. The operating system sets up and maintains a table for each running program called the Process Memory Map, or PMM. This is a table of all the pages of memory that program can access and where each is really located. Every time your program accesses any portion of memory, the address (called a virtual address) is processed by the MMU. The MMU looks in the PMM to find out where the memory is really located (called the physical address). The physical address can be any location in memory or on disk that the operating system has assigned for it. If the location the program wants to access is on disk, the page containing it must be read from disk into memory, and the PMM must be updated to reflect this action (this is called a page fault).   Because accessing the disk is so much slower than accessing RAM, the operating system tries to keep as much of the virtual memory as possible in RAM. If youre running a large enough program (or several small programs at once), there might not be enough RAM to hold all the memory used by the programs, so some of it must be moved out of RAM and onto disk (this action is called paging out). The operating system tries to guess which areas of memory arent likely to be used for a while (usually based on how the memory has been used in the past). If it guesses wrong, or if your programs are accessing lots of memory in lots of places, many page faults will occur in order to read in the pages that were paged out. Because all of RAM is being used, for each page read in to be accessed, another page must be paged out. This can lead to more page faults, because now a different page of memory has been moved to disk. The problem of many page faults occurring in a short time, called page thrashing, can drastically cut the performance of a system. Programs that frequently access many widely separated locations in memory are more likely to cause page thrashing on a system. So is running many small programs that all continue to run even when you are not actively using them. To reduce page thrashing, you can run fewer programs simultaneously. Or you can try changing the way a large program works to maximize the capability of the operating system to guess which pages wont be needed. You can achieve this effect by caching values or changing lookup algorithms in large data structures, or sometimes by changing to a memory allocation library which provides an implementation of malloc() that allocates memory more efficiently. Finally, you might consider adding more RAM to the system to reduce the need to page out.
Asked by: Interview Candidate | Asked on: Mar 6th, 2005
Showing Answers 1 - 10 of 10 Answers
arnabganguly

Answered On : Mar 26th, 2007

Just ! A  wonderful Explaination

  
Login to rate this answer.

"Programs that frequently access many widely separated locations in memory are more likely to cause page thrashing on a system. "   why ???

"So is running many small programs that all continue to run even when you are not actively using them""  why??

thank you :)

  
Login to rate this answer.
tigersasi

Answered On : May 11th, 2008

View all answers by tigersasi

this explanation is more than enough

  
Login to rate this answer.

I have some doubts.

1) As you said the page size is generally 4KB or 8KB. What factors decides the page size? Is it the kernal or what?

2) As per I understand the total RAM available is called the physical memory, and the memory which you map to your disk (Hard disk etc..) is called the virtual memory.

But you said that all the memory address that is refered by the process is called the virtual memory, and when PMM maps that address to actual address (RAM, HDD) its called physical address.

Please clarify

Yes  1 User has rated as useful.
  
Login to rate this answer.
nimishthakkar

Answered On : Sep 10th, 2008

View all answers by nimishthakkar

Excessive page fault is called thrashing. CPU spend most of the time in page fault related activity than the useful work.

Yes  1 User has rated as useful.
  
Login to rate this answer.
nimishthakkar

Answered On : Sep 10th, 2008

View all answers by nimishthakkar

Page size you have to choose as per the requirement. If you choose page size big then processing of page fault takes more time but if you choose page size small then there is possibility that more number of page fault occures but processing time of page fault will reduce.

During each page fault you need to bring complete page from VM to PM and transfer time will be more if page size is big.


I hope this will make picture little bit clear.

Yes  1 User has rated as useful.
  
Login to rate this answer.
crimola

Answered On : Jan 8th, 2009

View all answers by crimola

I believe this can be described in a simpler and more complete form:

1) Understand what Virtual Memory is - it is functionality implemented by the running OS (Linux, Windows, Mainframe OS, etc) to make a system appear to have more real memory than it does.

2) The granularity is normally applied at the process/task level.

3) VMem requires an MMU - Memory Managemen Unit.

4) Each process is assigned a given amount of VMem, for example 5 processes can be assigned 1GB of memory each (adding up to 5GB) while the actual system only has 1GB of REAL memory.

5) Each processed is assigned a Page Table (or a Segment Table and multiple Page Tables in more complex systems). The Page table defines which Chunks of memory (usually 4K/8K) belonging to that process are actually residing in Real memory at any given moment. The rest of the memory has been "Paged Out" which means save to disk.

6) It is possible for an idle process to completely Paged Out. In that case, that process is not consuming any memory or processor time at all. An active process will usually have its most active Pages (the ones it is reading and writting from) in Real Memory. When it accesses those pages, no "Paging" is required.

7) Paging occurs when the process tries to access a memory address that is in a Page that has been paged out to disk and is not currently in Real memory. This results in an interrupt (a Page Fault interrupt) that the OS passes to one of its components - The Page Manager (PM) to handle. The Page Manager, keeps track of where the corresponding Page is on disk and reads it out to Real memory as well as it updates the Page Table to indicate the page is now in memory. This all transparent to the process - it resumes execution and is able to store/read from the corresponding page.

8) A phenomenom can occurr when there are multiple processes running that forces the OS to perform much process switching and paging in and out process pages.

9! When the OS reaches the point that it is using more processor time Paging (In and Out) rather than allowing processes to complete their task we have reached the point of *Page Trashing*

I hope this is of help.. or write to crimola AT gmail DOT com for more info.

Carlos

Yes  2 Users have rated as useful.
  
Login to rate this answer.
crimola

Answered On : Jan 8th, 2009

View all answers by crimola

First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):

Page Thrashing only comes about when you use Virtual Memory which requires an MMU and "fools" a process into believing that it has memory available than actual Real Memory.  However. it requires Page Management and an OS that brings needed (accessed) pages from Disk to Memory On Demand (when the process accesses a memory address that is currently on disk, it must be read from disk to real memory an *mapped* to that process's memory address space.  *Page Trashing* occurs when the OS's Page Manager (or let's just say the OS) is spending more time, or an excessive amount of time, *paging in and out* than running needed tasks.  The process of paging requires substantial processor time.


"Programs that frequently access many widely separated locations in memory are more likely to cause page thrashing on a system. "   why ???

I believe this would only be the case in processes that access shared memory.  The Page Manager would be forced to first make room for the new page to be bringed in and then bring in the needed page.

Most commonly, Page Trashing occurs with high activity and time slicing leading to the running process being timed out and a new process going into "running" state and requiring its pages to be "swapped" to real memory.  This is what causes Windows to go into a long delay while you see your disk activity light quickly flashing.

"So is running many small programs that all continue to run even when you are not actively using them""  why??

It's not the size of the program is the amount of memory they use.  As little as two or three processes can lead to Page Trashing if your "time slice" is short and each of those processes access their virtual memory in a dispersed form.

thank you :)

Hope it helps! :)

Yes  2 Users have rated as useful.
  
Login to rate this answer.
amit1220

Answered On : Dec 13th, 2012

Thrashing is caused by under allocation of the minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multi-programming. It can be eliminated by reducing the level of multi-programming.

  
Login to rate this answer.
kranthi tadisetty

Answered On : Oct 20th, 2013

thrashing means "high pagefaultservice time ",bcoz of that reason the operating system can applying pagereplacement algorithms are very highly,i.e(processor busy with executing pagereplacement algorithms rather than executing userinstructions

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.