Skip to content

feat(config): add jemalloc_background_thread option#1260

Open
IgorOhrimenko wants to merge 2 commits into
pgdogdev:mainfrom
IgorOhrimenko:jemalloc-background-thread-config
Open

feat(config): add jemalloc_background_thread option#1260
IgorOhrimenko wants to merge 2 commits into
pgdogdev:mainfrom
IgorOhrimenko:jemalloc-background-thread-config

Conversation

@IgorOhrimenko

@IgorOhrimenko IgorOhrimenko commented Jul 24, 2026

Copy link
Copy Markdown

Implements the config-based option suggested in #1230.

Adds a [general] option jemalloc_background_thread (default false, also settable via PGDOG_JEMALLOC_BACKGROUND_THREAD). When enabled, PgDog turns on jemalloc's background purge threads at startup via tikv-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.

  • Opt-in (default off): no behaviour change unless enabled.
  • No-op on non-jemalloc builds (test, msvc).
  • JSON schema regenerated (.schema/).

Docs: pgdogdev/docs#100.

Refs #1230.

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.
@CLAassistant

CLAassistant commented Jul 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Assert the default (false) and env-var (PGDOG_JEMALLOC_BACKGROUND_THREAD)
handling of the new option.

@sgrif sgrif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@sgrif

sgrif commented Jul 24, 2026

Copy link
Copy Markdown
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

@levkk

levkk commented Jul 24, 2026

Copy link
Copy Markdown
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.

@sgrif

sgrif commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Yeah, I don't think we need to worry about anything like that. This is pretty universally recommended to be enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants