RFR: JDK-8304421: Introduce malloc size feedback

Justin King jcking at openjdk.org
Fri Mar 17 17:24:42 UTC 2023


Memory allocated by `malloc()` is frequently larger than the size actually requested. Some `malloc()` implementations allow querying this information. This can be useful as an optimization for some use cases, such as an arena allocator, as it allows using the entire memory block.

This change updates `os::malloc()` by appending an additional argument that can request the actual usable size. On platforms that support it, the actual usable size of the allocation returned by `malloc()` will be filled in. Callers should then use `os::free_sized`, as with NMT enabled it can assert that the size is correct. This also is a precursor to eventually supporting `free_sized` from C23, which is an optimization usabled by some `malloc()` implementations to make `free()` quicker.

This change also upgrades and refactors Chunk to use this facility.

**Observations**

NMT could use this same facility to keep track of the actual allocated size, instead of the requested size it has today, making it more accurate. Doing so is out of scope for this change.

-------------

Commit messages:
 - Reorder ChunkPoolSize so NONE is 0
 - Add support for malloc size feedback

Changes: https://git.openjdk.org/jdk/pull/13081/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13081&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8304421
  Stats: 376 lines in 5 files changed: 262 ins; 35 del; 79 mod
  Patch: https://git.openjdk.org/jdk/pull/13081.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/13081/head:pull/13081

PR: https://git.openjdk.org/jdk/pull/13081


More information about the hotspot-runtime-dev mailing list