LCA Performance Monitoring & Tuning 4 — Questions and Answers
Question 1: What does the Linux OOM killer do, and which /proc file stores each process's OOM score?
- It terminates processes to free memory; scores are in /proc/<pid>/oom_score (Correct answer)
- It pauses processes until memory is available; scores are in /proc/<pid>/status
- It logs memory errors to syslog; scores are in /proc/meminfo
- It moves processes to swap; scores are in /proc/<pid>/smaps
Correct answer: It terminates processes to free memory; scores are in /proc/<pid>/oom_score
When memory is exhausted, the OOM killer selects a victim using /proc/<pid>/oom_score and kills it.
Question 2: Which tool provides a flame graph-compatible call-stack profiler for on-CPU and off-CPU analysis in Linux?
- perf record + perf script (Correct answer)
- strace -c
- valgrind --callgrind
- gprof
Correct answer: perf record + perf script
perf record captures stack samples; perf script outputs them for flame graph generation with stackcollapse tools.
Question 3: What kernel parameter controls the maximum number of open file descriptors system-wide?
- fs.file-max (Correct answer)
- kernel.pid_max
- vm.max_map_count
- net.core.somaxconn
Correct answer: fs.file-max
fs.file-max sets the kernel-wide limit on open file handles; per-process limits are set via ulimit.
Question 4: Which command shows memory usage broken down by shared, private, and anonymous mappings for a specific process?
- cat /proc/<pid>/smaps
- pmap -x <pid>
- Both /proc/<pid>/smaps and pmap -x provide this detail (Correct answer)
- free -m
Correct answer: Both /proc/<pid>/smaps and pmap -x provide this detail
Both /proc/<pid>/smaps and pmap -x <pid> show detailed per-mapping memory breakdown including shared and private pages.
Question 5: What does enabling Transparent Huge Pages (THP) do and when might you disable it?
- THP automatically uses 2MB pages to reduce TLB misses; disable it for databases that manage memory themselves to avoid latency spikes (Correct answer)
- THP compresses pages to save RAM; disable it on systems with no swap
- THP pins pages in RAM; disable it on low-memory systems
- THP enables NUMA balancing; disable it on single-socket systems
Correct answer: THP automatically uses 2MB pages to reduce TLB misses; disable it for databases that manage memory themselves to avoid latency spikes
THP reduces TLB pressure but can cause latency spikes during compaction; databases like Redis and MongoDB recommend disabling it.
Question 6: Which sysctl tunable directly reduces the time the kernel waits before writing dirty pages to disk?
- vm.dirty_writeback_centisecs (Correct answer)
- vm.dirty_ratio
- vm.dirty_background_ratio
- vm.swappiness
Correct answer: vm.dirty_writeback_centisecs
vm.dirty_writeback_centisecs sets the interval (in centiseconds) at which the kernel's flush threads wake to write dirty pages.
Question 7: What is the effect of setting /proc/sys/kernel/sched_migration_cost_ns to a higher value?
- The scheduler is less likely to migrate tasks between CPUs, improving cache locality at the cost of load balance speed (Correct answer)
- Tasks migrate more frequently, improving CPU utilization
- The scheduler increases the time slice for each task
- Context switches happen less often overall
Correct answer: The scheduler is less likely to migrate tasks between CPUs, improving cache locality at the cost of load balance speed
A higher sched_migration_cost_ns makes migrations more expensive in the scheduler's cost model, favoring cache-hot execution.
What does the Linux OOM killer do, and which /proc file stores each process's OOM score?