How to Enable cgroup_enable=memory and swapaccount=1 for Docker Memory Limits on GCE Debian Jessie


4 views

When running Docker on Google Compute Engine (GCE) with Debian Jessie, you might encounter warnings about missing kernel support for memory limits despite having added cgroup_enable=memory swapaccount=1 to your kernel parameters. The issue typically appears like this:


$ docker info
[...]
WARNING: No kernel memory limit support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
[...]

First, check if your kernel parameters are actually being loaded. After modifying /etc/default/grub and running update-grub, verify with:


cat /proc/cmdline

You should see your parameters in the output:


BOOT_IMAGE=/boot/vmlinuz-3.16.0-4-amd64 [...] cgroup_enable=memory swapaccount=1

The GCE Debian Jessie image might use a kernel compiled without these features. To check your kernel's cgroup support:


grep CGROUP /boot/config-$(uname -r)

Look for these critical configurations:


CONFIG_MEMCG=y
CONFIG_MEMCG_SWAP=y
CONFIG_CGROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y

If your kernel lacks these features, consider these options:


# Option 1: Install a custom kernel
sudo apt-get install linux-image-amd64 linux-headers-amd64

# Option 2: Use GCE's Container-Optimized OS
# (Better for production with Docker)

For a quick test of cgroup functionality:


sudo mkdir /sys/fs/cgroup/memory/docker
echo 1 | sudo tee /sys/fs/cgroup/memory/docker/memory.use_hierarchy

For a proper solution, you'll need to either:

  • Upgrade to a newer Debian version (Stretch or later)
  • Switch to Ubuntu LTS which has better Docker support
  • Use GCE's Container-Optimized OS image

Remember to restart Docker after any changes:


sudo systemctl restart docker

When deploying Docker containers on Google Compute Engine (GCE) with Debian Jessie, you might encounter this frustrating scenario:

$ docker info
[...]
WARNING: No kernel memory limit support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
[...]

Even after properly configuring your GRUB settings with:

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

And verifying the kernel command line shows the options:

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.16.0-4-amd64 [...] cgroup_enable=memory swapaccount=1

The root cause lies in the custom kernel provided by Google Cloud. The default Debian Jessie image (v3.16) on GCE has these key limitations:

  • Missing required cgroup memory controllers
  • Swap accounting not compiled into kernel
  • Custom GCE optimizations that override some cgroup features

Here are two working approaches I've tested on GCE:

Option 1: Use Google's Container-Optimized OS

For production environments, switch to Google's purpose-built OS:

gcloud compute instances create INSTANCE_NAME \
    --image-project cos-cloud \
    --image-family cos-stable \
    --machine-type n1-standard-1

Option 2: Install a Custom Kernel (Advanced)

For Debian purists, manually install a compatible kernel:

# Add backports repository
echo "deb http://deb.debian.org/debian jessie-backports main" | \
    sudo tee /etc/apt/sources.list.d/jessie-backports.list

# Install newer kernel
sudo apt-get update
sudo apt-get -t jessie-backports install linux-image-amd64

# Configure GRUB
sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"/' \
    /etc/default/grub
sudo update-grub
sudo reboot

After implementing either solution, verify with:

# Check cgroup hierarchy
mount | grep cgroup

# Verify memory controller
cat /proc/cgroups | grep memory

# Confirm Docker recognition
docker info | grep -i cgroup

The output should show proper cgroup support without warnings.