I. What Is Memory?
Memory is the storage space in a computer used to hold the data and instructions required for programs to run.
When we open a piece of software, run a piece of code, or visit a web page, the computer needs to use memory.
For example, when running a Python program:
name = "Alice"
age = 25
result = age + 10
print(name, result)
During program execution, the computer needs to store:
- Program instructions: what operation should be executed next.
- Variable data: what values
name,age, andresulteach store. - Intermediate results: temporary data generated during computation.
- Execution state: where the program is currently executing.
- Function call information: function parameters, local variables, and return addresses.
All of this information requires a certain amount of storage space.
Memory is the important storage area used while a program runs.
1. The Nature of Memory
From the perspective of a computer system, memory is a storage device that can be directly accessed by the CPU.
It has several important characteristics:
| Characteristic | Description |
|---|---|
| Random access | Data at a specified location can be accessed directly by address |
| Fast read/write speed | Access speed is usually much higher than that of SSDs and hard disk drives |
| Temporary storage | Data in mainstream DRAM memory is lost when power is cut off |
| Limited capacity | Physical memory capacity is limited by the hardware configuration |
| Organized by address | Each storage location has a corresponding address |
There is an important concept to understand here:
Memory does not simply store files; it provides a workspace that running programs can read from and write to quickly.
For example, a text file is stored on an SSD. When a program opens it, the operating system typically reads the file contents into memory so that the program can process the data conveniently.
2. What Is the Difference Between Memory and a Hard Drive?
Both memory and hard drives can store data, but they serve different roles.
| Aspect | Memory (RAM) | Hard Drive (SSD / HDD) |
|---|---|---|
| Main purpose | Holds data while programs are running | Long-term storage of files and programs |
| Access speed | Usually faster | Relatively slower |
| Data after power loss | Usually lost | Can be retained long term |
| Capacity | Usually smaller | Usually larger |
| Unit cost | Usually higher | Usually lower |
| CPU access method | Accessed directly through the memory hierarchy | Usually requires I/O operations |
They can be understood as follows:
- Hard drive: a warehouse for storing materials.
- Memory: the desktop used while working.
- CPU: the person responsible for performing tasks.
When a file needs to be processed, the materials are first taken from the warehouse and placed on the desktop, and then computation is performed.
Although this analogy is simple, it helps explain why memory is important.
3. The Basic Working Process of Memory
Suppose we start a program:
- The program file is stored on the SSD.
- The operating system creates a process.
- The code and data required by the program are mapped or loaded into the process address space.
- The CPU executes instructions and accesses the required data.
- While the program runs, it continuously reads, modifies, and creates data.
- When the program ends, the operating system reclaims the corresponding resources.
flowchart TD
A["Program file stored on SSD"] --> B["User starts program"]
B --> C["Operating system creates process"]
C --> D["Establish process virtual address space"]
D --> E["Load or map program code and data"]
E --> F["CPU executes program instructions"]
F --> G["Read and modify memory data"]
G --> H{"Does the program continue running?"}
H -->|Yes| F
H -->|No| I["Process exits"]
I --> J["Operating system reclaims related resources"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#FFF3D9,stroke:#D6B66E,color:#705923
style I fill:#F5F8F4,stroke:#B5BFC5,color:#334155
style J fill:#F5F8F4,stroke:#B5BFC5,color:#334155
Note: A program does not necessarily need to copy the entire executable file into physical memory at startup. Modern operating systems typically use mechanisms such as demand paging and memory mapping, loading the corresponding pages only when needed.
II. Why Does a Program Need Memory?
A program is essentially a set of instructions.
However, instructions alone cannot do all the work; a program also needs to store input data, computation results, and runtime state.
Memory mainly addresses the following issues.
1. Storing Data Required for Program Execution
When a program runs, it needs to use variables to store data.
For example:
username = "Tom"
score = 95
is_passed = True
The program needs to store:
| Variable | Data Type | Data Content |
|---|---|---|
| username | String | Tom |
| score | Integer | 95 |
| is_passed | Boolean | True |
These variables need to be accessed and modified while the program is running.
Memory provides them with runtime storage space.
For example:
score = 95
score = score + 5
print(score)
During execution:
- Create the variable
score. - Store the initial value
95. - Read the original value.
- Calculate
95 + 5. - Store the result
100in the storage location corresponding to the variable. - Output the result.
Without working storage space that can be read and written quickly, the CPU cannot process program data efficiently.
2. Storing Intermediate Results During Program Execution
Many computations are not completed in a single step.
For example:
a = 10
b = 20
c = 30
result = (a + b) * c
The computation process needs to produce intermediate results:
a + b = 30
30 * c = 900
These intermediate data need to be stored temporarily so that subsequent instructions can continue to use them.
In addition to variables, a program also produces:
- Expression computation results.
- Function return values.
- Temporary objects.
- Data structures.
- Algorithm execution state.
Memory provides storage space for these temporary data.
3. Storing Function Call Information
Programs often organize code through functions.
For example:
def add(a, b):
result = a + b
return result
value = add(10, 20)
When the add() function is executed, the runtime environment needs to record:
- The function parameters
aandb. - The local variable
result. - The function execution position.
- The position where execution should continue after the function returns.
This information is usually managed through the call stack and related runtime structures.
Each time a function is called, the runtime environment creates a corresponding call record and releases that record after the function returns.
4. Supporting Multiple Programs Running Simultaneously
Modern operating systems can run multiple programs at the same time.
For example:
- Browsers.
- Music players.
- Text editors.
- Development tools.
- Background services.
Each process needs its own runtime space.
Through virtual memory mechanisms, the operating system provides isolated address spaces for different processes.
In this way, one program generally cannot arbitrarily access another program's private memory.
flowchart TD
A["Operating System"] --> B["Process A: Browser"]
A --> C["Process B: Editor"]
A --> D["Process C: Music Player"]
B --> E["Virtual Address Space A"]
C --> F["Virtual Address Space B"]
D --> G["Virtual Address Space C"]
E --> H["Physical Memory Resources"]
F --> H
G --> H
H --> I["Memory Management Unit (MMU)"]
style A fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style D fill:#FFF3D9,stroke:#D6B66E,color:#705923
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#EAF3EC,stroke:#83A995,color:#315D49
style G fill:#F5F8F4,stroke:#B5BFC5,color:#334155
style H fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style I fill:#F6FAF7,stroke:#DCE9E0,color:#334155
There is an important distinction here:
Each process has an independent virtual address space, but the physical memory they use may be uniformly managed and allocated by the operating system.
Different processes can also share some physical pages in a controlled manner through mechanisms such as shared memory.
5. Improve CPU Execution Efficiency
The CPU's computing speed is usually much higher than that of SSDs and hard disk drives.
If the CPU had to read data directly from the hard disk for every computation, it would spend a great deal of time waiting for I/O.
Memory can provide the CPU with faster data access.
However, when the CPU actually accesses data, it also uses faster storage tiers, such as:
- CPU registers.
- CPU Cache.
- Main memory RAM.
Together, these components form the computer's memory hierarchy.
III. Computer Memory Hierarchy
A computer does not consist only of memory and a hard disk; rather, it is made up of multiple storage tiers with different speeds, capacities, and costs.
These can generally be divided into:
- Registers.
- CPU Cache.
- Main memory (RAM).
- Solid-state drive (SSD).
- Hard disk drive (HDD).
1. Memory Hierarchy
flowchart TD
A["CPU Registers"] --> B["L1 Cache"]
B --> C["L2 Cache"]
C --> D["L3 Cache"]
D --> E["Main Memory (RAM)"]
E --> F["SSD (Solid-State Drive)"]
F --> G["HDD (Hard Disk Drive)"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#FFF3D9,stroke:#D6B66E,color:#705923
style G fill:#F5F8F4,stroke:#B5BFC5,color:#334155
2. Registers
Registers are extremely fast storage units inside the CPU.
They are used to hold the data and state needed by the instructions the CPU is currently executing.
For example:
Calculation:
a = 10
b = 20
c = a + b
When the CPU performs addition, it may place the operands into registers, complete the calculation through the arithmetic logic unit (ALU), and then write the result back to a register or another storage location.
Characteristics of registers:
- Located inside the CPU.
- Extremely fast access speed.
- Limited in number and capacity.
- Directly involved in instruction execution.
3. CPU Cache
CPU Cache is a high-speed cache between the CPU and main memory.
Its main purpose is to reduce the time the CPU spends waiting for data from main memory.
Modern processors usually have multiple levels of cache:
| Cache Level | Main Characteristics |
|---|---|
| L1 Cache | Usually has the smallest capacity and the fastest speed |
| L2 Cache | Capacity is usually larger than L1 |
| L3 Cache | Capacity is usually larger and is often shared by multiple cores |
Caches generally take advantage of locality in program access:
Temporal Locality
Data that has been accessed recently may soon be accessed again.
For example:
total = 0
for i in range(1000):
total += i
The total in the loop is accessed repeatedly.
Spatial Locality
After an address is accessed, nearby addresses may also be accessed soon.
For example:
numbers = [1, 2, 3, 4, 5]
for number in numbers:
print(number)
Array elements are usually stored contiguously, and sequential access helps make use of the cache.
4. Main Memory (RAM)
RAM (Random Access Memory) is usually what we mean by memory in everyday usage.
It is responsible for holding the large amount of data that programs need to access while running.
Common types:
- DRAM: Dynamic Random Access Memory, widely used as computer main memory.
- SRAM: Static Random Access Memory, commonly used in CPU Cache.
DRAM requires periodic refresh to retain data, so it is typically used as main memory.
SRAM does not require periodic refresh like DRAM, but its cost per unit capacity is higher, so it is typically used for smaller-capacity high-speed caches.
5. SSD and HDD
SSDs and HDDs primarily handle long-term storage.
SSD (Solid State Drive)
They use flash memory chips to store data and have no moving mechanical parts.
Characteristics:
- Good random access performance.
- Fast read and write speeds.
- Usually good shock resistance.
- Usually more expensive than HDDs of the same capacity.
HDD (Hard Disk Drive)
Uses magnetic platters to store data, reading and writing through mechanical structures.
Characteristics:
- Relatively large capacity.
- Lower cost per unit of capacity.
- Relatively high random access latency.
- Contains moving mechanical parts.
6. Why can't we use only CPU Cache?
Since Cache is faster than main memory, why not just put all data into Cache?
The main reasons are:
- The storage technology used by Cache is more expensive.
- Space inside the CPU is limited.
- Cache capacity cannot easily be expanded to tens of GB.
- Main memory needs to carry the storage demands of large amounts of programs and data.
Computers balance access speed, capacity and cost through a multi-level storage structure.
4. How does memory store data?
To understand memory, you need to look further at how it is basically organized.
1. Memory consists of a large number of storage units
Logically, memory can be seen as a continuous address space made up of many bytes.
Each byte has its own address.
For example:
| Memory Address | Stored Content |
|---|---|
| 0x1000 | 01000001 |
| 0x1001 | 01000010 |
| 0x1002 | 01000011 |
| 0x1003 | 00000001 |
A byte contains 8 bits.
1 Byte = 8 Bits
Where:
- Bit: the smallest unit of data, with only 0 or 1.
- Byte: made up of 8 Bits.
- KB, MB, GB: commonly used capacity units.
In computer systems, capacity conversion sometimes uses binary units:
| Unit | Binary Conversion |
|---|---|
| 1 KiB | 1024 Bytes |
| 1 MiB | 1024 KiB |
| 1 GiB | 1024 MiB |
| 1 TiB | 1024 GiB |
Hard disk manufacturers, however, often use decimal units:
- 1 KB = 1000 Bytes.
- 1 MB = 1000 KB.
- 1 GB = 1000 MB.
This is also why the advertised capacity and the capacity shown by the operating system may not be exactly the same.
2. What is a memory address?
A memory address is a number used to locate a storage position.
For example:
Address 0x1000
Address 0x1001
Address 0x1002
Address 0x1003
Programs access data in memory through addresses.
You can think of memory as a row of numbered lockers:
- The locker number is the address.
- The contents of the locker are the data.
- Finding the locker by its number is memory access.
In modern computers, programs usually use virtual addresses rather than directly manipulating physical memory addresses.
Only after address translation is a virtual address mapped to an actual physical memory location.
3. How does the CPU read memory?
When the CPU accesses memory, it usually goes through the following process:
- The CPU generates a memory access request.
- The request carries the address to be accessed.
- The CPU first checks the relevant cache.
- If the cache hits, the data is read directly from the cache.
- If the cache misses, lower-level storage must be accessed.
- If necessary, main memory is accessed.
- The read result is returned to the CPU.
flowchart TD
A["CPU initiates a memory access"] --> B["Check CPU Cache"]
B --> C{"Does the cache hit?"}
C -->|Yes| D["Read data from Cache"]
C -->|No| E["Access main memory"]
E --> F["Read the target data"]
F --> G["Fill Cache according to the caching policy"]
D --> H["CPU uses the data"]
G --> H
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#FFF3D9,stroke:#D6B66E,color:#705923
style D fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style E fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Note: the cache hierarchy, prefetching, write-back and coherence protocols of actual processors are far more complex than this simplified flow. What is shown here is the basic process, meant to help with understanding.
5. How is memory allocated when a program runs?
When a program runs, the operating system and the runtime environment need to allocate and manage memory for the program.
For a process, its memory can usually be logically divided into multiple regions.
Common regions include:
- Code segment (Text Segment).
- Data segment (Data Segment).
- BSS segment.
- Heap.
- Stack.
- Memory mapping region (Memory Mapping).
1. Code Segment (Text Segment)
The code segment mainly stores the program's machine instructions.
For example:
int add(int a, int b) {
return a + b;
}
The compiler converts source code into machine instructions.
After the program is loaded, the relevant instructions are mapped into the process's code region.
The code segment usually has the following characteristics:
- It stores executable instructions.
- It is usually set to readable and executable.
- Ordinary write operations are usually not allowed.
- It may be shared by multiple processes.
2. Data Segment (Data Segment)
The data segment mainly stores initialized global variables and static variables.
For example:
int global_count = 100;
static int total = 200;
These variables usually exist for the entire duration of the program.
They are not automatically destroyed when a function finishes executing.
3. BSS Segment
The BSS segment stores global variables and static variables that are not explicitly initialized.
For example:
int global_count;
static int total;
In C, these variables are initialized to 0 by default.
In an executable file, the BSS segment usually does not need to store actual zero-value data for each variable; instead, it describes the required space through information such as the segment size.
4. Heap
The heap is used for dynamic memory allocation.
During program execution, if memory needs to be allocated according to actual conditions, the heap can be used.
For example, in C:
#include <stdio.h>
#include <stdlib.h>
int main() {
int *number = malloc(sizeof(int));
if (number == NULL) {
return 1;
}
*number = 100;
printf("%d\n", *number);
free(number);
return 0;
}
Here:
malloc()allocates dynamic memory.- The returned pointer stores the address of the allocated region.
*numberaccesses the data at that address.free()releases the allocated memory.
Main characteristics of the heap:
- Its lifetime is managed by the dynamic allocation and deallocation mechanism.
- It is suitable for storing data whose size or lifetime is uncertain.
- Allocation and deallocation usually incur additional management overhead.
- Incorrect use can lead to memory leaks or invalid access.
5. Stack
The stack is mainly used to manage runtime information during function calls.
For example:
int add(int a, int b) {
int result = a + b;
return result;
}
int main() {
int value = add(10, 20);
return 0;
}
When a function is called, the runtime environment needs to manage information such as parameters, local variables, and return addresses.
This information is usually organized by stack frames (Stack Frame).
After the function returns, the corresponding stack frame is usually released.
Characteristics of the stack:
- It is usually managed automatically by the runtime.
- A stack frame is created when a function is called.
- The corresponding stack frame is reclaimed when the function returns.
- Allocation and deallocation are usually very efficient.
- Space is usually limited, and excessively deep recursion may cause a stack overflow.
Note that not all local variables are necessarily stored on the stack. After compiler optimization, some variables may be placed in registers or even eliminated entirely.
6. Memory Mapping Region (Memory Mapping)
Modern operating systems also use memory mapping mechanisms to manage files and dynamic libraries.
Common uses include:
- Mapping dynamic link libraries into the process address space.
- Mapping files into memory.
- Creating shared memory.
- Managing access to large files.
For example, using mmap(), part of a file can be mapped into the process's virtual address space, allowing the program to read or modify file contents through memory access.
7. Process Memory Layout Diagram
The following is a simplified layout of a process's virtual address space. The actual layout may differ across operating systems, architectures, and programs.
High address
┌──────────────────────────┐
│ Stack │
│ Function calls, locals │
│ ↓ │
├──────────────────────────┤
│ │
│ Memory Mapping │
│ Dyn libs/maps/shared │
│ │
├──────────────────────────┤
│ ↑ │
│ Heap │
│ Dyn allocated data │
├──────────────────────────┤
│ BSS Segment │
│ Uninit globals/statics │
├──────────────────────────┤
│ Data Segment │
│ Init globals/statics │
├──────────────────────────┤
│ Text Segment │
│ Machine instructions │
└──────────────────────────┘
Low address
This diagram shows the traditional conceptual layout; it does not mean that the heap and stack grow in fixed directions on all systems, nor does it mean that the actual address space contains only these regions.
8. What Is the Difference Between the Heap and the Stack?
The heap and the stack are the two most important concepts for understanding program memory management.
| Aspect | Stack | Heap |
|---|---|---|
| Main purpose | Function calls and local runtime data | Dynamically allocated objects |
| Management | Usually managed automatically by the runtime | Managed by the allocator and program runtime |
| Lifetime | Usually ends when the function call ends | Determined by deallocation or garbage collection |
| Allocation characteristics | Usually uses stack-style allocation | Requires finding or managing available memory blocks |
| Space characteristics | Usually small and limited | Usually can expand as needed |
| Common issues | Stack overflow | Memory leaks, fragmentation, dangling pointers |
For example:
#include <stdlib.h>
int main() {
int a = 10;
int *p = malloc(sizeof(int));
if (p == NULL) {
return 1;
}
*p = 20;
free(p);
return 0;
}
Here:
ais a local variable in the function; it is usually placed on the stack or in a register.pis a local pointer variable, also usually on the stack or in a register.- The integer storage allocated by
malloc()is located in the area managed by the heap.
Note: the pointer variable itself and the memory it points to are not the same thing.
This is key to understanding memory management in C and C++.
VI. What Is Virtual Memory?
Virtual memory is a memory management mechanism provided by modern operating systems.
It provides each process with an independent virtual address space, so programs do not need to manage physical memory addresses directly.
1. Why Is Virtual Memory Needed?
Suppose a computer is running three programs at the same time:
- Browser.
- Editor.
- Music player.
If every program accessed physical memory directly, the following could occur:
- Different programs using the same address, causing conflicts.
- Programs accidentally modifying other programs' data.
- Physical memory allocation and reclamation becoming very complex.
- Programs needing to understand the underlying hardware memory layout.
Virtual memory solves these problems.
It lets programs use independent virtual address spaces, with the operating system and hardware performing the address mapping.
2. Virtual Addresses and Physical Addresses
Virtual Address
The address that a program sees and uses.
Physical Address
The location in actual main memory where data is stored.
For example:
Process A:
Virtual address 0x1000
↓
Physical address 0x8000
Process B:
Virtual address 0x1000
↓
Physical address 0xA000
The two processes can use the same virtual address but map it to different physical memory locations.
This makes memory isolation between processes possible.
3. What Is the MMU?
The MMU (Memory Management Unit) is a hardware module in the processor responsible for address translation and memory access permission checks.
Address translation usually relies on page tables.
The basic process is as follows:
- The CPU generates a virtual address.
- The MMU looks up the address translation information.
- If a cached mapping exists in the TLB, it is used directly.
- If the TLB misses, the lookup is completed through the page table.
- The physical address is obtained.
- Access permissions are checked.
- Physical memory is accessed.
The TLB (Translation Lookaside Buffer) is a high-speed cache used to store address translation results.
flowchart TD
A["CPU generates virtual address"] --> B["MMU receives address"]
B --> C["Look up TLB"]
C --> D{"TLB hit?"}
D -->|Yes| E["Obtain physical address"]
D -->|No| F["Look up page table"]
F --> G{"Page table mapping valid?"}
G -->|Yes| H["Update TLB"]
G -->|No| I["Trigger page fault"]
H --> E
E --> J["Check access permissions"]
J --> K["Access physical memory"]
I --> L["OS handles page fault"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#FFF3D9,stroke:#D6B66E,color:#705923
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style G fill:#FFF3D9,stroke:#D6B66E,color:#705923
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
style J fill:#EAF3EC,stroke:#83A995,color:#315D49
style K fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style L fill:#EAE8FA,stroke:#A49BD5,color:#51477D
4. Paging Mechanism
Virtual memory is usually managed through paging.
The operating system divides the virtual address space into fixed-size pages, and physical memory into correspondingly sized frames.
For example:
Assume the page size is 4 KiB:
Virtual address space:
Page 0
Page 1
Page 2
Page 3
Physical memory:
Frame 0
Frame 1
Frame 2
Frame 3
Virtual pages do not need to be mapped contiguously to physical frames.
For example:
Virtual Page 0 → Physical Frame 3
Virtual Page 1 → Physical Frame 1
Virtual Page 2 → Physical Frame 5
This allows the operating system to manage physical memory flexibly.
5. Page Fault
When a program accesses a virtual page that does not have a valid physical memory mapping, a page fault may be triggered.
A page fault does not necessarily mean the program has an error.
For example:
- The page has not yet been loaded into physical memory.
- The data corresponding to the page is located in swap space.
- A file-mapped page has not yet been read.
- The page access permissions do not meet the requirements.
The operating system decides how to handle it based on the specific situation.
If the page is valid but not yet resident in memory, the operating system may load the page from disk or other backing storage.
If the access violates permissions, for example writing data to a read-only page, the process may receive an exception signal or be terminated.
6. Relationship Between Virtual Memory and Physical Memory
Note in particular:
Virtual memory is not a simple substitute for physical memory, nor is it equivalent to hard disk space.
Virtual memory is an address space and memory management mechanism.
It can work in conjunction with mechanisms such as physical memory, file mapping, and swap space.
The operating system can also use demand paging to avoid allocating physical memory for all virtual addresses from the start.
VII. What Happens When Memory Runs Out?
A computer's memory capacity is limited.
When multiple programs run simultaneously, or a program uses a large amount of memory, memory pressure may occur.
1. Excessive Memory Usage
For example:
- Opening a large number of browser tabs at the same time.
- Running a large IDE.
- Loading a large dataset.
- Starting multiple containers.
- Running a large model inference service.
These operations all consume memory.
When available physical memory is insufficient, the operating system needs to take appropriate measures.