2 GB RAM VPS: What It Can Run, the Memory Math, and How to Push It Further

A 2 GB VPS is the most misunderstood tier in hosting. It is genuinely too small for a modern Java stack with an unconstrained heap, and genuinely enough for a PHP or Go application serving tens of thousands of requests a day. The difference between those outcomes is almost never the hardware — it is whether anyone did the arithmetic on where the 2048 MB actually goes. This article does that arithmetic, then shows which knobs recover usable memory when the sum comes up short.

The real capacity of a 2 GB guest

Start with what the kernel and base OS take before your application runs. On a minimal Debian 12 or Ubuntu 24.04 image with systemd, journald, sshd and no GUI, expect roughly 180–260 MB resident. Add a database, a web server, a PHP-FPM pool and a cache, and the numbers climb quickly. Here is a realistic budget for a typical LEMP + PostgreSQL guest:

ComponentTypical RSSNotes
Kernel + systemd + journald200 MBDepends on modules and cgroup v2
nginx (worker_processes auto)60 MBScales with worker count
PHP-FPM, 10 children450 MB~45 MB per child with OPcache
PostgreSQL baseline250 MBPlus shared_buffers
Redis120 MBSmall dataset, no persistence
sshd, cron, monitoring agent60 MBEasy to underestimate
Subtotal before app heap~1140 MBLeaves ~900 MB of headroom

The trap is that free -m reports buff/cache as used, so people conclude they are out of memory when they are not. Read MemAvailable instead; it already accounts for reclaimable page cache and is the number the kernel uses for its own allocation decisions.

PHP-FPM: the single biggest lever

PHP-FPM child processes are usually the largest and least controlled consumer. Each child keeps its own copy of loaded extension and application memory, so the pool size multiplied by per-process RSS is your memory floor. A pool of 25 children at 45 MB is 1.1 GB — enough to make a 2 GB guest swap on its own.

; /etc/php/8.3/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 12
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 500
request_terminate_timeout = 30s

Derive max_children from measurement, not from a blog post: after a week of real traffic, read pm.max_children reached events in the pool’s slow log and the total processes line in systemctl status php8.3-fpm. If max_children is being hit while MemAvailable is still above 300 MB, raise it by two and watch again. pm.max_requests = 500 caps memory creep from long-lived processes without hurting OPcache much.

PostgreSQL on 2 GB: shared_buffers and the rest

The standard advice of shared_buffers = 25% of RAM is wrong at this size — 512 MB of shared buffers in a 2 GB guest leaves too little for per-connection work. On 2 GB, 256 MB is a better target; on 4 GB, 512 MB. The single most common cause of “Postgres is eating all the RAM” is not shared buffers at all — it is work_mem multiplied by the number of concurrent sorts across all connections.

# /etc/postgresql/16/main/conf.d/10-small-vps.conf
shared_buffers = 256MB
work_mem = 4MB
maintenance_work_mem = 64MB
effective_cache_size = 1GB
max_connections = 40
temp_buffers = 8MB

Do the multiplication explicitly: 40 connections × 8 MB peak work_mem per sort × 3 sorts per query = 960 MB worst case. That number is why work_mem starts at 4 MB and why a pooler matters. effective_cache_size is not an allocation — it is a planner hint that tells Postgres how much of the OS page cache it may assume, so set it to roughly shared_buffers plus what the kernel can realistically cache (about 1 GB here).

Cap the JVM and Node before they cap you

Both runtimes default to a fraction of total system RAM, which is exactly wrong on a shared guest. A JVM on a 2 GB VPS will happily set a maximum heap near 512 MB and reserve additional non-heap memory on top. Pin it explicitly:

java -Xms256m -Xmx512m -XX:MaxMetaspaceSize=128m \
     -XX:+UseSerialGC -jar app.jar

node --max-old-space-size=384 server.js

UseSerialGC is deliberate on a 1–2 vCPU guest: parallel and G1 collectors spin up GC threads whose benefit is lost when there are only two cores, while their memory overhead is not.

Swap: a seatbelt, not a strategy

A 2 GB guest without swap will OOM-kill under a transient spike — a cron job, an image resize, a backup. A 2 GB guest that swaps constantly is running a workload it cannot afford. The useful configuration is small and fast-failing: 1–2 GB of swap with a low vm.swappiness so the kernel prefers dropping page cache, plus a clear alert on sustained swap-in.

fallocate -l 2G /swapfile && chmod 600 /swapfile
mkswap /swapfile && swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
sysctl -w vm.swappiness=10
vmstat 1 5   # watch si/so

On NVMe-backed instances swap is tolerable; on network storage it is not, so check which your provider gives you before relying on it for anything but emergency headroom.

Measuring before you change anything

Every number in this article is a starting point, not a target. Before editing a single config file, take a baseline so you can tell whether your changes helped. Two tools cover almost everything on a small guest: smem for proportional memory per service, and pidstat for per-process CPU and I/O over time.

apt install -y smem sysstat
smem -tk -c "pss uss rss command" | sort -k1 -n | tail -15
pidstat -u -r -d 5 12 > /tmp/baseline-pidstat.txt
awk '/MemAvailable/{printf "available %.0f MB\n",$2/1024}' /proc/meminfo

Run the baseline at peak traffic, not at 3 a.m. The interesting question is what the box looks like when it is working hardest, and a quiet-hour sample will make almost any configuration look fine. Repeat the same measurement after each change and keep the files — three snapshots of pidstat output tell a clearer story than any dashboard.

What a 2 GB box genuinely runs well

  • WordPress with a page cache — 20k–60k monthly visits if Redis object cache and a static cache are in place.
  • Laravel or Symfony API — comfortable when the FPM pool is capped at 10–12 and heavy jobs are queued, not inline.
  • PostgreSQL primary for a small app — fine up to a few GB of data with a pooler in front.
  • Docker with 3–5 small containers — as long as each has --memory limits set, otherwise one container can starve the rest.
  • Go or Rust services — these genuinely fit; a Go binary serving 5k req/s can sit under 80 MB.

What it does not run well: Elasticsearch (2 GB is its floor before data), a full Kubernetes control plane, a Java monolith with a large heap, or a build server compiling anything substantial.

How to recover another 300–400 MB

Before upgrading the plan, check these in order. Each is a measurable win with no application changes — start by reading the plan specs on VirtualServersVPS so you know the guaranteed memory figure you are working within:

  1. Switch journald to Storage=volatile and cap SystemMaxUse=200M; on many images this alone frees 100–200 MB of cache pressure.
  2. Disable services you did not install: systemctl list-units --state=running and mask snapd, ModemManager, bluetooth, unattended distro upgrades mid-day.
  3. Set nginx worker_processes 1; — two workers on a 2 vCPU guest rarely help and each costs ~20 MB.
  4. Use redis-server --maxmemory 96mb --maxmemory-policy allkeys-lru instead of leaving Redis unbounded.
  5. Trim OPcache: opcache.memory_consumption=96 and opcache.interned_strings_buffer=8 is enough for most apps.

Run smem -tk (from the smem package) rather than top for this work. It reports PSS, which divides shared pages among the processes that map them, so you see real cost per service instead of double-counting the same library a dozen times.

Kernel-level tuning for a low-memory guest

Beyond the application stack, a handful of sysctl values change how the kernel behaves when memory gets tight. On a 2 GB guest the goal is to keep file cache disposable and avoid letting dirty pages accumulate into a writeback storm that a small disk cannot absorb.

# /etc/sysctl.d/90-small-vps.conf
vm.swappiness = 10
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
vm.vfs_cache_pressure = 50
vm.min_free_kbytes = 65536
net.core.somaxconn = 1024

dirty_ratio = 10 caps the dirty page pool at roughly 180 MB, which means writeback happens in smaller, more frequent batches rather than one large flush that stalls everything. vfs_cache_pressure = 50 makes the kernel prefer keeping dentry and inode cache, which reduces filesystem lookups — noticeable on frameworks that stat hundreds of files per request. Apply with sysctl --system and verify with sysctl -a | grep -E 'dirty|swappiness'.

When 2 GB stops being enough

Two signals say you have outgrown the tier: MemAvailable below 10% for more than a few minutes a day, or sustained swap-out throughput above ~200 KB/s. Either one means the working set no longer fits, and no amount of tuning changes that. The step to 4 GB doubles headroom for roughly linear cost; for many workloads that is the cheapest performance upgrade available, especially compared with shaving 30% off PHP execution time. If you are choosing a plan now, look at the memory guaranteed rather than the burst figure — the difference between a 2 GB plan with a dedicated allocation and one sharing a noisy host is the difference between predictable and merely average.

Leave a Reply