RFR: JDK-8276731: Metaspace chunks are uncommitted twice
Thomas Stuefe
stuefe at openjdk.java.net
Sat Nov 6 05:48:47 UTC 2021
Small patch for a minor, benign error, which just eats up a bit of unnecessary processing time.
Metaspace returns memory to the OS by uncommitting free chunks when we unload classes. Today, we uncommit free metaspace chunks twice, and the second uncommit has no effect. Therefore, one of the uncommits is unnecessary.
In detail, when class unloading happens, we enter CLDG::purge():
- CLDG::purge()
- delete each CLD in the `_unloading` list
- which deletes the associated metaspace arena(s)
- which causes the arenas to return all of their now unused chunks to the chunk manager (`ChunkManager::return_chunk()`)
- where the buddy allocator combines them with their neighbors if they are free
- (A) and the resulting larger chunk gets uncommitted if it is larger than a commit granule
- then we pop back to CLDG::purge() and call `Metaspace::purge()`
- (B) `Metaspace::purge()` iterates through all free chunks in the chunk manager, now maximally folded, and uncommits those which are larger than a commit granule.
(A) and (B) are redundant. (B) uncommits memory which had already been uncommitted in step (A). Either A or B could be dropped.
I opt for keeping (B) and dropping (A) since:
- it is the expected behavior. We expect `Metaspace::purge()` to do some purging.
- (B) is less work than (A) since space is maximally defragmented at this point. All free chunks have been processed already and are therefore maximally folded by the buddy allocator.
-------------
Commit messages:
- dont uncommit when returning chunks but leave uncommitting to Metaspace::purge()
Changes: https://git.openjdk.java.net/jdk/pull/6277/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6277&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8276731
Stats: 6 lines in 1 file changed: 0 ins; 6 del; 0 mod
Patch: https://git.openjdk.java.net/jdk/pull/6277.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/6277/head:pull/6277
PR: https://git.openjdk.java.net/jdk/pull/6277
More information about the hotspot-runtime-dev
mailing list