Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-21753

Cycle references between memory manager and gc cleaner action

    XMLWordPrintableJSON

    Details

      Description

      MemoryManager.allocatePages uses this::releasePage as cleanup action in MemorySegmentFactory.allocateOffHeapUnsafeMemory. The cleanup function is used as gc cleaner action there. This creates a cycle referencing between memory manager and gc cleaner if allocated memory segment is not MemoryManager.release in time. Symptoms should be different based on versions:

      • Before 1.12.2: memory will not be reclaimed until gc after MemoryManager.release
      • * 1.12.2: memory will not be reclaimed until MemorySegment.free or gc after MemoryManager.release

      I quotes javadoc from jdk java.lang.ref.Cleaner here for references:

      The cleaning action is invoked only after the associated object becomes phantom reachable, so it is important that the object implementing the cleaning action does not hold references to the object. In this example, a static class encapsulates the cleaning state and action. An "inner" class, anonymous or not, must not be used because it implicitly contains a reference to the outer instance, preventing it from becoming phantom reachable. The choice of a new cleaner or sharing an existing cleaner is determined by the use case.

      See also FLINK-13985 FLINK-21419.

      I pushed test case in my repository after FLINK-21419 (which merged in 1.12.2 but not before) for evaluation.

      cc Andrey Zagrebin [~xintongsong] Till Rohrmann Kurt Young Nicholas Jiang 

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kezhuw Kezhu Wang
                Reporter:
                kezhuw Kezhu Wang
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: