Skip to content

Do not use /dev/zero to mmap anonymous memory - #48140

Merged
VSadov merged 3 commits into
dotnet:masterfrom
VSadov:mapLeak
Feb 11, 2021
Merged

VSadov merged 3 commits into
dotnet:masterfrom
VSadov:mapLeak

Conversation

@VSadov

@VSadov VSadov commented Feb 11, 2021 •

Copy link
Copy Markdown
Member

Long time ago /dev/zero was commonly used to map anonymous memory because MAP_ANON / MAP_ANONYMOUS was not universally supported.

Nowdays there is no reason for that and using MAP_ANON / MAP_ANONYMOUS saves one fd per mapping.

The limit for fd count could be modest (1024 is a typical default) and these can add up quickly when loading assemblies from streams.
Even when collectible context is used the count could be abnormally high since complete unloading requires 2 full GC cycles and can be delayed for other reasons.

Fixes:#47859

@ghost

ghost commented Feb 11, 2021

Copy link
Copy Markdown

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This looks like a typo that somehow makes no difference. The Qcall returns void -

void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrAssemblyArray,

@stephentoub stephentoub Feb 11, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that somehow makes no difference

Interesting. Does it just end up returning some garbage register value or something?

@VSadov VSadov Feb 11, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Most likely it was returning in a register that callers immediately used to store something else. No callers used the returned value.

The original idea was that the mismatch in the returns was the reason for the "leak". Turns out it was a bit deeper than that, and fixing the return type did not change anything.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cc: @janvorli

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The interop method would return whatever was in RAX / EAX / X0 / R0 at that point.

@VSadov VSadov added the area-PAL-coreclr only for closed issues label Feb 11, 2021
@ghost

ghost commented Feb 11, 2021

Copy link
Copy Markdown

Hello @VSadov!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@VSadov

VSadov commented Feb 11, 2021

Copy link
Copy Markdown
Member Author

Thanks!!

@VSadov
VSadov merged commit 59465d6 into dotnet:master Feb 11, 2021
@VSadov
VSadov deleted the mapLeak branch February 11, 2021 13:47
@ghost ghost locked as resolved and limited conversation to collaborators Mar 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-PAL-coreclr only for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants