GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Skip last 10% allocations for leak detection by apangin · Pull Request #1299 · async-profiler/async-profiler

Conversation

@apangin

@apangin apangin commented May 18, 2025

Copy link
Copy Markdown
Collaborator

Description

For native leak profiling, ignore allocations made in the last 10% of the profiling session.

Motivation and context

#1064 introduced the feature to create a flamegraph of native memory allocations. With --leak option, only those allocations are displayed that do not have matching free calls - such allocations are considered memory leaks. However, this algorithm is biased towards allocations made closer to the end of the profiling session, because such allocations are more likely to be freed only after the session has ended.

To avoid such a bias, it is proposed to simply ignore younger allocations. For example, if a profiling session runs for 10 minutes, allocations made during the last minute won't be included in the leak flamegraph.

How has this been tested?

Created an artificial memory leak by not closing DirectoryStream and ran

jfrconv --nativemem --leak --total --lines leak.jfr

Before the change:
leak-old

After the change:
leak-new


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

olivergillespie reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@Baraa-Hasheesh

Baraa-Hasheesh commented May 18, 2025

Copy link
Copy Markdown
Contributor

@apangin
Using a % could lead to a very large ignore window for long profiling sessions
For example if the profiling session is 1 hour => 60Minutes, we will ignore the last 6 minutes of allocations for memory leakage

At the same time using a static value like last minute could also lead to bad outcomes for short profiling sessions

I think we should have both a base static ignore window & % ignore window

We can define a base max ignore window of for example 10 seconds
And evaluate against the min value between the 10% & our base window

So for short profiling sessions we would use the % evaluation while for longer profiling sessions we would use the base max ignore window we define.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apangin apangin changed the title Leak tail Skip last 10% allocations for leak detection May 18, 2025
@apangin

apangin commented May 18, 2025

Copy link
Copy Markdown
Collaborator Author

if the profiling session is 1 hour => 60Minutes, we will ignore the last 6 minutes of allocations

On the other hand, profiler will collect useful allocation data for 54 minutes - that's a lot!
If there is a continuous leak, then finding a meaningful signal in 54 minutes is just as efficient as in 59 minutes, but in the latter case, the noise will be likely higher due to young allocations that have not been freed. The problem with a constant size tail is that there always be such allocations, no matter how long profiler runs, whereas with the fixed ratio, results accuracy increases with the duration of profiling session.

The approach proposed in this PR is simple and efficient. There is no point in complicating it without obvious benefits.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fandreuz

fandreuz commented May 19, 2025

Copy link
Copy Markdown
Contributor

@apangin As a user, I'd want to have this behavior documented, and to have the tail size configurable

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apangin

apangin commented May 19, 2025

Copy link
Copy Markdown
Collaborator Author

@fandreuz I agree on the documentation point - will add a sentence.
As to making it configurable, I'm not sure. In my paradigm, software should just work well by default; the less things require manual configuration, the better. That said, we may add a knob in the future, if there is a demand for it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@krk

krk commented May 19, 2025

Copy link
Copy Markdown
Contributor

There is a use case to record all allocations, in case the process is short-running or if this is executed as part of a CI, to verify lack of leaks. We could make the tail feature optiona, opt-out perhaps.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apangin added 4 commits May 21, 2025 02:34
@apangin
Skip last 10% allocations for leak detection
223fa5f
@apangin
Extract TAIL constant
9c276a1
@apangin
Configurable tail for leak profiling
c6da427
@apangin
md format
1577a4f
@apangin
apangin force-pushed the leak-tail branch from 238c565 to 1577a4f Compare May 21, 2025 01:35
@apangin
Off-by-1 error
db635b8
@apangin

apangin commented May 21, 2025

Copy link
Copy Markdown
Collaborator Author

OK, made this configurable with --tail option. Updated docs.

krk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fandreuz

fandreuz commented May 21, 2025

Copy link
Copy Markdown
Contributor

Looks good to me

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apangin
apangin merged commit d89ab7a into master May 21, 2025
@apangin
apangin deleted the leak-tail branch May 21, 2025 12:28
@apangin apangin mentioned this pull request May 26, 2025
Support leak detection of customer memory pool #1313
Open
2 tasks
roy-soumadipta pushed a commit to roy-soumadipta/async-profiler that referenced this pull request Jun 20, 2025
@apangin @roy-soumadipta
Skip last 10% allocations for leak detection (async-profiler#1299)
af23d9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@apangin @Baraa-Hasheesh @fandreuz @krk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.