Container & RAM Tuning
Linux zram, Swappiness & NVMe Guardrails for Dify KVM Nodes
Add a 2-4 GB compressed zram safety net and set vm.swappiness=10 so sudden PDF ingestion bursts slow gracefully instead of OOM-killing Postgres.
vm.swappiness=10 · 2-4 GB zram · Zero Sudden OOM Kill
Graceful Degradation During Bulk Uploads
Even with tight Compose limits, a user uploading a 150-page scanned PDF can briefly spike memory. A small zram swap buffer absorbs transient Python allocations without touching slow disk swap or killing the Postgres process.
Never Rely on Swap for HNSW Graphs
Swap is strictly an emergency airbag for Celery spikes, never a substitute for fitting active pgvector HNSW graphs in physical KVM RAM.
Measured Thresholds & Container Limits
| Kernel Parameter | Recommended Value | Why It Matters for Dify |
|---|---|---|
| vm.swappiness | 10 | Keeps pgvector HNSW hot in RAM; swaps only cold pages |
| zram Device Size | 25% of physical RAM | Compresses idle Python pages 2.5x in RAM |
| vm.overcommit_memory | 0 (default) or 1 for Redis | Prevents Redis BGSAVE fork allocation failures |