0Pricing
Linux Command Line Mastery · Lesson

Memory and CPU Performance Tools

Utilize tools like `vmstat`, `sar`, and `mpstat` to diagnose CPU and memory related performance issues.

Memory and CPU Performance Tools is a free Linux Command Line Mastery lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Diagnose Performance Issues

Understanding system performance is key to troubleshooting slow applications or an unresponsive server. CPU and memory are often the first resources to check.

In this lesson, we'll explore powerful command-line tools to monitor and diagnose issues related to your system's CPU and memory usage.

Meet `vmstat`

The vmstat (virtual memory statistics) command provides a quick, real-time snapshot of your system's activity. It reports on processes, memory, paging, block I/O, traps, and CPU activity.

It's excellent for observing current system behavior and identifying immediate bottlenecks.

`vmstat` Memory Overview

Let's run vmstat 1 1 to see a single report, then we'll break down the memory-related output. This command shows a report every 1 second, for 1 iteration.

  • swpd: amount of virtual memory used.
  • free: amount of idle memory.
  • buff: memory used as buffers.
  • cache: memory used as cache.
vmstat 1 1

`vmstat` CPU Details

Now, let's look at the CPU section of vmstat. Run the command again if you like, and focus on the 'cpu' columns:

  • us (user): time spent running non-kernel code.
  • sy (system): time spent running kernel code.
  • id (idle): time spent idle.
  • wa (wait): time spent waiting for I/O.

High wa often indicates disk bottlenecks.

vmstat 1 1

Introducing `sar`

The sar (System Activity Reporter) command is part of the sysstat package. Unlike vmstat, sar can collect and report historical system activity data.

This makes it invaluable for long-term analysis, identifying trends, and diagnosing intermittent problems that might not be visible with real-time tools.

`sar` for CPU Usage

To view CPU utilization with sar, we use the -u option. Run sar -u 1 1 to get a single report.

  • %user: CPU usage by user-level applications.
  • %system: CPU usage by kernel-level tasks.
  • %iowait: Time CPU spent waiting for I/O.
  • %idle: Time CPU was idle.
sar -u 1 1

`sar` for Memory Usage

To get detailed memory utilization reports with sar, use the -r option. Try sar -r 1 1.

  • kbmemfree: Amount of free memory.
  • kbmemused: Amount of used memory.
  • %memused: Percentage of used memory.
  • kbbuffers: Memory used by kernel buffers.
  • kbcached: Memory used by page cache.
sar -r 1 1

Understanding `mpstat`

The mpstat (multi-processor statistics) command is also part of the sysstat package. Its main advantage is providing per-processor or per-core CPU activity.

This is crucial for systems with multiple CPU cores, as it helps identify if a specific core is overloaded while others are idle.

`mpstat` Per-Core Activity

To see statistics for all individual CPU cores, use mpstat -P ALL 1 1. You'll see a separate line for each core (CPU 0, CPU 1, etc.) and an 'all' line for the average.

This helps pinpoint if a single-threaded application is maxing out one core, even if overall CPU usage seems low.

mpstat -P ALL 1 1

Performance Tool Check

Which of the following statements about Linux performance tools are TRUE?

Recap: CPU & Memory Tools

In this lesson, you learned about three essential tools for monitoring CPU and memory performance:

  • vmstat: For real-time system activity snapshots.
  • sar: For collecting and reporting historical system activity data.
  • mpstat: For detailed per-processor/per-core CPU usage.

Mastering these commands will significantly boost your ability to diagnose and troubleshoot Linux system performance issues.

Frequently asked questions

Is the “Memory and CPU Performance Tools” lesson free?

Yes — the full text of “Memory and CPU Performance Tools” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Memory and CPU Performance Tools”?

Utilize tools like `vmstat`, `sar`, and `mpstat` to diagnose CPU and memory related performance issues. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Command Line Mastery?

No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Memory and CPU Performance Tools” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Command Line Mastery lesson?

Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Disk I/O Monitoring: `iostat`, `iotop`
  2. Memory and CPU Performance Tools
  3. Advanced Logging and Troubleshooting Techniques
  4. Tracing System Calls with strace and ltrace
← Back to Linux Command Line Mastery