NOTE
Memory Tuning
1. Memory Performance Metrics 1.1. System Memory Usage 1.1.1. Used Memory Memory that has already been used. 1.1.2. Remaining Memory Memory that has not yet been used. 1.1.3. Shared Memory The amount of memory used by tmpfs; it is also a kind of cach
This is a historical learning note and may contain outdated or incomplete understanding.
1. Memory Performance Metrics
1.1. System Memory Usage
1.1.1. Used Memory
Memory that has already been used.
1.1.2. Remaining Memory
Memory that has not yet been used.
1.1.3. Shared Memory
The amount of memory used by tmpfs; it is also a kind of cache.
1.1.4. Available Memory
Remaining memory + cache and buffers.
1.1.5. Cache and Buffers
Cache is divided into two parts:
- Page cache for files read from disk.
- Reclaimable memory in the Slab allocator. Buffers refer to temporary storage for raw disk blocks.
1.2. Process Memory Usage
1.2.1. Virtual Memory
The process’s code segment, data segment, shared memory, allocated heap memory, swapped-out memory, etc. Allocated memory counts as virtual memory even if physical memory has not yet been allocated.
1.2.2. Resident Memory
Physical memory actually used by the process, excluding Swap and shared memory.
1.2.3. Shared Memory
Includes both real shared memory used together with other processes, as well as loaded dynamic libraries and the program’s code segment, etc.
1.2.4. Swap Memory
Memory swapped out to disk through Swap.
1.2.5. Page Faults
Calling a memory-allocation request does not immediately allocate physical memory. Instead, physical memory is allocated through a page fault when the requested memory is first accessed. Page faults are divided into:
- Major page fault: disk I/O is involved, such as Swap.
- Minor page fault: allocate directly from physical memory.
1.3. Swap Usage
1.3.1. Used Space and Remaining Space
Memory space that has been used and has not been used.
1.3.2. Swap-In and Swap-Out Speed
The amount of memory swapped in and out per second.
2. Memory Performance Tools
2.1. top
2.2. free
2.3. vmstat
3. How to Analyze a Memory Performance Bottleneck
3.1. Check Whether Memory Is the Bottleneck
- First use free to view overall system memory usage.
3.2. Find the Process with High Memory Usage
- Use
topto see which process has high memory usage and record its PID.
3.3. Analyze the Process
- If it is a Java process:
- If it is a Golang process:
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub