---
title: "Spin Infrastructure Adventures: Containers, Systemd, and CGroups"
description: "Spin development instances run systemd inside Kubernetes containers, and processes launched through systemd escaped the pod's memory cgroup, so pod memory limits were not enforced and instances could exceed their allotment and disturb neighbours."
url: "https://swe.quest/articles/spin-infrastructure-adventures-containers-systemd-and-cgroups-5a9e742638fea62c"
canonical: "https://shopify.engineering/spin-infrastructure-adventures-containers-systemd-cgroups"
source: "Shopify Engineering"
published: "2022-07-15"
difficulty: "hard"
kind: "Incident"
reading_minutes: 8
tags: ["containers","linux","kubernetes","debugging","multi-tenancy"]
---

# Spin Infrastructure Adventures: Containers, Systemd, and CGroups

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-07-15, 8 min read, Incident. Original: [https://shopify.engineering/spin-infrastructure-adventures-containers-systemd-cgroups](https://shopify.engineering/spin-infrastructure-adventures-containers-systemd-cgroups)

## Summary

Spin development instances run systemd inside Kubernetes containers, and processes launched through systemd escaped the pod's memory cgroup, so pod memory limits were not enforced and instances could exceed their allotment and disturb neighbours. Using kubectl top and a stress test, the team showed that processes started via kubectl exec landed in the kubepods cgroup while those started via spin shell landed in an effectively unlimited hierarchy. Reproductions across containerd, Docker and Podman traced the cause to the cgroupfs driver: Podman's systemd cgroup driver correctly delegates limits to the in-container systemd. The leak came from bind-mounting /sys/fs/cgroup read-only, which leaves subdirectories writable, and the fix is switching to the systemd cgroup driver, which Container-Optimized OS plans to make the default in version 101.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Kubernetes](https://swe.quest/tags/kubernetes.md) (Infrastructure)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)
- [Multi-tenancy](https://swe.quest/tags/multi-tenancy.md) (Architecture & design)

## Prerequisites

- Linux cgroups ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))
- systemd basics
- Kubernetes pods and resource limits ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))
- container runtimes ([easy posts on Runtimes & VMs](https://swe.quest/tags/runtimes.md?difficulty=easy))

## Keywords

systemd, cgroups, containerd, Podman, Docker, Container-Optimized OS, Spin, runc

## Related posts

- [Debugging Systems in the Cloud: MySQL, Kubernetes, and Cgroups](https://swe.quest/articles/debugging-systems-in-the-cloud-mysql-kubernetes-and-cgroups-a5ded3f862ca5b21.md): Shopify Engineering · 2021-10-21 · Hard · 8 min read · Debugging, Linux, MySQL, Kubernetes, Performance engineering
  Slow MySQL Pod startup and degraded query performance on long-running GKE nodes in Shopify's KateSQL platform traced back to a Linux kernel memory cgroup leak: roughly 50K zombie memory cgroups made mem\_cgroup\_commit\_charge slow, so each 128MB mmap during InnoDB buffer pool initialization took about 100 ms. The investigation used strace, perf flamegraphs, slabtop and /proc/cgroups, and Google kernel engineers confirmed it as a side effect of slab reparenting on cgroup removal.
- [The Shift to cgroup v2 in Kubernetes: What You Need to Know](https://swe.quest/articles/the-shift-to-cgroup-v2-in-kubernetes-what-you-need-to-know-ef93aafe6f995ba1.md): Kubernetes Blog · 2026-10-06 · Medium · 11 min read · Kubernetes, Linux, Containers, Memory management
  Kubernetes has deprecated cgroup v1: from v1.35 the kubelet refuses to start on cgroup v1 nodes by default (\`failCgroupV1: true\`), kubeadm preflight errors on it, and the fallback is slated for removal in v1.38. cgroup v2 enables Memory QoS with \`memory.high\` throttling and tiered \`memory.min\`/\`memory.low\` reservations, container-wide OOM kills via \`memory.oom.group\`, safe rootless delegation, eBPF-based device control, PSI metrics, and accurate Pod-level in-place resizing.
- [What else runs on your Postgres server, and how do we stop it from taking the database down?](https://swe.quest/articles/what-else-runs-on-your-postgres-server-and-how-do-we-stop-it-from-taking-the-79e9559393b71ab0.md): ClickHouse · 2026-08-21 · Medium · 4 min read · PostgreSQL, Linux, Memory management, Resilience, Multi-tenancy
  Supporting processes on a managed Postgres VM (PgBouncer, WAL-G, Prometheus, exporters, log collector, watchdogs) share memory, CPU and disk with the database, so a leak or CPU burst in any of them can take it down.
- [The case of the vanishing CPU: A Linux kernel debugging story](https://swe.quest/articles/the-case-of-the-vanishing-cpu-a-linux-kernel-debugging-story-3db1aa1b81ec8319.md): ClickHouse · 2025-03-05 · Hard · 32 min read · Linux, Memory management, Debugging, Performance engineering, Incidents & postmortems
  Intermittent, indefinite CPU saturation of ClickHouse Cloud pods, seen only on GCP, turned out to be a Linux kernel memory-management livelock.
- [Kubernetes v1.38 Sneak Peek](https://swe.quest/articles/kubernetes-v1-38-sneak-peek-0b9c569924e11f5d.md): Kubernetes Blog · 2026-11-23 · Hard · 7 min read · Kubernetes, Containers, Linux, Deployment
  Kubernetes v1.38, planned for December 16, 2026, will require container runtimes to report the cgroup driver via the CRI RuntimeConfig RPC.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
