Skip to content

Conversation

fhunleth
Copy link
Contributor

@fhunleth fhunleth commented Jul 6, 2025

This fixes an issue where the system_memory_high_watermark alarm was being set on Linux since get_basic_mem was using the less accurate sysconf strategy. Despite the comments, __SC_AVPHYS_PAGES is defined in glibc (but not musl libc).

Here's an example from before the change. memsup:get_memory_data() calls the C get_basic_mem function. The second element in the return tuple is the used memory (~222 MB) that it was reporting. It should have returned ~140 MB (254 MB - 114 MB) which also would not have set the system_memory_high_watermark alarm.

> memsup:get_memory_data().
{254287872, 222711808, {<0.3654.0>, 3819324}}
> memsup:get_system_memory_data().
[{available_memory,114470912},
 {buffered_memory,139264},
 {cached_memory,89665536},
 {free_memory,33357824},
 {free_swap,0},
 {system_total_memory,254287872},
 {total_memory,254287872},
 {total_swap,0}]

For consistency, the __SC_AVPHYS_PAGES check is done after the platform-specific checks in both places.

Specially this fixes an issue where the `system_memory_high_watermark`
alarm was being set on Linux since `get_basic_mem` was using the less
accurate sysconf strategy. Despite the comments, `__SC_AVPHYS_PAGES` is
defined in glibc.

Here's an example from before the change. `memsup:get_memory_data()`
calls the C `get_basic_mem` function. The second element in the return
tuple  is the used memory (~222 MB) that it was reporting. It should
have returned ~140 MB (254 MB - 114 MB) which also would not have set
the `system_memory_high_watermark` alarm.

```
> memsup:get_memory_data().
{254287872, 222711808, {<0.3654.0>, 3819324}}
> memsup:get_system_memory_data().
[{available_memory,114470912},
 {buffered_memory,139264},
 {cached_memory,89665536},
 {free_memory,33357824},
 {free_swap,0},
 {system_total_memory,254287872},
 {total_memory,254287872},
 {total_swap,0}]
```

For consistency, the `__SC_AVPHYS_PAGES` check is done after the
platform-specific checks in both places.
Copy link
Contributor

github-actions bot commented Jul 6, 2025

CT Test Results

  2 files   15 suites   3m 29s ⏱️
115 tests 110 ✅ 5 💤 0 ❌
135 runs  130 ✅ 5 💤 0 ❌

Results for commit 444704d.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Jul 7, 2025
@jhogberg jhogberg self-assigned this Jul 7, 2025
@jhogberg jhogberg added the testing currently being tested, tag is used by OTP internal CI label Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants