| # Copyright 2021 The ChromiumOS Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| description "Start the Chromium OS Resource Manager daemon" | |
| author "chromium-os-dev@chromium.org" | |
| start on started system-services | |
| stop on stopping system-services | |
| # Minijail forks off the desired process. | |
| expect fork | |
| # If the job respawns 10 times in 10 seconds, stop trying. | |
| respawn | |
| respawn limit 10 10 | |
| # resourced handles low memory situations and shall not be OOM-killed. | |
| oom score never | |
| # Let the daemon crash if it grows too much. "as" is "address space" (VM | |
| # size). The typical VM size of resourced is about 14MB. Set the limit to | |
| # about 3x typical VM size. | |
| limit as 45000000 unlimited | |
| script | |
| # powercap does not exist on ARM devies, conditionally bind mount. | |
| POWER_CAP_MOUNT="" | |
| if [ -d "/sys/class/powercap" ]; then | |
| POWER_CAP_MOUNT="-b /sys/class/powercap,,1 " | |
| fi | |
| # The transparent huge page(THP) path exists when THP is enabled. | |
| THP_MOUNT="" | |
| if [ -d "/sys/kernel/mm/transparent_hugepage" ]; then | |
| THP_MOUNT="-b /sys/kernel/mm/transparent_hugepage,,1" | |
| fi | |
| # The sched debugfs path is used to tune the scheduler. Depending on the | |
| # kernel/scheduler used, the path might not exist. | |
| SCHED_MOUNT="" | |
| if [ -d "/sys/kernel/debug/sched" ]; then | |
| SCHED_MOUNT="-b /sys/kernel/debug/sched,,1" | |
| fi | |
| exec minijail0 \ | |
| --config /usr/share/minijail/resourced.conf \ | |
| --seccomp-bpf-binary /usr/share/policy/resourced-seccomp.policy.bpf \ | |
| ${POWER_CAP_MOUNT} \ | |
| ${THP_MOUNT} \ | |
| ${SCHED_MOUNT} \ | |
| -- /usr/bin/resourced | |
| end script | |
| tmpfiles /usr/lib/tmpfiles.d/on-demand/resourced.conf |