feat(config): add jemalloc_background_thread option#1260
Open
IgorOhrimenko wants to merge 2 commits into
Open
Conversation
Adds a `[general]` option (also PGDOG_JEMALLOC_BACKGROUND_THREAD env), default off, that enables jemalloc's background purge threads at startup via tikv-jemalloc-ctl — equivalent to _RJEM_MALLOC_CONF=background_thread:true, so freed memory is returned to the OS after allocation bursts without requiring the env var. No-op on non-jemalloc builds (test/msvc). Refs pgdogdev#1230.
IgorOhrimenko
marked this pull request as ready for review
July 24, 2026 13:56
Assert the default (false) and env-var (PGDOG_JEMALLOC_BACKGROUND_THREAD) handling of the new option.
sgrif
requested changes
Jul 24, 2026
sgrif
left a comment
Contributor
There was a problem hiding this comment.
This doesn't need to be a config, we should be enabling this by default on all supported platforms. We don't need to be logging errors, this will only return an error on unsupported platforms
Contributor
|
/cc @levkk Since you asked for this to be a config option. I've never seen a scenario where jemalloc bg threads could be enabled and it wasn't desirable |
Collaborator
|
It was probably pre-second coffee and I wasn't thinking straight. I don't know why bg threads are disabled by default, so I was just thinking maybe we need to find out before unleashing this on everyone, so maybe an env var or something? Not sure. |
Contributor
|
Yeah, I don't think we need to worry about anything like that. This is pretty universally recommended to be enabled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements the config-based option suggested in #1230.
Adds a
[general]optionjemalloc_background_thread(defaultfalse, also settable viaPGDOG_JEMALLOC_BACKGROUND_THREAD). When enabled, PgDog turns on jemalloc's background purge threads at startup viatikv-jemalloc-ctl— the programmatic equivalent of_RJEM_MALLOC_CONF=background_thread:true— so freed memory is returned to the OS after bursts of large allocations instead of accumulating as retained dirty pages, without operators having to set the env var.test,msvc)..schema/).Docs: pgdogdev/docs#100.
Refs #1230.