RFR: 8330144: Revise os::free_memory() [v2]
duke
duke at openjdk.org
Tue Jul 16 14:57:53 UTC 2024
On Wed, 10 Jul 2024 20:09:45 GMT, Robert Toyonaga <duke at openjdk.org> wrote:
>> ### Summary
>> On linux, change `os::free_memory(char *addr, size_t bytes, size_t alignment_hint)` so that it uses `madvise(MADV_DONTNEED)` (similar to the BSD implementation) instead of recommitting over the existing committed memory to discard the existing pages. This function should free the underlying memory without uncommitting. The benefit of this change is that we can get rid of conditional logic dependent on whether we're dealing with huge pages, `madvise` can't fail, and we can also get rid of the "alignment_hint" parameter.
>>
>> `os::free_memory(char *addr, size_t bytes, size_t alignment_hint)` has also been renamed to `os::disclaim_memory(char *addr, size_t bytes)` to differentiate it from `os::free_memory()` which reports the size of free memory instead of actually releasing memory.
>>
>> **Transparent huge pages:**
>> `madvise(MADV_DONTNEED)` works with THP. As with small pages, `madvise(MADV_DONTNEED)` results in the memory being freed, RSS decreasing, and the addresses can be re-touched without being explicitly recommitted.
>>
>> To determine this, I set /sys/kernel/mm/transparent_hugepage/enabled to "always" and allocated a large amount of memory. Then /proc/PID/smaps shows that THP are being used to back that memory. After calling `disclaim_memory`, RSS decreases indicating the memory is no longer live. The `os::committed_in_range function` also reports that the memory has been freed (This function should probably be renamed to `live_in_range`). Touching the addresses again afterward is fine as well.
>>
>> **Explicit huge pages:**
>> `madvise(MADV_DONTNEED)` does not result in memory being freed when used on explicit huge pages. However, the pages are not lost either. Additionally, after `madvise(MADV_DONTNEED)`, we can retouch the addresses without any problems. In conclusion, `madvise(MADV_DONTNEED)` has no affect on huge pages. This means the behavior of of this function with respect to huge pages remains the same. We can remove the "alignment_hint" parameter.
>>
>> To determine this, I allocated some huge pages via /proc/sys/vm/nr_hugepages. Successful allocation was confirmed with /proc/meminfo. After calling `disclaim_memory`, /proc/meminfo shows no change in the number of huge pages in use. Explicit huge pages are not reflected in RSS so I used the `os::committed_in_range function` instead. After calling `disclaim_memory`, the `os::committed_in_range` function reports that the memory is still live. Unfortunately that's not an imp...
>
> Robert Toyonaga has updated the pull request incrementally with two additional commits since the last revision:
>
> - Minor cleanup and comments.
> - rename to disclaim_memory and update test
@roberttoyonaga
Your change (at version 6c9e6d5c385740e140b800113ec8d2b4d0a93e82) is now ready to be sponsored by a Committer.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20080#issuecomment-2231126734
More information about the hotspot-dev
mailing list