Why is main garbage collection slower than Small?

Passed through this link, but still has the confusion of what actually happens in the small and large collection of GC.

Let's say I have 100 objects of the young generation, of which 85 objects are unreachabe objects. Now that Minor GC is working, it will restore memory from 85 objects and move 15 objects to an older generation.

Now in the older generation there are 15 living objects, of which 3 are inaccessible. Let's say Major GK has a place. It will support 15 objects, as well as restore memory for 3 inaccessible objects. It is said that the main GC is slower than that of the younger GC. My question is why ? Is it because of major GC happens on generally greater number of objects than minor as minor gc occurs more frequently than major?

According to the understanding, major GC should be faster as it needs to do less work ie restore memory from inaccessible objects, except for the younger GC, because there is a high mortality rate in the younger generation.

+6
source share
2 answers

1) A minor GC will first move 15 objects to one of the survivors, for example SS1, the next GC will move those who are still alive in SS2, the next GC will transfer those who survived back to SS1, and so on. Only those who survived several (for example, 8) transfers (younger GCs) will finally go to the old generation.

2) The main GC occurs only when the JVM cannot allocate an object in the old generation, because there is no free space in it. To clear the memory of dead objects, the GC passes through all the objects of the old generation, since the old generation is several times larger than the new generation, it can contain several times more objects, so processing the GC will take several times more

+4
source

My question is why? Is this due to the fact that the main GC occurs as a whole for a larger number of objects than the secondary one, since insignificant gc is more common than the main one?

You pretty much hit a nail on your head. From an Oracle article, the focus is on:

Often the main collection is much slower because it includes all living objects .

Thus, not only the large GC analyzes these 15 objects in the old generation, it also passes through the young generation (again), and the permg and GC are those areas of the heap. Small GC analyzes only the younger generation, so in general there are not many objects to see.

According to the understanding, the main GC should be faster, since it has to do less work (i.e., restore memory from inaccessible objects) than the younger GC, since there is a high mortality rate in the younger generation.

I think I understand why you think so. I could imagine that a large GC can be launched very soon after a small GC, when objects are moving up to an almost complete old generation. Thus, the younger generation (presumably) does not contain too many objects for collection.

However, if I remember things correctly, the old generation is usually larger than the younger generation, so the GC not only needs to analyze more space, but also has to move again, and the rest of the objects in the younger generation (again). So this is probably why the main GC is slower - simply because there is still something to do. You may be able to make the main GC faster than the younger GC by resizing the generation spaces so that the younger generation is larger than the old generation and spoofing, but I don't think it would be a general setting to use ...

+2
source

Source: https://habr.com/ru/post/971817/


All Articles