Concepts / Storage Devices and File Systems

Storage Devices and File Systems

The CPU does not work directly with program files on a hard drive.

  • 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?
Key point

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.

Program fileSecondary memoryMain memoryActive program dataCPUExecutes codecopy programexecute and process
How does data move between secondary memory, main memory, and the CPU while a program is running?
Worked example

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. 1
    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. 2
    2. Execute the application

    The CPU executes the browser code from main memory.

  3. 3
    3. Request a webpage

    When the user enters a web address, the browser sends a request over the network.

  4. 4
    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. 5
    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.

Result

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.

Main memoryProgram data presentPower cutMain memoryData lostpower removedvolatile contents disappear
What happens to the contents of main memory when power is cut off?
Before

Document data is in main memory. Power is available.

The data is available for active processing but is volatile.

After

Document data remains in secondary memory. Power can be removed.

The saved data persists after shutdown because it was copied to secondary memory.

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

Examples of secondary memory and their appropriate long-term storage role

Key point

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.

ComputerRequests dataNetwork connectionSlow and unreliableWeb serverRemote webpage dataMain memoryReceived dataCPUProcesses datarequestforward requestreturn webpagedeliver dataprocess
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

  • Common mistake

    Assuming that data the CPU is using is automatically permanent

    What it looks like

    A document is open and visible, so a learner assumes it will survive a power cut.

    Why it fails

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

    Do this instead

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

  • Common mistake

    Thinking the CPU executes a program directly from a hard drive

    What it looks like

    Describing a browser as running straight from its stored program file.

    Why it fails

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

    Do this instead

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

  • Common mistake

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

    What it looks like

    Designing a critical, time-sensitive operation as though remote data will always arrive instantly.

    Why it fails

    The source describes network connections as slow and unreliable.

    Do this instead

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

  • Common mistake

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

    What it looks like

    Expecting an unsaved webpage to remain after closing the browser.

    Why it fails

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

    Do this instead

    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. 1
    Read the file from secondary memory into main memory.
  2. 2
    The CPU processes the data in main memory.
  3. 3
    Write the result from main memory to secondary memory if it must persist.
  4. 4
    Remember that unsaved data in main memory is vulnerable to power loss.

Memory Hierarchy Summary

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

At a glance

  • 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.

Related concepts

More concepts starting with S