[PR #15713] fix: use MemAvailable equivalent in cgroup memory check #77569

Open
opened 2026-05-05 10:14:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15713
Author: @ssam18
Created: 4/20/2026
Status: 🔄 Open

Base: mainHead: fix/cgroup-mem-available


📝 Commits (2)

  • ba5079c discover: fix cgroup free memory ignoring reclaimable page cache
  • 502e0bf discover: fix gofmt alignment in test struct

📊 Changes

2 files changed (+78 additions, -1 deletions)

View changed files

📝 discover/cpu_linux.go (+23 -1)
📝 discover/cpu_linux_test.go (+55 -0)

📄 Description

In LXC and Docker containers, memory.current includes reclaimable page cache, so computing free memory as memory.max - memory.current was giving a result closer to MemFree than MemAvailable, causing false "insufficient memory" errors even when Linux could reclaim enough cache to load the model.

The fix reads inactive_file from /sys/fs/cgroup/memory.stat and subtracts it from the used total before computing free memory, matching how the kernel calculates MemAvailable. Fixes #15704


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15713 **Author:** [@ssam18](https://github.com/ssam18) **Created:** 4/20/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/cgroup-mem-available` --- ### 📝 Commits (2) - [`ba5079c`](https://github.com/ollama/ollama/commit/ba5079cd0d65f1370d5fe78d80e1c0e46a6bf9a9) discover: fix cgroup free memory ignoring reclaimable page cache - [`502e0bf`](https://github.com/ollama/ollama/commit/502e0bf6a2a450fa153c3d9abb8327f5cab8f331) discover: fix gofmt alignment in test struct ### 📊 Changes **2 files changed** (+78 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `discover/cpu_linux.go` (+23 -1) 📝 `discover/cpu_linux_test.go` (+55 -0) </details> ### 📄 Description In LXC and Docker containers, `memory.current` includes reclaimable page cache, so computing free memory as `memory.max - memory.current` was giving a result closer to `MemFree` than `MemAvailable`, causing false "insufficient memory" errors even when Linux could reclaim enough cache to load the model. The fix reads `inactive_file` from `/sys/fs/cgroup/memory.stat` and subtracts it from the used total before computing free memory, matching how the kernel calculates `MemAvailable`. Fixes #15704 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 10:14:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#77569