Integrated: JDK-8276731: Metaspace chunks are uncommitted twice
Thomas Stuefe
stuefe at openjdk.java.net
Tue Nov 9 14:15:40 UTC 2021
On Fri, 5 Nov 2021 14:58:43 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: 4bd5bfd8
Author: Thomas Stuefe <stuefe at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/4bd5bfd8e2624715ebfa6e4c49172361389fbc98
Stats: 6 lines in 1 file changed: 0 ins; 6 del; 0 mod
8276731: Metaspace chunks are uncommitted twice
Reviewed-by: shade, coleenp
-------------
PR: https://git.openjdk.java.net/jdk/pull/6277
More information about the hotspot-runtime-dev
mailing list