RFR: 8334489: Add function os::used_memory [v3]
Johan Sjölen
jsjolen at openjdk.org
Thu Jun 20 11:20:40 UTC 2024
> A function os::used_memory is needed for GC ergonomics.
>
> A naïve implementation is:
>
> ```c++
> julong os::used_memory() {
> return os::physical_memory() - os::available_memory();
> }
>
>
> This function does not work well in a containerized environment, as the amount of physical memory may change. To understand why, we must look under the hood.
>
> ```c++
> julong os::used_memory() {
> return os::physical_memory() - os::available_memory();
> }
>
> // can be expanded into
>
> julong os::used_memory() {
> // The os::physical_memory() call
> julong mem_physical1 = OSContainer::memory_limit_in_bytes();
> // The os::available_memory() call
> julong mem_used = OSContainer::memory_usage_in_bytes();
> julong mem_physical2 = OSContainer::memory_limit_in_bytes();
>
> // Uh-oh: mem_physical1 may differ from mem_physical2 at this point
> // That means that this number is wrong
> return mem_physical1 - (mem_physical2 - mem_used);
> }
>
>
> The fix is to expose OSContainer::memory_usage_in_bytes if it's available, as this call does not depend on OSContainer::memory_limit_in_bytes. The default implementation will use the naïve implementation.
Johan Sjölen has updated the pull request incrementally with one additional commit since the last revision:
No, not like that, like *this*
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/19772/files
- new: https://git.openjdk.org/jdk/pull/19772/files/2ebb75fa..c12539a4
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=19772&range=02
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=19772&range=01-02
Stats: 25 lines in 3 files changed: 13 ins; 12 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/19772.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/19772/head:pull/19772
PR: https://git.openjdk.org/jdk/pull/19772
More information about the hotspot-runtime-dev
mailing list