[PR #13782] Use LXCFS' formula to compute free memory in a cgroup #45635

Open
opened 2026-04-25 01:17:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13782
Author: @markasoftware-tc
Created: 1/19/2026
Status: 🔄 Open

Base: mainHead: markasoftware/cgroup-reclaimable-memory


📝 Commits (1)

  • c05ac63 discover: properly account for page cache memory in a cgroup

📊 Changes

1 file changed (+70 additions, -2 deletions)

View changed files

📝 discover/cpu_linux.go (+70 -2)

📄 Description

Summary: Ollama currently computes used system memory incorrectly in containers, making it seem like there's less free memory than there is. Models often fail to run as a result.

Before this change, cgroup free memory was computed as cgroup total - cgroup used. However, cgroup used memory also includes page cache buffers, which means available memory can appear low when really there's plenty of memory available.

This change uses the same formula as LXCFS to account for reclaimable memory; LXCFS is written by some real container experts so I trust them. The relevant code they use to compute MemAvailable in their fake procfs is what I copy here: c67f5f88e3/src/proc_fuse.c (L1484-L1485)

Possibly fixes #13095, #13556 and #12692 (edit: also #14557)

I have not written any automated tests, but have manually tested it by seeing the amount of memory reported for the CPU under various amounts of cached memory (dd if=/dev/zero of=zero bs=1M count=5000; cat /dev/zero > /dev/null eg to cause 5 gb of page cache) and actual used memory (stress --vm 1 --vm-bytes 5G --vm-keep) and checked that the reported memory available on the CPU inference device is correct.


🔄 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/13782 **Author:** [@markasoftware-tc](https://github.com/markasoftware-tc) **Created:** 1/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `markasoftware/cgroup-reclaimable-memory` --- ### 📝 Commits (1) - [`c05ac63`](https://github.com/ollama/ollama/commit/c05ac6368cffcc89b77616811edf703191ba8361) discover: properly account for page cache memory in a cgroup ### 📊 Changes **1 file changed** (+70 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `discover/cpu_linux.go` (+70 -2) </details> ### 📄 Description Summary: Ollama currently computes used system memory incorrectly in containers, making it seem like there's less free memory than there is. Models often fail to run as a result. Before this change, cgroup free memory was computed as cgroup total - cgroup used. However, cgroup used memory also includes page cache buffers, which means available memory can appear low when really there's plenty of memory available. This change uses the same formula as LXCFS to account for reclaimable memory; LXCFS is written by some real container experts so I trust them. The relevant code they use to compute MemAvailable in their fake procfs is what I copy here: https://github.com/lxc/lxcfs/blob/c67f5f88e39ab1603a1106857b5fc78516437714/src/proc_fuse.c#L1484-L1485 Possibly fixes #13095, #13556 and #12692 (edit: also #14557) I have not written any automated tests, but have manually tested it by seeing the amount of memory reported for the CPU under various amounts of cached memory (`dd if=/dev/zero of=zero bs=1M count=5000; cat /dev/zero > /dev/null` eg to cause 5 gb of page cache) and actual used memory (`stress --vm 1 --vm-bytes 5G --vm-keep`) and checked that the reported memory available on the CPU inference device is correct. --- <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-04-25 01:17:46 -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#45635