Skip to content

Commit

Permalink
Merge pull request #8 from prometheus/superq/gomemlimit
Browse files Browse the repository at this point in the history
Automatically set GOMEMLIMIT
  • Loading branch information
SuperQ authored Sep 9, 2024
2 parents f32250d + a035c86 commit 1074bbd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions actions/setup_environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
type: boolean
description: Whether to enable multibuild docker
default: false
memlimit_ratio:
type: string
description: The ratio of memory reserved for Go
default: "0.8"
runs:
using: composite
steps:
Expand All @@ -32,6 +36,18 @@ runs:
key: ${{ runner.os }}-npm-${{ hashFiles('web/ui/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Set GOMEMLIMIT
run: |
ratio="${{ inputs.memlimit_ratio }}"
# Get the memory limit from cgroups v2.
cgroup=$(awk -F':' '{print $3}' /proc/self/cgroup)
cgroup_mem_limit=$(< "/sys/fs/cgroup/${cgroup}/memory.max")
if [[ "${cgroup_mem_limit}" != "max" ]] ; then
echo "${cgroup_mem_limit}" | awk -v "ratio=${ratio}" '{printf "GOMEMLIMIT=%.0fKiB\n", $1 / 1024 * ratio}' >> "$GITHUB_ENV"
exit 0
fi
# Fallback to the system memory limit.
awk -v "ratio=${ratio}" '$1 == "MemTotal:" {printf "GOMEMLIMIT=%.0fKiB\n", $2 * ratio}' /proc/meminfo >> "$GITHUB_ENV"
- run: make promu
shell: bash
if: inputs.enable_go == 'true'
Expand Down

0 comments on commit 1074bbd

Please sign in to comment.