Skip to content

Conversation

JohannesGaessler
Copy link
Collaborator

While working on code for retrieving and reporting the memory use of llama.cpp I've noticed that the CPU backend always reports all of its memory as being free. This was implemented in #13304 . This behavior doesn't seem correct to me and there is no documentation indicating why this is being done so my impression is that this is a bug. This PR fetches the number of available pages to calculate the "free" memory - this tends to be an underestimation due to file caches being considered allocated memory. But I did not see any other suitable property in the sysconf manual.

@JohannesGaessler
Copy link
Collaborator Author

Okay, so since the CI has failed with error: use of undeclared identifier '_SC_AVPHYS_PAGES' presumably the problem is that _SC_AVPHYS_PAGES is not available. This in indicated in the manual but both for _SC_PHYS_PAGES and _SC_AVPHYS_PAGES.

@slaren
Copy link
Member

slaren commented Sep 6, 2025

When talking about system memory, it's hard to even define free memory, because memory can be used in caches that can be freed at any moment, or swapped to disk. llama.cpp does not use the value of free memory for the CPU backend.

For practical purposes, IMO it's better to treat system memory as unlimited, or at worst limited only by the amount of physical memory.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 6, 2025
@JohannesGaessler JohannesGaessler changed the title ggml-cpu: fix reported free memory ggml-cpu: document use of "free" memory [no ci] Sep 6, 2025
@JohannesGaessler
Copy link
Collaborator Author

Fine by me, I just think this should be documented.

@JohannesGaessler JohannesGaessler merged commit 01806e7 into ggml-org:master Sep 6, 2025
1 check passed
walidbr pushed a commit to walidbr/llama.cpp that referenced this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants