Commit 702f91d
perf(tuned): activate and configure zswap for postgresql tuned profile (#2077)
* perf: activate and configure zswap for postgresql tuned profile
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.
* Update ansible/tasks/setup-tuned.yml
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update ansible/tasks/setup-tuned.yml
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* chore: bump ami version vars
* Update ansible/tasks/setup-tuned.yml
* fix: spacing that GH editor messed up
* refactor: use modprobe module instead
* fix: avoid an error on the GH runners due to missing kernel module
* fix: the runners are also ubuntu, so just ignore if we cannot load this
* refactor(tuned): refactor based on feedback from Sam
* fix(tuned): errant quotes
* Update vars.yml
* chore: bump to test
* fix(tuned): switch from copy to lineinfil to avoid perm issues on the temp dir copy creates
* refactor(tuned): use command instead of lineinfile in case the original file contents change on us
* chore: bump to release
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Sam Rose <samuel@supabase.io>1 parent 8810dd7 commit 702f91d
3 files changed
Lines changed: 62 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
102 | 150 | | |
103 | 151 | | |
104 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments