Bird
Raised Fist0
Operating Systemsknowledge~30 mins

Thrashing and working set model in Operating Systems - Mini Project: Build & Apply

Choose your learning style10 modes available
Understanding Thrashing and the Working Set Model
📖 Scenario: You are learning about how operating systems manage memory. Sometimes, a computer slows down because it spends too much time moving data between memory and disk. This is called thrashing. To understand this better, you will create a simple example that shows how the working set model helps reduce thrashing.
🎯 Goal: Build a step-by-step example that models a process's memory pages and how the working set model tracks pages to avoid thrashing.
📋 What You'll Learn
Create a list of page references representing memory accesses.
Define a window size to represent the working set time frame.
Use a loop to find the working set of pages in the current window.
Show the final working set for the last window of page references.
💡 Why This Matters
🌍 Real World
Operating systems use the working set model to decide which memory pages to keep in RAM and which to swap out, preventing thrashing and improving performance.
💼 Career
Understanding memory management concepts like thrashing and working sets is important for roles in system administration, software development, and performance optimization.
Progress0 / 4 steps
1
Create the list of page references
Create a list called page_references with these exact values: [1, 2, 3, 2, 4, 1, 5, 2, 1, 3, 4, 5].
Operating Systems
Hint

Think of page_references as the sequence of pages a program accesses in order.

2
Define the working set window size
Create a variable called window_size and set it to 4 to represent the number of recent page references to consider.
Operating Systems
Hint

The window_size tells us how many recent pages to look at when finding the working set.

3
Find the working set for each window
Use a for loop with variable i to go from window_size to the length of page_references. Inside the loop, create a set called working_set containing the pages from page_references[i - window_size:i].
Operating Systems
Hint

The loop moves a window over the page references. The working_set holds unique pages in that window.

4
Show the final working set
After the loop, create a variable called final_working_set and set it to the last working_set calculated.
Operating Systems
Hint

The final_working_set shows which pages are currently in use in the last window, helping to avoid thrashing.

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