Skip to content

skc: high memory usage during clang invocation causes OOM on 4GB CI #1114

@mbouaziz

Description

@mbouaziz

Problem

When skc compiles a binary with -O2, it peaks at ~4.3GB total memory because it holds ~3.4GB RSS while spawning clang -cc1 -O2 which adds ~0.9GB on top. This causes OOM kills on CI environments with 4GB RAM (e.g. CircleCI medium).

Measured Memory Profile

Captured building the skjs binary (skargo build --release --bin skjs) inside skiplabs/skip:latest:

Time Process RSS
T+0s skc starts ~200MB
T+10s skc (compilation) ~1.8GB
T+15s skc (peak, pre-clang) ~3.4GB
T+15s skc spawns clang -cc1 skc: 3.4GB + clang: ~270MB
T+25s PEAK skc: 3.4GB + clang: ~940MB = ~4.3GB total
T+35s done released

Key observations

  • skc holds 3.4GB RSS the entire time clang runs
  • clang -cc1 grows to ~940MB during LLVM codegen at -O2
  • The two processes overlap: skc doesn't free memory before clang finishes

Suggested Fix

Since skc's job is done once it writes the .ll file, it could:

  1. exec() into clang — replace the skc process entirely, reducing peak to max(3.4GB, 0.9GB) = 3.4GB
  2. Free compilation state before invoking clang
  3. Fork/exec clang and exit — let clang run independently

Option 1 would be the most effective.

Reproduction

git clone https://github.com/SkipLabs/skjs
git clone --recurse-submodules https://github.com/SkipLabs/skip

# This reliably OOMs:
docker run -d --name skc-oom-test --memory=4g --memory-swap=4g \
  -v "$PWD/skjs:/work/skjs" -v "$PWD/skip:/work/skip" \
  -w /work/skjs skiplabs/skip:latest \
  skargo build --release

docker inspect skc-oom-test --format '{{.State.OOMKilled}}'  # true = OOM

Current Workaround

skjs CI uses skargo build --release --bin skjs instead of skargo build --release to avoid building the test binary (which causes a second 4GB spike). This brings peak from ~4.3GB to ~3.9GB.

Environment

  • Docker image: skiplabs/skip:latest (skc 0.1.0, LLVM 20)
  • CI: CircleCI medium executor (4GB RAM)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions