Skip to content

Flush the allocator when freed memory could push RSS past the limit - #9

Merged
utay merged 1 commit into
altertable-1.5.5from
backport-allocator-flush-1.5.5
Oct 27, 2026
Merged

utay merged 1 commit into
altertable-1.5.5from
backport-allocator-flush-1.5.5

Conversation

@leo-altertable

Copy link
Copy Markdown

The buffer pool accounts for allocated buffers, but freed buffers stay resident in jemalloc as dirty pages until its one second decay runs on the arena that owns them. During spilling this retained memory grew to roughly 70% of the memory limit on TPC-DS q67 and got the process killed inside a cgroup while the tracked usage was within the limit. Count the bytes handed back to the block allocator, which is where every buffer and operator allocation is freed, and purge the allocator on the next buffer pool allocation once at least a sixteenth of the memory limit has been freed and the tracked usage plus that amount exceeds the limit. Resident memory then stays within the memory limit plus a sixteenth, while queries that run well below the limit never pay for a purge. Counting at the allocator rather than in the pool's accounting keeps buffer reuse during eviction, tag changes and failed reservations from being mistaken for frees. The allocator_bulk_deallocation_flush_threshold setting keeps its single-deallocation meaning.

(cherry picked from commit 71e7ab8)

The buffer pool accounts for allocated buffers, but freed buffers stay resident in jemalloc as dirty pages until its one second decay runs on the arena that owns them. During spilling this retained memory grew to roughly 70% of the memory limit on TPC-DS q67 and got the process killed inside a cgroup while the tracked usage was within the limit. Count the bytes handed back to the block allocator, which is where every buffer and operator allocation is freed, and purge the allocator on the next buffer pool allocation once at least a sixteenth of the memory limit has been freed and the tracked usage plus that amount exceeds the limit. Resident memory then stays within the memory limit plus a sixteenth, while queries that run well below the limit never pay for a purge. Counting at the allocator rather than in the pool's accounting keeps buffer reuse during eviction, tag changes and failed reservations from being mistaken for frees. The allocator_bulk_deallocation_flush_threshold setting keeps its single-deallocation meaning.

(cherry picked from commit 71e7ab8)
@leo-altertable
leo-altertable requested a review from utay October 27, 2026 17:01
@utay
utay merged commit af4245d into altertable-1.5.5 Oct 27, 2026
60 of 75 checks passed
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.

3 participants