How Fast Does systemd Restart a Crashed Service? Restart=always vs on-failure, Measured — and the Crash Loop It Refuses
The documented 100ms default is a sleep before the restart, not the crash-to-restart time: the measured gap is 0.252 seconds, two and a half times the configured delay. Restart=on-failure restarts a service that exits 1 exactly like Restart=always does, and refuses only a clean exit. And the default start limit ends the loop after 5 restarts in 10 seconds, whether or not the service keeps failing.
Written November 10, 2026 · Tested with systemd 255 · 15 min read
- The table: the delay is a floor, and systemd adds 0.15 to 0.25 seconds on top
- The closest published work computed the timeline; this guide measured it
- The clean exit that on-failure refuses
- The crash loop systemd stops after five starts
What this guide is
Each arm is a transient systemd-run --user unit whose whole job is to log a timestamp and then exit: /bin/sh -c "date +%s.%N >> /tmp/restart-probe-2026-11-10/<arm>-r<rep>.log; exit 1", with Restart= and RestartSec= set per arm and the start limit disabled (StartLimitIntervalSec=0) for every timed arm so the limit never interferes with the timing. The measurement is the gap between consecutive start timestamps in the log — the crash-to-restart time as the service itself experiences it — and NRestarts from systemctl show cross-checks the count. The box runs systemd 255 under a user manager on WSL2 kernel 6.18.33.2.
The question is the one the policy pieces never answer with a number: when a service crashes, how long until it is running again, and what part of that time is the configured delay and what part is systemd itself. The manual says RestartSec= "configures the time to sleep before restarting a service" and defaults to 100ms, and the closest published work reads that sentence as the whole answer — a service that crashes is restarted 100ms later. The probe checks that reading by measuring, and it is wrong in the direction that matters: the sleep is a minimum, not the total, and at the default the part systemd adds is larger than the delay itself.
The answer in one line: with RestartSec=100ms, the measured crash-to-restart gap is 0.252 seconds, not 0.100; with RestartSec=1s it is 1.248 seconds; with RestartSec=5s it is 5.244 seconds. Restart=on-failure restarts an exit-1 service at 0.248 seconds, indistinguishable from always at 0.252. And with the defaults left alone, a service that crashes instantly is refused after 5 restarts in about 0.9 seconds, not after 10 seconds — the burst count binds, not the window.
The table: the delay is a floor, and systemd adds 0.15 to 0.25 seconds on top
Each arm median is the median of the three rep medians, so one wild rep cannot move it. Every timed rep returned rc=0 from the harness, every timestamp file counted exactly the lines NRestarts predicted, and the two control arms recorded exactly one line each with zero restarts.
Restart=always,RestartSec=100ms, exit 1: 0.2520 seconds (rep medians 0.2520, 0.2520, 0.2516; range 0.164 to 0.347 across 120 gaps). 40 restarts in 10 seconds, identical on all three reps. Overhead over the configured delay: +0.152 seconds.Restart=always,RestartSec=1s, exit 1: 1.2481 seconds (rep medians 1.2521, 1.2441, 1.2481; range 1.037 to 1.288 across 28 gaps). 9 to 10 restarts in 12 seconds. Overhead: +0.248 seconds.Restart=always,RestartSec=5s, exit 1: 5.2440 seconds (rep medians 5.2440, 5.1660, 5.2477; range 5.092 to 5.252 across 9 gaps). 3 restarts in 17 seconds. Overhead: +0.244 seconds.Restart=on-failure,RestartSec=100ms, exit 1: 0.2482 seconds (rep medians 0.2482, 0.2517, 0.2482; range 0.120 to 0.356 across 121 gaps). 40 to 41 restarts in 10 seconds. Overhead: +0.148 seconds.Restart=on-failure,RestartSec=100ms, exit 0: 0 restarts, 2 of 2 reps, exactly 1 timestamp line each. A clean exit does not restart underon-failure, as the manual states.Restart=no,RestartSec=100ms, exit 1: 0 restarts, 2 of 2 reps, exactly 1 timestamp line each. The default policy never restarts, whatever the exit code.
Three things to read carefully in the table. First, the overhead is not a rounding error: at the 100ms default it is 0.152 seconds, larger than the configured delay itself, so the measured gap is 2.52 times the number the configuration states. At 1 second the overhead is 0.248 seconds (1.25 times the configured delay) and at 5 seconds it is 0.244 seconds (1.05 times). The practical form of the finding is that RestartSec is a floor with roughly 0.15 to 0.25 seconds of systemd's own work on top of it, and the floor dominates only once the delay is several seconds.
Second, the 100ms arm's overhead is smaller than the 1s and 5s arms' — 0.152 seconds against 0.248 and 0.244 — and this probe does not establish why. The rep medians at 100ms agree to the millisecond (0.2516 to 0.2520), so the difference is stable, not noise, but the mechanism is not measured here: it could be timer behavior, scheduling, or the cost of forking the next process, and the guide does not pick one. What is established is the per-arm number, and any reader who needs the mechanism should measure with the process start traced, not infer it from these gaps.
Third, on-failure and always are the same arm for a crashing service. Their medians differ by 0.004 seconds (0.2482 against 0.2520), inside the rep-to-rep spread, and their restart counts are the same. The policies differ only on a clean exit, where on-failure refuses and always restarts. The manual's table says exactly this — on-failure restarts on an unclean exit code, always restarts regardless — and the probe confirms the timing is identical where both policies apply. A reader choosing between them for a crashing service is choosing policy, not speed.
The closest published work computed the timeline; this guide measured it
The closest published work is Michael Stapelberg's "systemd: enable indefinite service restarts" (2024). It states the systemd 255 defaults — DefaultRestartSec=100ms, DefaultStartLimitIntervalSec=10s, DefaultStartLimitBurst=5 — and works out what they mean for a service that takes 100ms to crash: first start at T+0, first crash at T+100ms, second start at T+200ms, second crash at T+300ms, and so on, with systemd giving up at T+1s after the fifth crash inside 10 seconds. Every step in that table is derived from the documented defaults. None of it is measured.
The measurement corrects the table in the direction the derivation cannot see. Stapelberg's second start lands 100ms after the first crash, because the derivation treats the configured delay as the whole gap. The measured second start lands 252ms after the first crash. His fifth crash lands at T+900ms and systemd gives up at T+1s; the measured loop reaches its fifth start in about 0.9 seconds — the four gaps in the trap arm are 0.180, 0.236, 0.256 and 0.252 seconds — and the refusal follows immediately. The shape of his table is right and the spacing is about two and a half times wider, because the derivation omits the overhead this probe measures. A reader who budgets recovery time from the computed table underestimates the crash-to-restart time by 0.15 seconds per restart at the default, and that error compounds across the four restarts before the limit trips.
The other near work is a policy proposal, not a measurement either. GNU Taler's design document DD 102 (draft, first published 2026-09-03) proposes a baseline of Restart=always with RestartSec=10s, StartLimitIntervalSec=0, and RestartPreventExitStatus=6 9, retrying indefinitely with a fixed ten-second delay, and it explicitly rejects systemd 257's increasing delay because the delay does not reset after the service has been healthy. It states the ten-second delay as the recovery time and never measures what a ten-second configured delay costs in practice. The pattern is clear: a 10s configured delay would cost about 10.24 seconds per restart, and the fixed-delay choice is a choice about backoff state, not about the gap itself.
The RestartSec policy explainers in general state the delay as the total — "waits 5 seconds before restarting" — and none of them runs a crashing service and times the gap. This guide is the measured table those pieces cite numbers for without measuring: the delay plus the overhead, per arm, with the counts cross-checked against NRestarts.
The clean exit that on-failure refuses
The first trap is the policy the manual states and the prose repeats without testing: Restart=on-failure restarts on a non-zero exit, and does not restart on a clean exit. The probe runs the same unit shape with exit 0 instead of exit 1, twice, and both reps record exactly one timestamp line and NRestarts=0. The unit starts, logs once, exits cleanly, and systemd leaves it alone.
The manual's rule is more precise than the one-sentence version, and the guide states the full rule because the edge cases are where the trap lives. Under on-failure, a clean exit means exit code 0, or — for services that are not Type=oneshot — one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, or any status listed in SuccessExitStatus=. A process killed by SIGTERM therefore does not restart under on-failure, and neither does one that exits 0 after deciding its work is done. Under always, both restart. The probe tests only the exit-0 case; it does not test the signal cases, and the guide does not claim numbers for them. The practical rule follows from the tested case plus the manual's table: if the service can exit cleanly on purpose — a finished batch job, a deliberate shutdown — on-failure is the policy that lets it stop, and always is the policy that restarts it anyway.
The crash loop systemd stops after five starts
The second trap is the default start limit, run with the limit left exactly as systemd ships it: StartLimitIntervalSec and StartLimitBurst untouched, Restart=always, RestartSec=100ms, exit 1. The probe's trap arm records 5 timestamp lines and NRestarts=5, and then the journal says, in order:
probe-start-limit-r1.service: Failed with result 'exit-code'.
probe-start-limit-r1.service: Scheduled restart job, restart counter is at 5.
probe-start-limit-r1.service: Start request repeated too quickly.
probe-start-limit-r1.service: Failed with result 'exit-code'.
Failed to start probe-start-limit-r1.service - /bin/sh -c "date +%s.%N >> /tmp/restart-probe-2026-11-10/start-limit-r1.log; exit 1".
The unit then sits failed and inactive until an operator runs systemctl reset-failed. The box's user manager confirms the defaults behind it: DefaultStartLimitBurst=5, and the manual's rule is that services started more than 5 times within 10 seconds are not permitted to start again until the interval ends. The five starts here complete in about 0.9 seconds — the four gaps are 0.180, 0.236, 0.256 and 0.252 seconds — so the burst count binds long before the 10-second window matters. A service that crashes instantly does not get 10 seconds of retries; it gets 4 restarts, and then it is failed.
Two consequences follow, both visible in the trap. First, the limit counts starts, not crashes: the initial start plus four restarts is five starts, and the next restart job is the one refused — the journal's "restart counter is at 5" counts that refused job as the fifth restart, which is why NRestarts reads 5 although only four restarts ever ran. Second, the failed state is sticky: nothing in the probe re-arms the unit, and systemctl reset-failed is the documented way back, alongside stopping and starting the unit. Stapelberg's fix is StartLimitIntervalSec=0 in the [Unit] section, which disables the limiter for that unit; Taler's DD 102 uses the same setting for the same reason. Both pieces treat the limit as the thing that must be disabled for indefinite recovery, and the trap shows why: with the defaults, indefinite recovery stops after four restarts in under a second.
One note on the trap's own evidence: the probe script runs systemctl stop and systemctl reset-failed after each arm as cleanup, so a systemctl show taken after the trap reports NRestarts=0 and Result=success — the cleanup erased the state. The journal lines above and the trap arm's own count (lines=5 nrestarts=5, recorded before cleanup) are the evidence, not the post-cleanup show output. The guide quotes the journal, not the cleaned state.
RestartSec is a minimum, not the total
The third trap is the headline finding stated as a rule: RestartSec= configures the time to sleep before restarting, and the sleep is only part of the gap. The measured overheads — +0.152 seconds at 100ms, +0.248 at 1s, +0.244 at 5s — are the part the configuration does not state. At the default, the overhead exceeds the delay; at 5 seconds it is a 5 percent correction. The error from treating the configured delay as the total therefore shrinks as the delay grows, and it is largest exactly where the default sits.
The practical form is a budgeting rule. If a service must be back within a deadline after a crash, budget the configured delay plus about a quarter of a second on this class of machine, not the delay alone. If the service crashes in a tight loop, the four restarts before the default limit trips take about 0.9 seconds at the default delay, not the 0.4 seconds the configured numbers imply — four gaps of 0.1 seconds would be 0.4 seconds, and the measured gaps sum to 0.924 seconds. And if the delay is the recovery mechanism itself, as in Taler's 10-second fixed policy, the measured pattern says the real recovery time is the delay plus the same overhead, about 10.24 seconds, with the overhead a small fraction of the total at that scale.
The guide does not claim the overhead is the same on every machine. It is measured on one box — systemd 255, user manager, WSL2, a shell that logs a timestamp and exits — and the fork-and-exec cost of a real daemon's start will differ from a shell one-liner's. What transfers is the structure: the delay is a floor, the overhead is real and roughly constant across delays on one machine, and the default delay is the worst place to ignore it because the overhead is larger than the delay itself.
Checklist
- Before budgeting crash recovery from
RestartSec, add the overhead: at the 100ms default the measured gap is 0.252 seconds, not 0.100 — the delay is a floor, and systemd adds about 0.15 seconds at 100ms and about 0.25 seconds at 1s and 5s. - Before choosing
Restart=on-failurefor speed, check what it actually changes: for a service that exits 1 it restarts at 0.248 seconds, indistinguishable fromalwaysat 0.252 — the choice is policy for clean exits, not timing for crashes. - Before letting a service exit 0 under
Restart=always, check the policy:alwaysrestarts a clean exit,on-failuredoes not, and neither restarts anything underRestart=no. - Before relying on indefinite restarts with the defaults, check the start limit: an instantly crashing service is refused after 5 restarts in about 0.9 seconds, and the unit sits failed until
systemctl reset-failed— the burst count binds, not the 10-second window. - Before quoting a computed restart timeline, check whether it was measured: Stapelberg's T+200ms second start is derived from the documented defaults, and the measured second start is about T+252ms after the first crash.
- Before reusing these numbers, check the setup: systemd 255, user manager, WSL2 kernel 6.18.33.2, 32 CPUs, transient
systemd-run --userunits loggingdate +%s.%Nand exiting 1, wall-clock timestamps with five clock-jump gaps excluded.
Related guides on this site
- Copying a File Without read() and write() Is About Twice as Fast: sendfile vs copy_file_range vs splice, Measured
- Waking a Thread: pipe vs eventfd vs signalfd, Measured
- paste vs join, Measured: Fast by Position, Wrong by Key
- inotify vs Polling: Measured Wake Latency, Queue Overflow, and the Non-Recursive Trap
Sources
- systemd.service(5) Linux manual page — read 2026-11-10:
Restart=takesno,on-success,on-failure,on-abnormal,on-watchdog,on-abortoralways;on-failurerestarts on a non-zero exit code, a terminating signal, an operation timeout or a watchdog timeout, and "setting this to on-failure is the recommended choice for long-running services";RestartSec="configures the time to sleep before restarting a service" and "defaults to 100ms"; restart is "subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=". The primary source for the policy and the delay. - Michael Stapelberg, systemd: enable indefinite service restarts — read 2026-11-10: the systemd 255 defaults are
DefaultRestartSec=100ms,DefaultStartLimitIntervalSec=10s,DefaultStartLimitBurst=5; "services which specify Restart=always are restarted 100ms after they crash, and if the service crashes more than 5 times in 10 seconds, systemd does not attempt to restart the service anymore"; the computed timeline puts the second start at T+200ms and systemd giving up at T+1s. The closest published work; a computed timeline from documented defaults, not a measurement. - GNU Taler, DD 102: systemd service restart policy — read 2026-11-10: draft, first published 2026-09-03; "the proposed policy retries indefinitely with a fixed ten-second delay" with
Restart=always,RestartSec=10s,StartLimitIntervalSec=0,RestartPreventExitStatus=6 9; systemd 257's increasing delay "does not reset that delay after the service has been healthy for a long time"; alert threshold "three restarts within fifteen minutes". A policy proposal with no measurements. - Veldica, systemd Timers vs Cron: What Actually Happens When a Run Is Missed — the sibling guide: the same user manager, the same WSL clock-jump artifact excluded from its counts, and the timer-side answer to the scheduling question this guide answers for restarts. This guide measures crash-to-restart; it does not re-teach the timer table.
- Veldica, systemd Unit Checker — the sibling tool: checks a unit file for the configuration mistakes that make a restart policy silently wrong, including the start-limit settings this guide measures. This guide measures the behavior; the tool checks the configuration.
Keep Exploring
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.
Paste sshd -G output and get a hardening verdict on the values your server actually runs.
Paste a server block and get WebSocket, TLS, HSTS, and proxy-header verdicts.
Paste a systemd timer expression and get the specific reason it fails, the normalized form, and the past-date traps the built-in check hides.
The full sysadmin hub \u2014 systemd, cgroups, file tools, and measured Linux comparisons.