Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8334489

Add function os::used_memory

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 24
    • None
    • hotspot
    • b04

    Description

      A function os::used_memory is needed for GC ergonomics.

      A naïve implementation is:

      ```
      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.

      ```
      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 unreliable
        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.

      Attachments

        Issue Links

          Activity

            People

              jsjolen Johan Sjölen
              jsjolen Johan Sjölen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: