You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In followup to haskellari/postgresql-simple#114 β I've found a heavy heap fragmentation issue in my LO-intense workload β and determined that it's not the Haskell heap which got fragmented, but rather the C malloc one.
βοΈ Here, the reallocBytes call, while releasing the extra unused space under maxLen β will create differing-length allocations, which depend on LO sizes. So if I do tens of thousands of varying-size LO reads β this puts stress onto malloc to handle fragmentation well.
The fixed graph on the left β is exact same test running against exact same Haskell executable, but with LD_PRELOAD=jemalloc.so. The baseline on the right β with stock allocator in libc6 2.35-0ubuntu3.1 on Ubuntu 22.04.2 LTS.
Would you approve adding a flag jemalloc to the cabal-file here?
No. mallocBytes comes from base, and I don't have to worry about how it works & whether different allocators would conflict.
Okay, got it π Fair enough, good to know, thanks for reply π
I'm closing the issue then.
Had just one question β whether the LO buffers could be allocated on Haskell heap instead of C heap?
But will self-answer.
There's this mallocForeignPtrBytes API β it's fairly old, base-4.0.0.0 has it β conceptually equivalent to mallocBytes _ >>= newForeignPtr finalizerFree, but backed by newPinnedByteArray# instead.
Superficially it seems usable here β but it's not straightforward, due to unknown-beforehand allocation length which the reallocBytes call handles. So, without a realloc variation for bytearray-ForeignPtr's (which I don't seeΒΉ), we'll either "slop-leak" unused trailing memory, or will need buffer copying.
Hi again @phadej π
Asking for opinion before a PR.
In followup to haskellari/postgresql-simple#114 β I've found a heavy heap fragmentation issue in my LO-intense workload β and determined that it's not the Haskell heap which got fragmented, but rather the C malloc one.
postgresql-libpq/src/Database/PostgreSQL/LibPQ.hs
Lines 2012 to 2025 in 900abcb
βοΈ Here, the
reallocBytes
call, while releasing the extra unused space undermaxLen
β will create differing-length allocations, which depend on LO sizes. So if I do tens of thousands of varying-size LO reads β this puts stress ontomalloc
to handle fragmentation well.The
fixed
graph on the left β is exact same test running against exact same Haskell executable, but withLD_PRELOAD=jemalloc.so
. Thebaseline
on the right β with stock allocator in libc6 2.35-0ubuntu3.1 on Ubuntu 22.04.2 LTS.Would you approve adding a flag
jemalloc
to the cabal-file here?https://jemalloc.net/ to perhaps save you a search query π
The text was updated successfully, but these errors were encountered: