Linux Memory Debugging: Uncover Hidden Issues with /proc Filesystem
This comprehensive guide teaches Linux engineers how to use the /proc filesystem to diagnose memory issues that standard tools like top and free miss, covering system-level analysis, process memory breakdowns, swap investigation, kernel memory tracking, and memory leak detection with practical commands and interpretation logic.
Reading font

Problem Background
In Linux system operations, memory issues are among the most common and difficult faults to troubleshoot. Operations engineers habitually use top, free and similar tools to quickly check memory usage, but these tools show aggregated statistics that hide many details.
When encountering the following scenarios, top is often powerless:
System memory insufficient but top shows large free memory
Process RSS small but actual GPU memory usage large
Memory keeps growing but cannot find which process is leaking
OOM Killer frequently triggers but top shows no cause
Process killed but /proc/meminfo still shows memory shortage
Swap usage high but unknown which pages swapped out
Process memory usage abnormal but unclear if heap, stack, or shared libraries
At this point, you need to directly read the /proc filesystem for finer-grained information. /proc is a pseudo-filesystem exposed by the Linux kernel for process and system state, containing vast details that top cannot show.
This article targets Linux operations engineers and SREs, organizing how to troubleshoot memory problems via /proc, clarifying file meanings, reading methods, analysis approaches, and common pitfalls.
Applicable Scenarios
System memory insufficient, need to locate specific cause
Process memory usage abnormal, need to analyze memory distribution
OOM Killer frequently triggers, need to locate killed process and cause
Swap usage high, need to find swapped-out memory
Memory cache usage large, need to judge if reclaimable
Need to precisely calculate process real memory usage
Need to trace memory leak problems
Core Knowledge Points
/proc Filesystem Introduction
/procis a pseudo-filesystem (pseudo-filesystem), not occupying actual disk space; all content is dynamically generated by the kernel. Main components: /proc/meminfo: system-level memory statistics /proc/$PID/: process-level info, each process has a directory named by PID /proc/sys/: kernel parameters, dynamically adjustable /proc/vmstat: virtual memory statistics /proc/buddyinfo: buddy system memory fragmentation info /proc/slabinfo: slab allocator statistics
Memory Classification
Linux memory can be classified from multiple dimensions:
By Purpose:
User-space memory: memory used by processes
Kernel-space memory: memory used by kernel and drivers
Page Cache: file cache
Buffer: block device cache
Slab: kernel object cache
By State:
Active: recently accessed, not reclaimed
Inactive: recently not accessed, reclaimable
Dirty: modified but not written back to disk
Writeback: currently writing back to disk
By Attribute:
Anonymous pages: heap, stack, etc., no corresponding file
File-backed pages: have corresponding file, can be re-read from file
Shared memory: shared by multiple processes
Common Misconceptions
RSS ≠ process real memory usage : RSS includes shared libraries; shared libraries used by multiple processes are counted repeatedly.
free shows inaccurate available memory : Cache and Buffer are usually reclaimable, but free doesn't reflect this.
Memory not necessarily released immediately after process kill : kernel may delay reclaim, or other processes still using shared memory.
Swap usage doesn't necessarily mean memory shortage : kernel may proactively swap out inactive pages to make room for active pages.
Overall Troubleshooting Approach
Troubleshooting Flow
Discover memory issue
↓
Check system-level memory status (/proc/meminfo)
↓
Determine cause of memory shortage (user processes, kernel, cache)
↓
Locate specific process (/proc/$PID/status, smaps)
↓
Analyze process memory distribution (heap, stack, shared libraries, anonymous pages)
↓
Determine optimization or reclaim solution
↓
Verify effectAnalysis Dimensions
Total Analysis : system total memory, used, available, cache
Distribution Analysis : user space, kernel space, cache, slab
Process Analysis : each process's RSS, PSS, USS
Memory Mapping Analysis : heap, stack, shared libraries, anonymous pages, file pages
Trend Analysis : memory growth trend, leak characteristics
Practical Steps
Step 1: Check System-Level Memory Status
Read /proc/meminfo
cat /proc/meminfoExpected Output (partial):
MemTotal: 65536000 kB
MemFree: 2048000 kB
MemAvailable: 32768000 kB
Buffers: 1024000 kB
Cached: 28672000 kB
SwapCached: 512000 kB
Active: 45056000 kB
Inactive: 12288000 kB
Active(anon): 18432000 kB
Inactive(anon): 4096000 kB
Active(file): 26624000 kB
Inactive(file): 8192000 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 16384000 kB
SwapFree: 12288000 kB
Dirty: 256000 kB
Writeback: 4000 kB
AnonPages: 20480000 kB
Mapped: 8192000 kB
Shmem: 2048000 kB
Slab: 4096000 kB
SReclaimable: 3072000 kB
SUnreclaim: 1024000 kB
KernelStack: 128000 kB
PageTables: 512000 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 49152000 kB
Committed_AS: 81920000 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 256000 kB
VmallocChunk: 34359482367 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 524288 kB
DirectMap2M: 66060288 kBKey Field Explanations
A detailed table explains each field's meaning, unit, and judgment logic. Key fields include: MemTotal: total physical memory (fixed) MemFree: completely free memory (excludes cache/buffer) MemAvailable: available memory including reclaimable cache (more accurate than MemFree) Buffers: block device buffers (usually small) Cached: page cache (filesystem cache, reclaimable) SwapCached: pages swapped out then back in but still in swap Active/Inactive: active/inactive memory (recently accessed vs reclaimable) Active(anon)/Inactive(anon): active/inactive anonymous pages (process heap/stack; inactive anon can swap out) Active(file)/Inactive(file): active/inactive file pages (file cache, reclaimable; inactive file prioritized for reclaim) Unevictable: non-reclaimable memory (mlocked pages) SwapTotal/SwapFree: swap total and free Dirty/Writeback: dirty pages (modified not written) and writeback pages AnonPages: total anonymous pages (process heap/stack) Mapped: memory mapped to user space (includes shared libraries) Shmem: shared memory (tmpfs, IPC shared memory) Slab/SReclaimable/SUnreclaim: slab allocator memory (kernel object cache; reclaimable vs unreclaimable) KernelStack: kernel stack (~8KB per thread) PageTables: page table usage (related to process count and memory size) Committed_AS: allocated virtual memory (may exceed physical) VmallocUsed: vmalloc usage (kernel modules, drivers)
Quick Memory Status Judgment
awk '
/MemTotal/ {total=$2}
/MemAvailable/ {avail=$2}
/MemFree/ {free=$2}
/Cached/ {cached=$2}
/Buffers/ {buffers=$2}
/Slab/ {slab=$2}
/SwapTotal/ {swap_total=$2}
/SwapFree/ {swap_free=$2}
END {
print "Total:", int(total/1024), "MB"
print "Available:", int(avail/1024), "MB", "("int(avail/total*100)"%%)"
print "Free:", int(free/1024), "MB"
print "Cache:", int((cached+buffers)/1024), "MB"
print "Slab:", int(slab/1024), "MB"
print "Swap Used:", int((swap_total-swap_free)/1024), "MB", "/"int(swap_total/1024), "MB"
if (avail/total < 0.1) print "WARNING: Available memory < 10%"
if (swap_total > 0 && (swap_total-swap_free)/swap_total > 0.5) print "WARNING: Swap usage > 50%"
}' /proc/meminfoExpected Output:
Total: 64000 MB
Available: 32000 MB (50%)
Free: 2000 MB
Cache: 29000 MB
Slab: 4000 MB
Swap Used: 4000 MB /16000 MBJudgment Logic: MemAvailable < 10%: memory pressure, may trigger OOM Cached large: can try clearing cache but usually unnecessary; kernel auto-reclaims Slab > 10% MemTotal: kernel object usage high, check for kernel module leaks Swap usage > 50%: may impact performance, check for abnormal processes
Step 2: Analyze Active and Inactive Memory
Active/inactive memory distribution determines system reclaim strategy. grep -E "Active|Inactive" /proc/meminfo Expected Output:
Active: 45056000 kB
Inactive: 12288000 kB
Active(anon): 18432000 kB
Inactive(anon): 4096000 kB
Active(file): 26624000 kB
Inactive(file): 8192000 kBJudgment Logic: Inactive(file) easiest to reclaim; kernel prioritizes reclaiming this Inactive(anon) needs swap space to reclaim; cannot reclaim without swap Active(anon) large and MemAvailable small: process anonymous pages high, possible process memory leak
Check Memory Reclaim Priority
cat /proc/vmstat | grep -E "pgsteal|pgscan|pgfault"Expected Output:
pgfault 12345678
pgmajfault 123456
pgscan_kswapd_normal 234567
pgscan_direct_normal 123
pgsteal_kswapd_normal 234000
pgsteal_direct_normal 100Field Meanings: pgfault: total page faults (minor fault, data in memory) pgmajfault: major page faults (need disk read) pgscan_kswapd_normal: pages scanned by background reclaim pgscan_direct_normal: pages scanned by direct reclaim (process blocks) pgsteal_kswapd_normal: pages reclaimed by background pgsteal_direct_normal: pages reclaimed by direct reclaim
Judgment Logic: pgscan_direct_normal continuously growing: severe memory shortage, processes block waiting for reclaim, performance degrades pgmajfault high: frequent disk reads, possibly high swap usage or insufficient cache
Step 3: Locate Processes Consuming Most Memory
topshows process RSS but RSS includes shared memory, not precise enough. Use /proc for more accurate info.
Sort by RSS
ps aux --sort=-rss | head -20Or directly read /proc:
for pid in $(ls /proc | grep -E '^[0-9]+$'); do
if [ -f "/proc/$pid/status" ]; then
rss=$(awk '/^VmRSS:/ {print $2}' /proc/$pid/status)
name=$(awk '/^Name:/ {print $2}' /proc/$pid/status)
echo "$rss $name $pid"
fi
done | sort -rn | head -20Expected Output:
10485760 java 12345
5242880 python 23456
2621440 mysqld 34567Unit is kB.
Understand RSS, PSS, USS Differences
RSS (Resident Set Size) : physical memory used by process, includes shared libraries
PSS (Proportional Set Size) : RSS proportionally divided; shared libraries split by number of using processes
USS (Unique Set Size) : process-private memory, excludes shared portions
Example: Process A and B both use libc.so (10MB):
A RSS = A private + 10MB
B RSS = B private + 10MB
A PSS = A private + 10MB/2 = A private + 5MB
B PSS = B private + 10MB/2 = B private + 5MB
A USS = A private
B USS = B private
Calculate PSS:
pid=12345
awk '/^Pss:/ {sum += $2} END {print sum " kB"}' /proc/$pid/smapsCalculate USS:
pid=12345
awk '/^Private/ {sum += $2} END {print sum " kB"}' /proc/$pid/smapsCompare RSS, PSS, USS:
pid=12345
echo "PID: $pid"
awk '/^VmRSS:/ {print "RSS:", $2, "kB"}' /proc/$pid/status
awk '/^Pss:/ {sum += $2} END {print "PSS:", sum, "kB"}' /proc/$pid/smaps
awk '/^Private/ {sum += $2} END {print "USS:", sum, "kB"}' /proc/$pid/smapsExpected Output:
PID: 12345
RSS: 10485760 kB
PSS: 8388608 kB
USS: 7340032 kBUSS is process's real memory usage; PSS accounts for sharing; RSS is most conservative estimate (may double-count).
Step 4: Analyze Process Memory Distribution
/proc/$PID/smapsprovides detailed process memory mapping info, showing each memory segment's attributes.
Read smaps
pid=12345
cat /proc/$pid/smaps | head -50Expected Output (partial):
00400000-00500000 r-xp 00000000 08:01 12345678 /usr/bin/python3.9
Size: 1024 kB
Rss: 512 kB
Pss: 256 kB
Shared_Clean: 256 kB
Shared_Dirty: 0 kB
Private_Clean: 256 kB
Private_Dirty: 0 kB
Referenced: 512 kB
Anonymous: 0 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
ShmemPmdMapped: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me dw sd
7f1234567000-7f1234678000 rw-p 00000000 00:00 0 [heap]
Size: 1024 kB
Rss: 1024 kB
Pss: 1024 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 1024 kB
Referenced: 1024 kB
Anonymous: 1024 kB
...Field Meanings:
First line: address range, permissions (r=read, w=write, x=execute, p=private, s=shared), offset, device, inode, file path or segment name Size: virtual memory size Rss: actual physical memory used Pss: proportionally divided physical memory Shared_Clean: shared unmodified pages Shared_Dirty: shared modified pages Private_Clean: private unmodified pages Private_Dirty: private modified pages Anonymous: anonymous pages (heap, stack) Swap: size swapped out to swap
Common Segment Names: [heap]: heap [stack]: stack [vdso]: virtual dynamic shared object /lib/xxx.so: shared libraries /usr/bin/xxx: executable files
Unnamed: anonymous memory mappings (mmap allocations)
Stat Memory Distribution
Count heap, stack, shared libraries, anonymous pages:
pid=12345
cat /proc/$pid/smaps | awk '
/^[0-9a-f]/ {
seg = $6
if (seg == "[heap]") type = "heap"
else if (seg == "[stack]") type = "stack"
else if (seg ~ /\.so/) type = "shlib"
else if (seg == "") type = "anon"
else type = "other"
}
/^Rss:/ {
rss[type] += $2
}
END {
print "Heap:", rss["heap"], "kB"
print "Stack:", rss["stack"], "kB"
print "Shared Libs:", rss["shlib"], "kB"
print "Anonymous:", rss["anon"], "kB"
print "Other:", rss["other"], "kB"
}'Expected Output:
Heap: 5242880 kB
Stack: 8192 kB
Shared Libs: 2097152 kB
Anonymous: 1048576 kB
Other: 524288 kBJudgment Logic:
Heap large: possible memory leak or business needs large memory
Stack large: possible deep recursion or large stack arrays
Shared libs large: many libraries loaded but usually shared, not a concern
Anonymous mappings large: possibly using mmap for large allocations
Find Largest Memory Segment
pid=12345
cat /proc/$pid/smaps | awk '
/^[0-9a-f]/ {
addr = $1
perm = $2
file = $6
}
/^Rss:/ {
rss = $2
if (rss > max_rss) {
max_rss = rss
max_addr = addr
max_perm = perm
max_file = file
}
}
END {
print "Largest segment:"
print " Address:", max_addr
print " Perm:", max_perm
print " RSS:", max_rss, "kB"
print " File:", max_file
}'Expected Output:
Largest segment:
Address: 7f1234567000-7f1244567000
Perm: rw-p
RSS: 3145728 kB
File: [heap]If largest segment is heap and RSS abnormally large, possible memory leak.
Step 5: Analyze Swap Usage
High swap usage degrades performance; need to find which processes or pages swapped out.
Check System Swap Status
grep -E "Swap" /proc/meminfoExpected Output:
SwapCached: 512000 kB
SwapTotal: 16384000 kB
SwapFree: 12288000 kBCalculate Swap Usage Rate:
Swap usage = (SwapTotal - SwapFree) / SwapTotal * 100%Check Each Process's Swap Usage
for pid in $(ls /proc | grep -E '^[0-9]+$'); do
if [ -f "/proc/$pid/status" ]; then
swap=$(awk '/^VmSwap:/ {print $2}' /proc/$pid/status)
name=$(awk '/^Name:/ {print $2}' /proc/$pid/status)
if [ "$swap" -gt 0 ] 2>/dev/null; then
echo "$swap $name $pid"
fi
fi
done | sort -rn | head -20Expected Output:
2097152 java 12345
1048576 python 23456
524288 mysqld 34567Unit is kB.
Judgment Logic:
Single process swap large: process inactive long time, swapped out
Multiple processes swap large: system memory severely insufficient, frequent paging
Check Which Memory Segments Swapped Out
pid=12345
cat /proc/$pid/smaps | awk '
/^[0-9a-f]/ {addr = $1; file = $6}
/^Swap:/ {
swap = $2
if (swap > 0) {
total_swap += swap
print addr, file, swap, "kB"
}
}
END {print "Total Swap:", total_swap, "kB"}'Expected Output:
7f1234567000-7f1244567000 [heap] 1048576 kB
7f1244568000-7f1254568000 (anon) 524288 kB
Total Swap: 1572864 kBJudgment Logic:
Heap swapped out: process not accessing heap memory for long time
Stack swapped out: thread inactive long time
Shared libs swapped out: rare, indicates extreme memory pressure
Step 6: Analyze Kernel Memory Usage
Kernel memory includes Slab, kernel stack, page tables, etc., not directly usable by user processes.
Check Slab Statistics
cat /proc/slabinfo | head -20Expected Output:
slabinfo - version: 2.1
# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
kmalloc-8192 256 256 8192 4 8 : tunables 0 0 0 : slabdata 64 64 0
kmalloc-4096 1024 1024 4096 8 8 : tunables 0 0 0 : slabdata 128 128 0
dentry 50000 52000 192 40 2 : tunables 0 0 0 : slabdata 1300 1300 0
inode_cache 30000 32000 608 13 2 : tunables 0 0 0 : slabdata 2462 2462 0Field Meanings: name: slab cache name active_objs: active object count num_objs: total object count objsize: object size (bytes) active_slabs: active slab count
Calculate Slab Usage:
cat /proc/slabinfo | awk 'NR > 2 {sum += $3 * $4} END {print sum / 1024 / 1024, "MB"}'Judgment Logic:
Slab usage > 10% MemTotal: kernel object usage high dentry, inode_cache large: filesystem cache high, usually normal
Uncommon slab large: possible kernel module or driver leak
Check Kernel Stack Usage
grep KernelStack /proc/meminfoExpected Output: KernelStack: 128000 kB Judgment Logic:
Each thread uses ~8KB kernel stack
KernelStack large: many threads; calculate thread count: 128000 / 8 = 16000 threads
Check Page Table Usage
grep PageTables /proc/meminfoExpected Output: PageTables: 512000 kB Judgment Logic:
Page table usage related to process count and virtual memory size
Page tables > 1% MemTotal: many processes or large virtual memory
Step 7: Trace Memory Leaks
Memory leaks manifest as continuous process memory growth without business justification.
Continuous Process Memory Monitoring
pid=12345
while true; do
timestamp=$(date +%s)
rss=$(awk '/^VmRSS:/ {print $2}' /proc/$pid/status 2>/dev/null)
if [ -n "$rss" ]; then
echo "$timestamp $rss"
else
echo "Process exited"
break
fi
sleep 60
done > /tmp/mem_monitor_$pid.logAfter running, plot trend:
awk '{print $1, $2/1024}' /tmp/mem_monitor_12345.log | gnuplot -e "
set terminal png size 800,600;
set output '/tmp/mem_trend.png';
set xlabel 'Time (s)';
set ylabel 'RSS (MB)';
plot '-' using 1:2 with lines title 'RSS'
"Or simple observation:
awk '{print $1, $2/1024}' /tmp/mem_monitor_12345.log | tail -20Judgment Logic:
RSS continuous linear growth: obvious memory leak
RSS step-like growth: possibly cache or batch processing, not necessarily leak
RSS grows then stabilizes: business logic needs, not leak
Compare Heap Memory Growth
pid=12345
while true; do
timestamp=$(date +%s)
heap_rss=$(cat /proc/$pid/smaps 2>/dev/null | awk '/^[0-9a-f].*\[heap\]/{getline; if (/^Rss:/) print $2}')
if [ -n "$heap_rss" ]; then
echo "$timestamp $heap_rss"
else
echo "Process exited"
break
fi
sleep 60
done > /tmp/heap_monitor_$pid.logIf heap memory continuously grows, likely heap memory leak.
Use valgrind or gdb to Locate Leak Points
This is beyond /proc scope, but if leak confirmed, use professional tools:
valgrind --leak-check=full --log-file=/tmp/valgrind.log ./your_program
gdb -p 12345
(gdb) info proc mappings
(gdb) dump memory /tmp/heap.dump 0x7f1234567000 0x7f1244567000Step 8: Clear Memory Cache (Caution)
If Cache/Buffer confirmed excessive, can manually clear but usually unnecessary; kernel auto-reclaims.
Clear Page Cache
sync
echo 1 > /proc/sys/vm/drop_cachesRisk Warning: After clearing, filesystem access slows as files re-read from disk. Only use when cache usage confirmed abnormal.
Clear dentry and inode Cache
sync
echo 2 > /proc/sys/vm/drop_cachesClear All Caches
sync
echo 3 > /proc/sys/vm/drop_cachesPre-check Before Operation
free -m
cat /proc/meminfo | grep -E "Cached|Buffers"Post-operation Verification
free -mJudgment Logic:
After clearing, MemAvailable significantly increases: cache was indeed excessive
After clearing, MemAvailable barely changes: cache not the problem
Common Commands
System Memory Summary
cat /proc/meminfo | grep -E "MemTotal|MemAvailable|MemFree|Cached|SwapTotal|SwapFree|Slab"All Process Memory Usage
ps aux --sort=-rss | head -20
top -b -n 1 -o %MEM | head -20Process Detailed Memory Info
pid=12345
cat /proc/$pid/status | grep -E "Vm"
cat /proc/$pid/smaps_rollup
cat /proc/$pid/mapsCalculate Process PSS
pid=12345
awk '/^Pss:/ {sum += $2} END {print "PSS:", sum, "kB"}' /proc/$pid/smapsView Process Memory Segments
pid=12345
cat /proc/$pid/mapsView Process Open Files
pid=12345
ls -l /proc/$pid/fd
lsof -p $pidSystem Memory Usage Trend
sar -r 1 10
vmstat 1 10OOM Killer Logs
dmesg -T | grep -i "out of memory"
grep -i "killed process" /var/log/syslogPage Reclaim Statistics
cat /proc/vmstat | grep -E "pgsteal|pgscan"Memory Fragmentation
cat /proc/buddyinfo
cat /proc/pagetypeinfoConfiguration Examples
Adjust Kernel Memory Reclaim Strategy
cat /proc/sys/vm/swappiness
echo 10 > /proc/sys/vm/swappinessswappinessrange 0-100, higher values favor swap:
0: avoid swap as much as possible
10: less swap (recommended for servers)
60: default
100: aggressive swap
Make Permanent:
echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl -pAdjust Dirty Page Writeback Strategy
cat /proc/sys/vm/dirty_ratio
cat /proc/sys/vm/dirty_background_ratio
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratiodirty_ratio: when dirty pages exceed this % of available memory, processes block waiting for writeback dirty_background_ratio: when dirty pages exceed this %, background writeback starts
Make Permanent:
echo "vm.dirty_ratio=10" >> /etc/sysctl.conf
echo "vm.dirty_background_ratio=5" >> /etc/sysctl.conf
sysctl -pAdjust OOM Killer Strategy
cat /proc/sys/vm/overcommit_memory
echo 2 > /proc/sys/vm/overcommit_memoryovercommit_memoryoptions:
0: default, kernel decides whether to allow overcommit
1: always allow overcommit
2: disallow allocations exceeding CommitLimit Make Permanent:
echo "vm.overcommit_memory=2" >> /etc/sysctl.conf
sysctl -pSet Process OOM Priority
Each process has oom_score_adj parameter, range -1000 to 1000; higher values more likely to be killed by OOM Killer.
pid=12345
cat /proc/$pid/oom_score_adj
echo -500 > /proc/$pid/oom_score_adjJudgment Logic:
-1000: never killed by OOM Killer (use with caution)
0: default
1000: most likely to be killed
For critical processes, set negative values to lower kill priority.
Log and Metric Observation Methods
Observe Memory Shortage Logs
dmesg -T | grep -i "memory"
grep -i "out of memory" /var/log/kern.log
journalctl -k | grep -i "oom"Typical Log:
[12345.678] Out of memory: Kill process 12345 (java) score 890 or sacrifice child
[12345.679] Killed process 12345 (java) total-vm:102400kB, anon-rss:51200kB, file-rss:2048kB, shmem-rss:0kBJudgment Logic: score 890: OOM score high, process uses lots of memory total-vm:102400kB: virtual memory size anon-rss:51200kB: anonymous page usage file-rss:2048kB: file page usage
Observe Memory Reclaim Logs
dmesg -T | grep -i "reclaim"
cat /proc/vmstat | grep -E "pgsteal|pgscan" | awk '{sum += $2; print $1, $2} END {print "Total:", sum}'Real-time Memory Status Monitoring
watch -n 1 "free -m && echo && cat /proc/meminfo | grep -E 'MemAvailable|Cached|Slab|SwapFree'"
watch -n 1 "ps aux --sort=-rss | head -10"Troubleshooting Paths
Scenario 1: System Memory Insufficient but top Shows free
Phenomenon: free -m Output:
total used free shared buff/cache available
Mem: 64000 45000 2000 1000 17000 16000
Swap: 16000 4000 12000freeonly 2000 MB but available 16000 MB.
Troubleshooting Steps:
Check buff/cache: cat /proc/meminfo | grep -E "Buffers|Cached". If Cached large, most "used" memory is cache, reclaimable.
Check SReclaimable: grep SReclaimable /proc/meminfo. If large, reclaimable Slab usage high.
Conclusion: system memory not truly insufficient; MemAvailable is accurate available memory indicator.
Scenario 2: Process RSS Small but Actual GPU Memory Large
Phenomenon: ps aux | grep python Output:
user 12345 0.5 2.0 10485760 1310720 ? Sl 10:00 5:32 python train.pyRSS only 1.3GB but nvidia-smi shows GPU memory 30GB.
Troubleshooting Steps:
Confirm RSS only counts CPU memory: cat /proc/12345/status | grep VmRSS GPU memory not in /proc, need separate check: nvidia-smi or cat /proc/driver/nvidia/gpus/*/information Conclusion: GPU memory managed by GPU driver, doesn't consume system memory; /proc cannot directly reflect it.
Scenario 3: OOM Killer Frequently Triggers
Phenomenon: dmesg -T | grep -i "killed process" Output:
[2026-09-09 10:00:00] Killed process 12345 (java)
[2026-09-09 10:05:00] Killed process 23456 (python)
[2026-09-09 10:10:00] Killed process 34567 (mysqld)Troubleshooting Steps:
Check if system memory truly insufficient: cat /proc/meminfo | grep -E "MemAvailable|SwapFree" Check killed process memory usage from logs: dmesg -T | grep -i "killed process" | tail -5 or record before next trigger: ps aux --sort=-rss > /tmp/ps_before_oom.log Check oom_score_adj for top processes
Adjust strategy: add physical memory, optimize apps, enable swap if memory truly insufficient; fix leak or restart process if leak; lower oom_score_adj for critical processes if mis-killed.
Scenario 4: High Swap Usage Causes Performance Degradation
Phenomenon: free -m shows Swap 75% used, system slow.
Troubleshooting Steps:
Find processes using most swap (script provided)
Check if these processes still active: top -p 12345,23456,34567 Decision: inactive processes normal; active processes frequently accessing swapped pages degrades performance — consider adding memory or lowering swappiness Temporarily release swap (risky): swapoff -a && swapon -a. Risk: if physical memory insufficient, disabling swap may trigger OOM.
Risk Warnings
1. Cache Clearing Causes Performance Degradation
Risk Scenario: Executing echo 3 > /proc/sys/vm/drop_caches causes application filesystem access slowdown.
Prevention: Only clear when cache usage confirmed abnormal; record cache size before/after; avoid clearing during business peak.
2. Kernel Parameter Changes Cause Instability
Risk Scenario: Modifying swappiness, overcommit_memory etc. causes frequent OOM or performance drop.
Prevention: Backup current values before changes; adjust gradually and observe; use sysctl -w for temporary changes, confirm stable before writing to /etc/sysctl.conf.
3. Misjudging Memory Leaks
Risk Scenario: RSS continuously growing judged as leak, but actually business logic needs (cache, preloading).
Prevention: Combine with business logic judgment; observe if RSS stabilizes at threshold; check heap/stack/shared library distribution.
4. Reading /proc Files Fails
Risk Scenario: Process exited, reading /proc/$pid/status fails; insufficient permissions to read some process /proc info.
Prevention: Check file existence before reading; use 2>/dev/null to ignore errors; use root privileges.
Verification Methods
Verify Memory Statistics Consistency
cat /proc/meminfo | awk '
/MemTotal/ {total=$2}
/MemFree/ {free=$2}
/Buffers/ {buffers=$2}
/Cached/ {cached=$2}
/Slab/ {slab=$2}
/AnonPages/ {anon=$2}
END {
used = total - free - buffers - cached
print "MemTotal:", total
print "Calculated Used:", used
print "Actual Used (free output):", total - free
print "Difference:", (total - free) - used
}'Verify Process Memory Statistics
pid=12345
rss=$(awk '/^VmRSS:/ {print $2}' /proc/$pid/status)
pss=$(awk '/^Pss:/ {sum += $2} END {print sum}' /proc/$pid/smaps)
uss=$(awk '/^Private/ {sum += $2} END {print sum}' /proc/$pid/smaps)
echo "RSS: $rss kB"
echo "PSS: $pss kB"
echo "USS: $uss kB"
echo "USS <= PSS <= RSS: $([ $uss -le $pss ] && [ $pss -le $rss ] && echo 'PASS' || echo 'FAIL')"Verify Cache Clearing Effect
cached_before=$(grep ^Cached: /proc/meminfo | awk '{print $2}')
echo 3 > /proc/sys/vm/drop_caches
cached_after=$(grep ^Cached: /proc/meminfo | awk '{print $2}')
echo "Before: $cached_before kB"
echo "After: $cached_after kB"
echo "Freed: $((cached_before - cached_after)) kB"Rollback Plans
Restore Kernel Parameters
sysctl -w vm.swappiness=60
sysctl -w vm.dirty_ratio=20
sysctl -w vm.dirty_background_ratio=10
sysctl -w vm.overcommit_memory=0Restore Process OOM Priority
pid=12345
echo 0 > /proc/$pid/oom_score_adjRe-enable Swap
swapon -a
swapon -sProduction Environment Considerations
1. Regular Memory Status Inspection
Create cron job to record key memory metrics:
crontab -e
*/10 * * * * cat /proc/meminfo | grep -E "MemAvailable|Cached|Slab|SwapFree" >> /var/log/mem_check.logWeekly review to identify abnormal trends.
2. Configure Memory Alerts
In monitoring system configure alerts:
MemAvailable < 10%Swap usage > 50%OOM Killer triggered3. Process Memory Limits
Use cgroup to limit process memory, prevent single process exhausting system memory:
cgcreate -g memory:/myapp
echo 10G > /sys/fs/cgroup/memory/myapp/memory.limit_in_bytes
cgexec -g memory:myapp /usr/bin/myapp4. Log Retention
OOM logs are key evidence; ensure sufficient retention:
grep -i "killed process" /var/log/syslog | wc -lIf logs rotated away, adjust logrotate config.
5. Memory Leak Monitoring
For known leak-prone apps, periodic restart or continuous monitoring tools.
6. Documentation and Knowledge Accumulation
Record each memory issue's troubleshooting process, root cause, solution; build Runbook.
Summary
The /proc filesystem is a powerful tool for Linux memory troubleshooting, providing fine-grained information that top, free cannot show. Core points include:
Understand Memory Classification : user space, kernel space, cache, slab, anonymous pages, file pages; different memory types have different reclaim strategies
Use Correct Metrics : MemAvailable more accurate than MemFree ; PSS more accurate than RSS
System to Process : first check /proc/meminfo for overall status, then /proc/$PID/ to locate specific process
Focus on Details : /proc/$PID/smaps provides detailed memory mapping info, showing heap, stack, shared library distribution
Track Trends : continuously monitor process memory to identify leak characteristics
Operate Cautiously : clearing cache, modifying kernel parameters, disabling swap all carry risks; assess impact before operations
Combine Tools : /proc is foundation; combine with valgrind , gdb , perf for deeper analysis
Continuous Optimization : memory issues usually accumulate gradually; need regular inspection and tuning
In actual troubleshooting, /proc provides objective, real-time information, but interpretation requires combining business logic and system behavior. Single metrics cannot explain entire problems; need cross-validation of multiple metrics to form complete fault profile.
Ultimately, root resolution of memory problems often lies in application layer, not operations. Operations engineers' responsibility: quickly locate issues, provide temporary mitigation, supply detailed on-site data to development teams, drive root-cause fixes.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.