Bird
Raised Fist0
Operating Systemsknowledge~10 mins

Thrashing and working set model in Operating Systems - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Thrashing and working set model
Process starts running
↓
Needs pages in memory
↓
Check if enough frames
↓
Load pages
↓
Process runs
↓
Working set tracked
↓
Adjust frames based on working set
↓
Process runs smoothly
This flow shows how a process requests memory pages, how lack of frames causes thrashing, and how the working set model helps manage frames to avoid thrashing.
Execution Sample
Operating Systems
Process requests pages
If frames < working set size
  Page faults increase
  Thrashing occurs
OS tracks working set
OS adjusts frames
Process runs smoothly
This pseudo-code shows how the system checks if the process has enough memory frames to hold its working set and adjusts to prevent thrashing.
Analysis Table
StepConditionActionResult
1Process starts runningRequest pagesPages needed in memory
2Frames available >= working set size?YesLoad pages into frames
3Process runsAccess pagesFew page faults
4Frames available < working set size?YesPage faults increase
5Page faults highThrashing occursProcess slows down
6OS tracks working setCalculate pages used recentlyWorking set size determined
7OS adjusts framesAllocate frames to match working setPage faults reduce
8Process runsAccess pagesRuns smoothly again
💡 Thrashing stops when OS allocates enough frames to cover the working set size.
State Tracker
VariableStartAfter Step 3After Step 5After Step 7Final
Frames availableEnoughEnoughInsufficientAdjustedEnough
Page faults0LowHighReducedLow
Working set sizeUnknownUnknownTrackedDeterminedStable
Key Insights - 3 Insights
Why does thrashing cause the process to slow down?
Because the process keeps causing page faults and waiting for pages to load, it spends more time swapping pages than doing useful work (see execution_table step 5).
How does the working set model help prevent thrashing?
It tracks the pages the process uses recently and ensures enough frames are allocated to hold these pages, reducing page faults (see execution_table steps 6 and 7).
What happens if the OS does not adjust frames based on the working set?
The process will continue to thrash because it does not have enough frames to hold its needed pages, causing high page faults and slow execution (see execution_table steps 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at which step does thrashing start?
AStep 5
BStep 4
CStep 3
DStep 6
💡 Hint
Check the 'Action' and 'Result' columns where 'Thrashing occurs' is mentioned.
According to variable_tracker, what happens to page faults after OS adjusts frames?
APage faults increase
BPage faults stay high
CPage faults reduce
DPage faults become zero
💡 Hint
Look at the 'Page faults' row after Step 7 in variable_tracker.
If the working set size is underestimated, what is likely to happen?
AProcess will run smoothly
BThrashing will continue
CFrames will be over-allocated
DPage faults will be zero
💡 Hint
Refer to key_moments about the importance of matching frames to working set size.
Concept Snapshot
Thrashing happens when a process has too few memory frames, causing many page faults and slow execution.
The working set model tracks the pages a process uses recently.
OS allocates frames to cover the working set to reduce thrashing.
Adjusting frames based on working set size helps the process run smoothly.
Full Transcript
Thrashing occurs when a process does not have enough memory frames to hold the pages it needs, causing frequent page faults and slowing down the process. The working set model helps by tracking the pages the process uses recently and ensuring enough frames are allocated to hold these pages. When the OS detects thrashing, it calculates the working set size and adjusts the number of frames allocated to the process. This reduces page faults and allows the process to run smoothly again.

Practice

(1/5)
1. What is thrashing in operating systems?
easy
A. A system running multiple programs efficiently
B. A process running without any memory
C. A method to speed up CPU processing
D. Excessive paging causing slow system performance

Solution

  1. Step 1: Understand the meaning of thrashing

    Thrashing happens when the system spends too much time swapping pages in and out of memory instead of executing processes.
  2. Step 2: Identify the effect of thrashing

    This excessive paging slows down the computer significantly, reducing performance.
  3. Final Answer:

    Excessive paging causing slow system performance -> Option D
  4. Quick Check:

    Thrashing = Excessive paging slowing system [OK]
Hint: Thrashing means too much swapping slows the computer [OK]
Common Mistakes:
  • Confusing thrashing with normal multitasking
  • Thinking thrashing speeds up the CPU
  • Believing thrashing means no memory usage
2. Which of the following best describes the working set of a process?
easy
A. Pages never accessed by the process
B. All pages in the system memory
C. Pages recently used by the process
D. Pages swapped out to disk

Solution

  1. Step 1: Define working set

    The working set is the collection of pages a process has used recently and needs to run efficiently.
  2. Step 2: Identify correct description

    Pages recently used by the process fit this definition, unlike all pages or swapped pages.
  3. Final Answer:

    Pages recently used by the process -> Option C
  4. Quick Check:

    Working set = Recently used pages [OK]
Hint: Working set means pages used recently by process [OK]
Common Mistakes:
  • Thinking working set includes all system pages
  • Confusing working set with swapped out pages
  • Assuming working set is pages never accessed
3. Consider a system where a process's working set size suddenly grows beyond available memory. What is the most likely outcome?
medium
A. Thrashing will occur, slowing down the system
B. The process will run faster due to more pages
C. The system will ignore the extra pages
D. The process will terminate immediately

Solution

  1. Step 1: Analyze working set growth impact

    If the working set grows beyond available memory, the system must swap pages frequently to keep up.
  2. Step 2: Identify system behavior

    This frequent swapping causes thrashing, which slows down the system instead of speeding it up.
  3. Final Answer:

    Thrashing will occur, slowing down the system -> Option A
  4. Quick Check:

    Working set too big = Thrashing slows system [OK]
Hint: Too big working set causes thrashing and slowdown [OK]
Common Mistakes:
  • Assuming more pages always improve speed
  • Believing system ignores memory limits
  • Thinking process ends immediately without warning
4. A system is experiencing thrashing. Which change would best reduce thrashing?
medium
A. Increase the working set size of all processes
B. Reduce the number of processes competing for memory
C. Decrease the CPU speed
D. Disable paging completely

Solution

  1. Step 1: Understand cause of thrashing

    Thrashing happens when too many processes compete for limited memory, causing excessive paging.
  2. Step 2: Identify best solution

    Reducing the number of processes competing for memory lowers paging demand and reduces thrashing.
  3. Final Answer:

    Reduce the number of processes competing for memory -> Option B
  4. Quick Check:

    Less competition = less thrashing [OK]
Hint: Fewer processes competing reduces thrashing [OK]
Common Mistakes:
  • Increasing working set size worsens thrashing
  • Decreasing CPU speed does not fix memory issues
  • Disabling paging causes system failure
5. A system uses the working set model to manage memory. If a process's working set is 100 pages but only 80 pages fit in memory, what should the system do to avoid thrashing?
hard
A. Swap out some pages from the process's working set
B. Increase the process's working set size to 120 pages
C. Allow the process to run with only 80 pages and swap frequently
D. Terminate the process immediately

Solution

  1. Step 1: Analyze working set vs memory size

    The process needs 100 pages to run well, but only 80 pages fit in memory, causing potential thrashing.
  2. Step 2: Determine best memory management action

    Swapping out some pages from the working set or adjusting memory allocation helps keep the working set within limits and avoids thrashing.
  3. Final Answer:

    Swap out some pages from the process's working set -> Option A
  4. Quick Check:

    Adjust working set to fit memory to avoid thrashing [OK]
Hint: Adjust working set size to fit memory to prevent thrashing [OK]
Common Mistakes:
  • Increasing working set size worsens thrashing
  • Allowing frequent swaps causes thrashing
  • Terminating process is last resort, not first
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard