Skip to content

Conversation

@klutchell
Copy link
Contributor

@klutchell klutchell commented Aug 22, 2025

To alleviate memory pressure, increase zram to 50% or a given value of total memory at runtime. This allows the host to compress inactive pages to reduce contention.

This service optionally allows for the maximum zram percentage and compression algorithm to be modified at runtime using variables.

Change-type: minor

Based on: #276
See: https://balena.fibery.io/Security/Information_Security_and_Reliability_Incident/GitHub-Runners-Failure-during-vcpu-run-Out-of-memory-(os-error-12)-130

This comment was marked as outdated.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new zram service to the Docker Compose configuration to help alleviate memory pressure by compressing inactive pages. The service creates a compressed RAM disk that acts as swap space, using a configurable percentage of total system memory (defaulting to 50%) with the LZ4 compression algorithm.

  • Adds a new zram service that creates compressed swap space using a percentage of total memory
  • Implements configurable compression algorithm and memory percentage through environment variables
  • Includes cleanup logic to disable existing swap devices and remove existing zram devices before setup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

for swap in ${swaps}; do
# Swap devices reported by /proc/swaps in the container are missing the /dev/ prefix
echo "Disabling swap device ${swap##*/}..."
swapoff /dev/${swap##*/}
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter expansion ${swap##*/} removes everything up to the last slash, but according to the comment on line 244, swap devices from /proc/swaps are already missing the /dev/ prefix. This means the expansion is unnecessary and could potentially cause issues if the swap device name contains slashes.

Suggested change
swapoff /dev/${swap##*/}
echo "Disabling swap device ${swap}..."
swapoff /dev/${swap}

Copilot uses AI. Check for mistakes.
for swap in ${swaps}; do
# Swap devices reported by /proc/swaps in the container are missing the /dev/ prefix
echo "Disabling swap device ${swap##*/}..."
swapoff /dev/${swap##*/}
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous line, the parameter expansion ${swap##*/} is redundant since the comment states swap devices are already missing the /dev/ prefix. This should be swapoff /dev/${swap} to avoid potential issues.

Suggested change
swapoff /dev/${swap##*/}
echo "Disabling swap device ${swap}..."
swapoff /dev/${swap}

Copilot uses AI. Check for mistakes.
@klutchell klutchell force-pushed the kyle/zram-swap branch 2 times, most recently from fbc6f5c to e74b13e Compare August 22, 2025 19:22
@klutchell
Copy link
Contributor Author

/rebase

@klutchell
Copy link
Contributor Author

/rebase

@klutchell
Copy link
Contributor Author

/rebase

@klutchell klutchell marked this pull request as ready for review September 3, 2025 14:13
@klutchell
Copy link
Contributor Author

/rebase

@klutchell
Copy link
Contributor Author

/rebase

To alleviate memory pressure, increase zram to 50% or a given
value of total memory at runtime. This allows the host to compress
inactive pages to reduce contention.

This service optionally allows for the maximum zram percentage and
compression algorithm to be modified at runtime using variables.

Change-type: minor
Signed-off-by: Kyle Harding <[email protected]>
@klutchell klutchell marked this pull request as draft September 5, 2025 17:32
auto-merge was automatically disabled September 5, 2025 17:32

Pull request was converted to draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants