■ ■ ■ ■ ■ ■
preload-mimalloc/README.md
| 1 | + | # Vendored mimalloc |
| 2 | + | |
| 3 | + | |
| 4 | + | This is [mimalloc](https://github.com/microsoft/mimalloc) vendored for use in |
| 5 | + | our server code. You can upgrade mimalloc by editing `VERSION` in |
| 6 | + | `update-sources.sh` and re-running it. |
| 7 | + | |
| 8 | + | Usage sites in haskell projects look like: |
| 9 | + | |
| 10 | + | -- See 'preload-mimalloc/README.md' |
| 11 | + | -- We want this in all server binary executable sections |
| 12 | + | common preload-mimalloc |
| 13 | + | c-sources: ../preload-mimalloc/mimalloc/src/static.c |
| 14 | + | include-dirs: ../preload-mimalloc/mimalloc/include |
| 15 | + | cc-options: -DMI_MALLOC_OVERRIDE |
| 16 | + | |
| 17 | + | ## Usage in haskell projects |
| 18 | + | |
| 19 | + | In [#9447](https://github.com/hasura/graphql-engine-mono/pull/9447) we see |
| 20 | + | overloading the server with large and slow queries results in high memory usage |
| 21 | + | and what looks like a space leak, involving foreign data from libpq. |
| 22 | + | |
| 23 | + | See that ticket for details, but mimalloc helps (relative to my glibc) by: |
| 24 | + | |
| 25 | + | - better avoiding fragmentation, resulting in lower overall memory usage (4GB peak 2.8 aftervs. |
| 26 | + | - eagerly decomitting memory so that OS-reported memory usage is a useful |
| 27 | + | metric (we do the same in the haskell RTS by specifying |
| 28 | + | `--disable-delayed-os-memory-return`) |
| 29 | + | |
| 30 | + | We also benefit by standardizing this, rather than relying on users' glibc |
| 31 | + | version, which might vary in behavior, making debugging difficult. |
| 32 | + | |
| 33 | + | Other implementations such as tcmalloc or jemalloc were not tested but might |
| 34 | + | perform better or be more tunable. |
| 35 | + | |
| 36 | + | ### Why not LD_PRELOAD? |
| 37 | + | |
| 38 | + | It's most common and simplest to use the dynamic linker to override malloc. |
| 39 | + | This would work in docker containers we ship, but we want all users to have the |
| 40 | + | same (better) behavior out of the box. |
| 41 | + | |