Skip to content

allow custom memory allocator - mimalloc (linux,musl,glibc) #60467

@dufkaf

Description

@dufkaf

We are running lot of microservices in AKS cluster and tried Alpine Linux .NET Core docker images instead of Debian due to its size and runtime memory requirements. We see better RAM utilization - typical small aspnet microservice that consumes 200-400MB with debian/glibc consumes 100-250MB with alpine/musl. However we also noticed performance degradation issue with multithreaded memory heavy workloads. We see 30-40% slowdowns when compared to debian/glibc. We noticed it on service with 4-5GB in memory data set where REST API queries this data while the data set is updated on the background.

Looks like it is known issue of musl libc memory allocator - both old and new introduced recently.

https://www.linkedin.com/pulse/testing-alternative-c-memory-allocators-pt-2-musl-mystery-gomes
https://news.ycombinator.com/item?id=23081071 - discussion about its features notably no per thread heaps

As musl is also used in memory constrained/embedded environments, the features of the allocator (concurrency issues) is more a design choice than a bug.

There is custom memory allocator https://github.com/microsoft/mimalloc with quite positive reviews overall that tries to solve such issues.

Would it make sense to support mimalloc on Alpine Linux (or even Debian/Ubuntu or Windows) as part of .net runtime build to replace default OS allocator?

Since there is garbage collector and its own memory handling in CLR that may possibly be tuned at build time to musl/glibc, is it worth even trying to just blindly LD_PRELOAD mimalloc on Alpine or Debian when starting .net core app without any support in the runtime?

Alpine Linux is one of three .NET Linux docker images supported and published and is promoted by members of .NET Team as a better choice (e.g. here https://devblogs.microsoft.com/dotnet/staying-safe-with-dotnet-containers/ "We also recommend Alpine because ..." ) however looks like at least for us the current performance of Alpine is lacking when compared to more heavy Linux docker images.

Feel free to change type of this issue, "performance" felt like best fit.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions