Skip to content

Commit

Permalink
Make memory tuning cgroups v2 compatible
Browse files Browse the repository at this point in the history
The old implementation only checked the sysfs files corresponding to
cgroups v1. Most Linux distribution kernels have switched to cgroups
v2 several years ago, which uses a different set of paths for various
settings (memory limits included).

The net effect of the old implementation was that it completely
ignored the memory limits, if the container was run in a kernel with
cgroups v2 (in those kernels cgroups v1 are disabled by default).
  • Loading branch information
iarenaza authored and svenklemm committed Jul 1, 2024
1 parent 33ebf7c commit 84ed6a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docker-entrypoint-initdb.d/001_timescaledb_tune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ fi

if [ -z "${TS_TUNE_MEMORY:-}" ]; then
# See if we can get the container's total allocated memory from the cgroups metadata
if [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
# Try with cgroups v2 first.
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
TS_TUNE_MEMORY=$(cat /sys/fs/cgroup/memory.max)
TS_CGROUPS_MAX_MEM=true
# cgroups v2 is not available, try with cgroups v1
elif [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
TS_TUNE_MEMORY=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)

TS_CGROUPS_MAX_MEM=true
fi
if [ "${TS_CGROUPS_MAX_MEM:-false}" != "false" ]; then
if [ "${TS_TUNE_MEMORY}" = "18446744073709551615" ]; then
# Bash seems to error out for numbers greater than signed 64-bit,
# so if the value of limit_in_bytes is the 64-bit UNSIGNED max value
Expand Down

0 comments on commit 84ed6a2

Please sign in to comment.