How to Completely Disable the ‘ondemand’ Service in Ubuntu Server

The ondemand.service is an initialization script in older and some specific LTS builds of Ubuntu Server that automatically configures the CPU frequency scaling governor to the “ondemand” setting upon boot. The ondemand governor dynamically scales CPU clock speeds up or down based on current system load to save power. While this is excellent for laptops or idle desktops, it introduces micro-latency as the CPU takes milliseconds to ramp up to maximum frequency when hit with a sudden spike in requests. For high-performance database servers (like PostgreSQL or Redis), real-time trading platforms, or virtualization hypervisors, administrators require the CPU to operate at maximum frequency constantly (the “performance” governor) to ensure absolute zero-latency execution.

This guide explains how to completely disable the ondemand service in Ubuntu Server, ensuring the system does not dynamically throttle CPU frequencies to save power.

Stop and Mask the Ondemand Service

To guarantee that the server boots and remains locked to maximum performance, we must stop the ondemand service and explicitly mask it to prevent systemd from invoking it during the boot sequence.

  1. Log into your Ubuntu Server via SSH using an account with sudo privileges.
  2. First, check if the service is currently running or queued:
    sudo systemctl status ondemand.service
  3. Stop the service immediately:
    sudo systemctl stop ondemand.service
  4. Next, disable the service to remove its symlinks from the systemd schedule:
    sudo systemctl disable ondemand.service
  5. For absolute certainty, explicitly mask the service. This symlinks the unit file to /dev/null, creating a hard block against it starting under any circumstances:
    sudo systemctl mask ondemand.service

Verify the Service Lockdown

By masking ondemand.service, you guarantee that the Ubuntu OS will silently skip the frequency scaling initialization, though you should manually ensure your governor is set to “performance” via cpufrequtils.

To verify the lockdown is successful, attempt to start the service manually:

sudo systemctl start ondemand.service

Systemd will return a fatal error stating that the unit is masked (e.g., Failed to start ondemand.service: Unit ondemand.service is masked). You can further verify your CPU’s current governor by executing cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor. If properly configured for a production database, the output should read performance rather than ondemand across all logical cores.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.