levo

Input, Output and Storage

Virtual storage and disk thrashing

  • 1 thing to know
  • Component 01

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

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

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

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

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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