Back to articles
AI & Cloud

Optimizing Linux Virtual Memory with Sysctl VM: Solution to Enhance VPS Performance Running Large Databases in RAM

Guide to optimizing Linux virtual memory using sysctl vm to improve VPS performance when running large databases in RAM, including configuration, verification, and troubleshooting.

DPTCloud Engineering4 min read
Optimizing Linux Virtual Memory with Sysctl VM: Solution to Enhance VPS Performance Running Large Databases in RAM

Optimizing Linux Virtual Memory with Sysctl VM

Optimizing virtual memory on Linux through sysctl vm parameters is a critical step to improve VPS performance when running large database applications such as PostgreSQL, MySQL, or AI models that require substantial memory. Proper optimization helps the system manage RAM and swap more efficiently, reducing latency and increasing processing speed.

Introduction to Sysctl VM

sysctl is a utility that allows users to adjust Linux system parameters at runtime. The vm group focuses on virtual memory management, including RAM, swap, and cache. Key parameters like vm.swappiness, vm.dirty_ratio, and vm.vfs_cache_pressure directly impact system performance.

Important Parameters and Configuration

Below are key parameters and recommended configurations for VPS running large databases:

Parameter Recommended Value Description
vm.swappiness 10 Reduces swap usage to prioritize RAM. Lower values help minimize access latency.
vm.dirty_ratio 10 Limits the percentage of dirty pages before writing to disk. Lower values reduce I/O bottlenecks.
vm.dirty_background_ratio 5 Percentage of dirty pages written to disk in background. Lower values reduce concurrent I/O load.
vm.vfs_cache_pressure 50 Adjusts how aggressively filesystem cache is purged. Lower values retain more cache.

Configuration and Application

To apply these parameters, edit the /etc/sysctl.conf file:

vm.swappiness = 10
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
vm.vfs_cache_pressure = 50

After saving changes, apply them immediately with:

sudo sysctl -p

Verification and Confirmation

After configuration, verify the current values using:

sysctl vm.swappiness
sysctl vm.dirty_ratio
sysctl vm.dirty_background_ratio
sysctl vm.vfs_cache_pressure

Ensure the values match the intended settings.

Troubleshooting

If the system experiences lag or freezing, check:

  • High I/O latency due to excessive swap usage. Monitor with vmstat 1.
  • Inefficient dirty page handling. Check with vmstat -s.
  • Excessively high swappiness value. Adjust if necessary.

References

For more information on Linux virtual memory management, refer to the official documentation:

Related infrastructure & engineering guides: Set Up S3 Gateway for Google Drive: Turn Google Drive into Professional Object Storage for Enterprises

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478