Systemd Resource Limits Calculator

Configure and generate Systemd cgroups resource control unit directives (MemoryMax, CPUQuota, TasksMax, OOMScoreAdjust) and runtime systemctl set-property commands.

How to Configure Systemd Resource Control Limits

1

Input Service Limits

Set target CPU cores, maximum RAM (`MemoryMax`), and task limits for your Linux service.

2

Real-time Generation

The calculator generates systemd unit file directives (`CPUQuota=200%`) and live CLI commands.

3

Copy Configuration

Click Copy on the unit file snippet or paste `systemctl set-property` into your server terminal.

Tool Options

CPUQuota & Core Conversion

Automatically calculates CPUQuota percentage values from fractional or whole CPU core counts.

MemoryMax & OOM Tuning

Configures RAM hard limits and tunes Linux kernel Out-Of-Memory score adjustments (-1000 to 1000).

Live systemctl CLI Output

Generates production unit file blocks alongside executable systemctl set-property commands.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the Systemd Resource Limits Calculator do?

The Systemd Resource Limits Calculator helps Linux sysadmins, SREs, and DevOps engineers configure cgroups resource control directives (MemoryMax, MemoryHigh, CPUQuota, TasksMax, OOMScoreAdjust) for Linux services and user slices. It outputs production [Service] unit file blocks and live systemctl set-property CLI commands.

Core Concepts

Understanding Systemd Cgroups Resource Directives:

  • MemoryMax: Hard memory limit for the unit cgroup. Exceeding this limit triggers the Linux kernel Out-of-Memory (OOM) killer.
  • CPUQuota: Assigns a percentage of CPU execution time (e.g. 200% grants 2 full CPU cores).
  • TasksMax: Limits maximum number of concurrent tasks/threads in the cgroup (prevents fork bombs).
  • OOMScoreAdjust: Adjusts OOM killer preference (-1000 makes process immune to OOM, 1000 makes it first choice for termination).

How to use the tool?

  1. Input Service Limits: Enter target CPU cores, RAM limits (MemoryMax), and task limits.
  2. Real-time Generation: The tool computes systemd directives (CPUQuota=200%) and live CLI commands.
  3. Copy Configuration: Click Copy on the unit file snippet or paste systemctl set-property into your server.

Related Developer Utilities

If you manage Linux infrastructure, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/linux/systemd-resource-calculator) to programmatically calculate systemd resource control directives.

API Request Parameters

Name Type Description Example
unitName String Target unit name. Default "my-service.service". "web-app.service"
cpuCores Number Target CPU core allocation. 2
memoryMax String Max memory limit string. "1G"
tasksMax String Max tasks limit string. "512"
oomScoreAdjust Number OOM score adjust (-1000 to 1000). 0
oomPolicy String OOM policy ("stop", "kill", "continue"). "stop"

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/linux/systemd-resource-calculator \
  -H "Content-Type: application/json" \
  -d '{
    "unitName": "web-app.service",
    "cpuCores": 2,
    "memoryMax": "1G",
    "tasksMax": "512"
  }'

Python

import requests

url = "https://blueutils.com/api/linux/systemd-resource-calculator"
payload = {
    "unitName": "web-app.service",
    "cpuCores": 2,
    "memoryMax": "1G",
    "tasksMax": "512"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "unitName": "web-app.service",
                "cpuCores": 2,
                "memoryMax": "1G",
                "tasksMax": "512"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/linux/systemd-resource-calculator"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether calculation succeeded. true
unitSnippet String Formatted [Service] unit configuration snippet. "[Service]\nMemoryMax=1G\nCPUQuota=200%\nTasksMax=512"
runtimeCommand String Executable systemctl set-property CLI commands. "sudo systemctl set-property web-app.service MemoryMax=1G..."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "unitName": "web-app.service",
  "directives": [
    "MemoryMax=1G",
    "CPUQuota=200%",
    "TasksMax=512"
  ],
  "unitSnippet": "[Service]\nMemoryMax=1G\nCPUQuota=200%\nTasksMax=512",
  "runtimeCommand": "sudo systemctl set-property web-app.service MemoryMax=1G\nsudo systemctl set-property web-app.service CPUQuota=200%\nsudo systemctl set-property web-app.service TasksMax=512"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid OOMScoreAdjust value. Must be an integer between -1000 (OOM immune) and 1000 (OOM first choice)."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to calculate Systemd Resource Limits?

Integrating the Systemd Resource Control API into automation tools provides key benefits:

  • Automated Service Hardening: Generate CPU and RAM limits for containerized Linux virtual machines automatically.
  • Ansible & Infrastructure Provisioning: Compute unit drop-in overrides during VM provisioning.

Native Usage

How to generate and apply systemd resource control limits programmatically across environments:

Node.js (JavaScript)

function buildSystemdLimits(unitName = 'my-service.service', memoryMax = '1G', cpuQuota = '200%') {
  return `sudo systemctl set-property ${unitName} MemoryMax=${memoryMax} CPUQuota=${cpuQuota}`;
}

console.log(buildSystemdLimits());

Linux (Bash Shell)

#!/bin/bash
UNIT="my-service.service"
sudo systemctl set-property "$UNIT" MemoryMax=1G CPUQuota=200% TasksMax=512

Python

def get_systemd_limits(unit="my-service.service", cpu_cores=2, mem="1G"):
    quota = f"{int(cpu_cores * 100)}%"
    return f"sudo systemctl set-property {unit} MemoryMax={mem} CPUQuota={quota}"

print(get_systemd_limits())

Java

public class SystemdLimitsBuilder {
    public static String buildLimitCmd(String unit, String memoryMax, String cpuQuota) {
        return "sudo systemctl set-property " + unit + " MemoryMax=" + memoryMax + " CPUQuota=" + cpuQuota;
    }

    public static void main(String[] args) {
        System.out.println(buildLimitCmd("my-service.service", "1G", "200%"));
    }
}

Frequently Asked Questions (FAQ)

How do I limit RAM usage for a systemd service?

Configure MemoryMax=1G in your [Service] unit block or execute sudo systemctl set-property my-service.service MemoryMax=1G at runtime.

What does CPUQuota=200% mean in Systemd?

CPUQuota=200% allocates up to 2 full CPU cores of execution time across all threads in the service cgroup.

How do I adjust the Linux OOM Killer score for critical systemd services?

Set OOMScoreAdjust=-1000 in your unit file to protect critical services from being killed during system memory exhaustion, or 1000 for disposable processes.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.