Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
DevOpsJune 23, 20264 min read

Linux performance power management: Tuning C-states and P-states

Master Linux performance power management by tuning C-states and P-states. Stop thermal throttling and stabilize your VPS energy consumption today.

linuxperformancevpskerneldevopspower-managementDockerCI/CD

I spent a week last month chasing a ghost in our production monitoring. Every Tuesday at 2:00 PM, a batch job would trigger, and one of our VPS nodes would experience a 15% drop in throughput, followed by a spike in latency. It wasn’t a memory leak or a locking issue; the CPU was simply downclocking to prevent overheating, killing our performance.

When you're running high-density workloads, default linux performance settings aren't always your friend. Most distributions ship with power-saving profiles that prioritize energy efficiency over consistent execution time. While that’s great for a laptop, it’s a recipe for disaster on a server running database workloads or real-time proxies.

Understanding the Power Management Stack

Before you start poking at the kernel, you need to understand what you're fighting. Your CPU manages power through two primary mechanisms:

  1. P-states (Performance States): These control the operating frequency and voltage. When the CPU is under load, it moves to a higher P-state (higher clock speed). When idle, it drops to a lower state to save power.
  2. C-states (Idle States): These are sleep states. C0 is the operating state. C1, C2, and so on are increasingly deep sleep states where the CPU shuts off various internal components to save power.

The problem is the latency penalty. When a core is in a deep C-state (like C6), it takes a non-trivial amount of time to wake up and start executing instructions. If your application is latency-sensitive, that "wakeup" time is pure overhead.

The Wrong Turn: Blindly Disabling Everything

My first instinct was to "turn it all off." I found a guide suggesting I add intel_idle.max_cstate=0 and processor.max_cstate=0 to the GRUB command line.

It worked, but it was a disaster. The server’s idle power consumption jumped by about 35 watts, and the fan noise became constant. The CPU was running at max frequency even when doing nothing. I had traded thermal throttling for an unnecessary electric bill and increased wear on the cooling system. Don't do this unless you're benchmarking a high-frequency trading engine.

Tuning P-states with cpufreq

Instead of disabling everything, you want to constrain the system. I prefer using the cpufreq subsystem to enforce a sane performance floor.

First, check your current governor:

Bash
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

If it’s set to powersave or ondemand, you’re likely seeing those performance swings. For a production server, I always switch to performance. It doesn’t mean the CPU runs at max clock 100% of the time, but it tells the kernel to prioritize responsiveness over power savings when making frequency transitions.

Bash
# Install cpufrequtils if not present
sudo apt install cpufrequtils

# Set the governor to performance for all cores
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

If you’re running heavy database workloads, you might also want to look into Linux Performance: Tuning HugePages for High-Traffic Docker Databases to complement these CPU-level tweaks.

Controlling C-states for Stability

If you still hit thermal limits, you don't need to disable all C-states. You just need to stop the CPU from entering the deepest, slowest-to-wake states.

Use cpupower to inspect what your CPU is doing:

Bash
sudo apt install linux-cpupower
sudo cpupower idle-info

You’ll see a list of states. If your workload is sensitive to jitter, you can disable the deepest C-state (usually C6 or C7) at runtime without a reboot:

Bash
# Disable C-state 3
sudo cpupower idle-set -d 3

This keeps the CPU ready to execute instructions almost instantly. I’ve found that disabling just the bottom two sleep states usually solves about 90% of the "latency spike" issues we see on our virtualized instances.

When to Stop Tuning

It’s easy to get lost in the weeds of kernel parameters. If you’re seeing consistent performance, stop. If you’re still seeing stalls, it might not be the CPU frequency at all. Sometimes, it’s the disk I/O queuing that causes the CPU to wait, which can look like a performance dip. In those cases, I’ve had better luck with Docker I/O throttling: Control container performance with Cgroup v2 than with any CPU power setting.

Remember, every server environment is different. A bare-metal box has more granular control than a VPS, where the hypervisor might be intercepting your requests anyway. If you're on a cloud VPS, your provider might be limiting your P-states regardless of what you set inside the guest OS.

I’m still experimenting with intel_pstate parameters on our newer Xeon nodes. Some of the newer kernels have introduced "energy_performance_preference" (EPP) values that provide a more nuanced way to balance power and performance than the old governor system. It’s worth a look if you’re on a kernel newer than 5.10.

Back to Blog

Similar Posts

DevOpsJune 22, 20264 min read

Optimizing Linux Boot Times: A Practical Guide for VPS

Optimizing Linux boot times is critical for VPS scaling. Learn how to use systemd-analyze to identify bottlenecks and speed up your server startup sequence.

Read more
Close-up of a smart socket with vibrant blue and pink neon lighting, showcasing modern technology.
DevOpsJune 21, 20264 min read

Systemd Timers: The Better Way to Handle Linux Automation

Systemd timers provide a robust, observable alternative to cron for Linux automation. Learn how to manage server maintenance tasks with native systemd features.

Read more
Close-up of software development tools displaying code and version control systems on a computer monitor.
DevOpsJune 20, 20264 min read

Deploying a side project on a single cheap VPS reliably

Deploying a side project on a single cheap VPS is the best way to master infrastructure. Learn to secure, automate, and manage your stack without breaking.

Read more