Configuration
Cgroups are configured in theconfig.toml file. Here’s the basic configuration structure:
Configuration Options
Main Cgroups Settings
-
count: Number of cgroup partitions to create. Gitaly will create this many cgroup slices to distribute Git processes across. Default: 10 -
mountpoint: The location where the cgroup filesystem is mounted. On most modern Linux systems, this is/sys/fs/cgroup. This should match your system’s cgroup mount point. -
hierarchy_root: The root name for Gitaly’s cgroup hierarchy. Gitaly will create its cgroups under this name within the cgroup filesystem. Default:"gitaly"
Memory Control
The[cgroups.memory] section configures memory limits for Git processes:
-
enabled: Set totrueto enable memory limiting via cgroups. Default:false -
limit: Memory limit in bytes for each cgroup partition. Git processes exceeding this limit may be terminated by the kernel’s OOM killer.
CPU Control
The[cgroups.cpu] section configures CPU resource allocation:
-
enabled: Set totrueto enable CPU limiting via cgroups. Default:false -
shares: CPU shares allocated to each cgroup partition. This is a relative weight; higher values give processes more CPU time when there is contention. The default Linux value is 1024.
How It Works
When cgroups are enabled:- Gitaly creates
countnumber of cgroup partitions at startup - Each Git process spawned by Gitaly is assigned to one of these cgroup partitions
- The Linux kernel enforces the resource limits defined in the cgroup configuration
- Processes are distributed across cgroup partitions to balance resource usage
Prerequisites
- Linux kernel with cgroup support: Most modern Linux distributions include cgroup support by default
- Cgroup filesystem mounted: Verify that cgroups are mounted at the specified
mountpoint - Appropriate permissions: The Gitaly process must have permission to create and manage cgroups
Verifying Cgroup Setup
You can verify that cgroups are working by checking the cgroup filesystem:Best Practices
- Start with conservative limits: Begin with generous limits and tighten them based on your workload
- Monitor resource usage: Use Gitaly’s Prometheus metrics to monitor resource consumption before and after enabling cgroups
- Test in non-production first: Test cgroup configurations in a staging environment before applying to production
- Consider your workload: Repositories with large files or complex operations may require higher limits
Troubleshooting
Processes Being Killed
If Git processes are being killed unexpectedly, check:- System logs for OOM (Out of Memory) killer messages:
dmesg | grep -i oom - Whether memory limits are too restrictive for your workload
- Gitaly logs for cgroup-related errors
Cgroups Not Working
If cgroups don’t appear to be working:- Verify cgroup filesystem is mounted:
mount | grep cgroup - Check Gitaly has permission to write to the cgroup mountpoint
- Ensure your Linux kernel supports cgroup v2 (recommended) or v1
- Check Gitaly logs for errors during startup