Concepts / Storage Devices and File Systems

Storage Devices and File Systems

Main memory is fast and nearly as quick as the CPU, but it is volatile and loses all data when power is cut off.

  • Programming

Two Jobs, Two Memory Systems

A running program needs data close to the CPU so that the CPU can access it quickly. A computer also needs to retain programs and files after power is removed. One type of memory cannot provide both requirements equally well, so computers use multiple memory systems. Main memory supports fast active work, while secondary memory supports long-term storage.

Main memoryFast; volatileSecondary memorySlower; persistent
What changes when storage is fast but volatile versus slower but persistent?

Main memory is fast and nearly as quick as the CPU, but it is volatile. Secondary memory is much slower, but it retains data without power.

A Program’s Route to the CPU

The CPU does not work directly with program files on a hard drive. When you start a program, the operating system copies the program from secondary memory into main memory. The CPU then executes the program code from main memory. The same pattern applies to data: information needed for active processing must be placed in main memory before the CPU works with it.

copy programexecute and processProgram fileSecondary memoryMain memoryActive program dataCPUExecutes code
How does data move between secondary memory, main memory, and the CPU while a program is running?

Opening a Web Browser

Trace what happens when a user opens a browser, loads a webpage, and then closes the browser without saving the page.

1. Start the browser: The browser application is stored on secondary memory, such as a hard drive. When the browser icon is selected, the operating system copies the application into main memory.

2. Execute the application: The CPU executes the browser code from main memory.

3. Request a webpage: When the user enters a web address, the browser sends a request over the network.

4. Receive webpage data: The web server sends webpage data back over the network. The data arrives in main memory, where the CPU processes it and the computer displays it.

5. Close without saving: The webpage data held in main memory is lost when the browser closes without saving it. The browser application remains on secondary memory and can be loaded again later.

The browser application persists because it is stored in secondary memory, while the unsaved webpage data was only part of the active information in main memory.

Saving Across the Power Boundary

Volatility describes whether memory keeps its contents when power is removed. Main memory requires constant power, so cutting power causes all data in it to be lost. Secondary memory is non-volatile: it retains data indefinitely without power. Saving is therefore an explicit transfer from main memory to secondary memory.

power removedvolatile contents disappearMain memoryProgram data presentPower cutMain memoryData lost
What happens to the contents of main memory when power is cut off?

For the same reason, a program that reads a large file must first read that file from secondary memory into main memory. If the program produces results that must still exist after the program finishes, it must explicitly write those results to secondary memory.

Choosing Secondary Memory

Secondary memory is designed for long-term storage because it keeps data without power. Common examples include disk drives, specifically hard disk drives and solid-state drives, as well as flash memory found in USB sticks and portable music players. These technologies are appropriate for retaining programs and files rather than for the CPU’s immediate processing work.

Storage typeSource-described usePersistence
Hard disk driveLong-term storage of programs and filesRetains data without power
Solid-state driveLong-term storage of programs and filesRetains data without power
Flash memoryStorage in USB sticks and portable music playersRetains data without power

The important classification is not simply the device’s physical form. Secondary memory is identified here by its role: it retains data without power and provides long-term storage.

Networks as Remote Storage

A network connection can act as a form of secondary memory because it provides access to data stored somewhere else. The data is remote rather than already present on the computer’s local storage. The computer requests the data, receives it over the network, and places it into main memory so the CPU can process it.

requestforward requestreturn webpagedeliver dataprocessComputerRequests dataNetwork connectionSlow and unreliableWeb serverRemote webpage dataMain memoryReceived dataCPUProcesses data
How does the computer access remote data, and where do speed, availability, and connection limitations affect the process?

What do you think happens?

A webpage has arrived from a server over the network. Where must the webpage data be placed before the CPU processes it?

  • Directly on the hard drive only
  • In main memory
  • Only on the network connection
Reveal answer

Answer: In main memory

The webpage data arrives over the network and is placed into main memory. The CPU then processes the data from main memory.

Mistakes About Persistence

  • Assuming that data the CPU is using is automatically permanent

    Active data is held in main memory, which is volatile and loses its contents when power is removed.

    Fix: Explicitly save the document to secondary memory when it must persist.

  • Thinking the CPU executes a program directly from a hard drive

    The operating system copies the program from secondary memory into main memory before the CPU executes it.

    Fix: Trace the route as secondary memory to main memory to CPU.

  • Treating network access as equally reliable and immediate as local active memory

    The source describes network connections as slow and unreliable.

    Fix: Use network connections for remote access while recognizing their speed and availability limitations.

  • Assuming that closing a program saves every piece of data it used

    Data that remains only in main memory can be lost when it is no longer active or when power is removed.

    Fix: Save important results explicitly to secondary memory.

Apply the Memory Model

EASY

A program reads a file, changes its data, and produces a result that must still exist after the computer is turned off. Describe the movement of the data through the memory systems. Then identify what could be lost if the program ends before it saves the result.

Hints
  • Begin with where the original file is stored.
  • Identify where the CPU must find the data while processing it.
  • Finish by identifying where the result must be written for persistence.
  1. Read the file from secondary memory into main memory.
  2. The CPU processes the data in main memory.
  3. Write the result from main memory to secondary memory if it must persist.
  4. Remember that unsaved data in main memory is vulnerable to power loss.

Memory Hierarchy Summary

  1. Main memory is fast and close to the CPU, so the CPU uses it for active program execution and data processing.
  2. Main memory is volatile: its contents are lost when power is cut off.
  3. Secondary memory is slower but non-volatile, so it retains programs and files for long-term storage.
  4. Disk drives and flash memory are examples of secondary memory.
  5. Network connections provide remote access to data, but their slowness and unreliability make them unsuitable for critical, time-sensitive operations.

Key Takeaways

  • The CPU works with data in main memory rather than directly with files on secondary memory.
  • Main memory provides speed but loses its contents without power.
  • Secondary memory provides persistence but is much slower than main memory.
  • Saving explicitly copies data from main memory to secondary memory.
  • Network connections can provide remote data access, but they are slow and unreliable compared with local active processing.