Skip to content

Conversation

@BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Aug 28, 2025

Free method headers created for inlining. Make some offsets arrays used by dynamic interp methods freeable. Make tiering data and the data items for dynamic methods freeable.

For dynamic methods, imethod_alloc0 allocates from the dynamic method's mempool which is freed when the method is collected. We were previously allocating only from the global memory manager.
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses memory leaks in the Mono interpreter, particularly for dynamic methods. The main focus is on properly freeing method headers created during inlining operations and making various data structures associated with dynamic methods freeable.

Key changes:

  • Tracks and frees method headers created during inlining to prevent memory leaks
  • Changes memory allocation strategy for offset arrays to use freeable memory
  • Implements cleanup of tiering data and patch sites when dynamic methods are freed

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/mono/mono/mini/interp/transform.h Adds headers_to_free field to track method headers for cleanup
src/mono/mono/mini/interp/transform.c Implements header tracking and changes allocation strategy for offset arrays
src/mono/mono/mini/interp/tiering.h Adds function declaration for clearing data items patch sites
src/mono/mono/mini/interp/tiering.c Implements cleanup logic for patch sites when dynamic methods are freed
src/mono/mono/mini/interp/interp.c Integrates patch site cleanup into method freeing process
src/mono/mono/mini/interp/interp-internals.h Adds n_data_items field to track data item count for cleanup

Previously we were registering imethod locations from these data items in order for them to be patched once a method is tiered up. Because of this registering, the data item had to always be around. We now free the data item for dynamic methods and also we deregister the patch locations when freeing such a method.
We add them to a list for later freeing. This uses the same pattern as jit.
@BrzVlad BrzVlad merged commit 82a3571 into dotnet:main Aug 29, 2025
70 checks passed
@srxqds
Copy link
Contributor

srxqds commented Sep 1, 2025

can you backport to release/9.0 and release/10.0 branch

BrzVlad added a commit to BrzVlad/runtime that referenced this pull request Sep 11, 2025
…otnet#119176)

* [mono][interp] Fix leaking of compilation data

For dynamic methods, imethod_alloc0 allocates from the dynamic method's mempool which is freed when the method is collected. We were previously allocating only from the global memory manager.

* [mono][interp] Stop leaking data items

Previously we were registering imethod locations from these data items in order for them to be patched once a method is tiered up. Because of this registering, the data item had to always be around. We now free the data item for dynamic methods and also we deregister the patch locations when freeing such a method.

* [mono][interp] Free headers allocated for inlined methods

We add them to a list for later freeing. This uses the same pattern as jit.

* [mono][interp] Skip interp free for methods not yet compiled
BrzVlad added a commit to BrzVlad/runtime that referenced this pull request Sep 12, 2025
…otnet#119176)

* [mono][interp] Fix leaking of compilation data

For dynamic methods, imethod_alloc0 allocates from the dynamic method's mempool which is freed when the method is collected. We were previously allocating only from the global memory manager.

* [mono][interp] Stop leaking data items

Previously we were registering imethod locations from these data items in order for them to be patched once a method is tiered up. Because of this registering, the data item had to always be around. We now free the data item for dynamic methods and also we deregister the patch locations when freeing such a method.

* [mono][interp] Free headers allocated for inlined methods

We add them to a list for later freeing. This uses the same pattern as jit.

* [mono][interp] Skip interp free for methods not yet compiled

Fix attempt to free tiering data when tiering is disabled (dotnet#119294)
BrzVlad added a commit to BrzVlad/runtime that referenced this pull request Sep 23, 2025
…otnet#119176)

* [mono][interp] Fix leaking of compilation data

For dynamic methods, imethod_alloc0 allocates from the dynamic method's mempool which is freed when the method is collected. We were previously allocating only from the global memory manager.

* [mono][interp] Stop leaking data items

Previously we were registering imethod locations from these data items in order for them to be patched once a method is tiered up. Because of this registering, the data item had to always be around. We now free the data item for dynamic methods and also we deregister the patch locations when freeing such a method.

* [mono][interp] Free headers allocated for inlined methods

We add them to a list for later freeing. This uses the same pattern as jit.

* [mono][interp] Skip interp free for methods not yet compiled

Fix attempt to free tiering data when tiering is disabled (dotnet#119294)
@github-actions github-actions bot locked and limited conversation to collaborators Sep 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants