levo

Input, Output and Storage

Virtual storage and disk thrashing

  • 1 thing to know
  • Component 01
Start revising · £5/month

Overview

Recall questions on how virtual memory uses secondary storage, page faults and page replacement, disk thrashing and how to cure it, the two meanings of virtual storage, and why cache and virtual memory are different ideas.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

What is virtual memory, and when does disk thrashing occur?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Which part of secondary storage does virtual memory actually use, and how is it set aside?

    Model answer

    A region of the hard disk or SSD is reserved by the operating system to hold pages of data and program code that will not fit in RAM. On Windows this is a page file, a single large file on the system drive; on Unix-like systems it is usually a dedicated swap partition, or a swap file. Either way it is ordinary secondary storage, addressed by the operating system rather than by the programmer, and the processor never reads from it directly: a page has to be copied back into RAM before it can be used. Its size is configurable, and making it larger increases how much a machine can appear to hold but does nothing for speed, because the underlying storage is still thousands of times slower than RAM.

  2. 2

    If secondary storage is thousands of times slower than RAM, why is virtual memory a good idea at all?

    Model answer

    Because at any given moment a running program only needs a small part of itself and its data. The rest, the code for features not currently in use and data not being touched, can sit on disk without slowing anything down, freeing RAM for what is actually in use. That lets programs larger than physical RAM run at all, and lets many more programs stay open at once. The slow disk access is only paid when a page that is not in RAM is genuinely needed.

  3. 3

    Describe what happens when a program accesses an address whose page is not in RAM.

    Model answer

    The program uses virtual addresses, and the memory management unit translates each one by looking the virtual page up in a page table to find the physical frame it occupies. If the page table shows that the page is not currently in RAM, a page fault occurs. The operating system suspends the process, finds a free frame, evicting an existing page if necessary and writing it back to the page file first if it has been modified, reads the required page from secondary storage into the frame, updates the page table, and then restarts the instruction that faulted. The program itself is unaware any of this happened, apart from the delay.

  4. 4

    How does the operating system decide which page to remove when it needs space?

    Model answer

    It applies a replacement policy. The usual approach is to evict the page that has been least recently used, on the assumption that a page untouched for a while is the one least likely to be wanted soon. Pages that have not been modified since being loaded are preferred, because they can simply be discarded rather than written back. Some pages belonging to the operating system are locked in memory and never evicted at all.

  5. 5

    What does thrashing look like from the point of view of the storage device, and why does it shorten the life of an SSD?

    Model answer

    The drive is in almost continuous use: a stream of small reads and writes as pages are swapped out and back in, with the activity light on constantly and disk queue length high, while processor utilisation is low because the CPU is waiting rather than working. On a magnetic drive the heads are seeking constantly, which is why the machine also becomes audibly busy. On an SSD there is no seek time, so thrashing is less catastrophic, but flash cells tolerate only a finite number of erase and write cycles, and a thrashing machine writes to the swap area continuously, so it consumes that endurance far faster than normal use would. That is why adding RAM, rather than a faster drive, is the proper cure.

  6. 6

    Why does thrashing make a computer catastrophically slow rather than just somewhat slower?

    Model answer

    Because of the sheer size of the speed gap. A RAM access takes tens of nanoseconds while an access to a mechanical disk takes several milliseconds, a difference of something like a hundred thousand times, so replacing memory accesses with disk accesses does not add a small overhead, it multiplies the cost enormously. Each fault may also require a modified page to be written out as well as a new one read in, doubling the transfers, and while a process waits for its page it cannot run at all.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Input, Output and Storage, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.