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.
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 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.
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.
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 type | Source-described use | Persistence |
|---|---|---|
| Hard disk drive | Long-term storage of programs and files | Retains data without power |
| Solid-state drive | Long-term storage of programs and files | Retains data without power |
| Flash memory | Storage in USB sticks and portable music players | Retains 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.
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?
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
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.
- Read the file from secondary memory into main memory.
- The CPU processes the data in main memory.
- Write the result from main memory to secondary memory if it must persist.
- Remember that unsaved data in main memory is vulnerable to power loss.
Memory Hierarchy Summary
- Main memory is fast and close to the CPU, so the CPU uses it for active program execution and data processing.
- Main memory is volatile: its contents are lost when power is cut off.
- Secondary memory is slower but non-volatile, so it retains programs and files for long-term storage.
- Disk drives and flash memory are examples of secondary memory.
- 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.