perf(tuned): activate and configure zswap for postgresql tuned profile#2077
perf(tuned): activate and configure zswap for postgresql tuned profile#2077
Conversation
This change enables zswap with the zsmalloc allocator and zstd compression within the postgresql tuned profile to improve system responsiveness and database performance under memory pressure. ### Technical Overview: What is zswap? zswap is a Linux kernel feature that provides a compressed write-back cache for swapped pages. Instead of immediately moving pages from RAM to the physical swap device (HDD/SSD) when memory is full, zswap intercepts them, compresses them, and stores them in a dynamically allocated RAM pool. This effectively increases the "perceived" amount of RAM available to the system. ### Why zsmalloc over zbud? We have selected 'zsmalloc' as the zpool allocator instead of 'zbud' for several reasons: - Density: zsmalloc is a slab-based allocator that can pack many compressed objects into a single physical page, whereas zbud is hard-coded to a maximum of 2 objects per page (2:1 ratio). - Efficiency: On modern kernels (Linux 6.3+), zsmalloc supports proper eviction to disk, removing the primary historical advantage of zbud. It provides significantly better memory utilization and higher compression density. ### Why zstd over lz4? While lz4 offers faster compression/decompression speeds, we have opted for 'zstd' for the following reasons: - Compression Ratio: zstd provides a substantially higher compression ratio than lz4. In database workloads where memory density is critical, fitting more pages into the zswap pool is more beneficial than the marginal speed gains of lz4. - Balance: zstd offers a superior balance between CPU overhead and compression efficiency, especially for the 4KB-8KB pages typically handled by the kernel and PostgreSQL. ### Benefits for PostgreSQL Performance Implementing zswap is particularly beneficial for PostgreSQL workloads: - Mitigation of Swap Thrashing: PostgreSQL performance degrades exponentially when active buffers are swapped to disk. zswap ensures that these pages stay in RAM (compressed), allowing "major page faults" to be resolved at RAM speeds rather than waiting for disk I/O. - I/O Latency Stability: By reducing the frequency of physical writes to the swap partition, zswap prevents I/O contention between the kernel's swap subsystem and PostgreSQL's own WAL and data writes. - Consistent Query Latency: Queries that access less-frequently used data that has been compressed into zswap will return much faster than if they had to be fetched from physical swap, leading to more predictable p99 latencies.
There was a problem hiding this comment.
Pull request overview
This PR enables zswap with the zsmalloc allocator and zstd compressor for the PostgreSQL tuned profile, aiming to improve system responsiveness and reduce swap I/O pressure under memory-intensive PostgreSQL workloads.
Changes:
- Adds a new
community.general.ini_filetask to write a zswap configuration entry into the tunedpostgresqlprofile'stuned.conf.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…-488 * 'INDATA-488' of github.com:supabase/postgres: Update ansible/tasks/setup-tuned.yml Update ansible/tasks/setup-tuned.yml
|
@samrose i do not like having to add that when, but the runners don't have the module. open to ideas |
|
samrose
left a comment
There was a problem hiding this comment.
need to discuss and review before merge
* 'develop' of github.com:supabase/postgres: Add introductory line to README (#2078)
samrose
left a comment
There was a problem hiding this comment.
Just need to address accurate increment of version. Or it will have to be done over again when you merge, and the release will fail
… temp dir copy creates
…-488 * 'INDATA-488' of github.com:supabase/postgres: chore: bump to test Update vars.yml
…al file contents change on us
|
All tests passing https://github.com/supabase/supadev/actions/runs/22747411633 |
This change enables zswap with the zsmalloc allocator and zstd compression within the postgresql tuned profile to improve system responsiveness and database performance under memory pressure.
Technical Overview: What is zswap?
zswap is a Linux kernel feature that provides a compressed write-back cache for swapped pages. Instead of immediately moving pages from RAM to the physical swap device (HDD/SSD) when memory is full, zswap intercepts them, compresses them, and stores them in a dynamically allocated RAM pool. This effectively increases the "perceived" amount of RAM available to the system.
Why zsmalloc over zbud?
We have selected 'zsmalloc' as the zpool allocator instead of 'zbud' for several reasons:
Why zstd over lz4?
While lz4 offers faster compression/decompression speeds, we have opted for 'zstd' for the following reasons:
Benefits for PostgreSQL Performance
Implementing zswap is particularly beneficial for PostgreSQL workloads: