DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk9 min

Fixing “fork: Cannot Allocate Memory” on a 1 GB LAMP VPS

A practical runbook for resolving “fork: Cannot allocate memory” on a 1 GB LAMP VPS—covering swap, CommitLimit, Apache/PHP concurrency, database memory and when to upgrade.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The message -bash: fork: Cannot allocate memory means Linux refused to create a new process because its memory-admission rules could not guarantee the child process’s potential address space. It does not necessarily mean every byte of physical RAM is already used. On a 1 GB LAMP VPS, check commit accounting, swap, provider limits and short-lived spikes first; then cap Apache/PHP and database memory. Change vm.overcommit_memory only after inspecting the relevant limits, and treat repeated failures after tuning as evidence that the VPS is too small.

What the error actually means

When a shell starts a command, it normally calls Linux fork() to create a child process. The child initially resembles the parent and may later allocate or modify memory. Before allowing that operation, the kernel accounts for the child’s potential virtual memory under the system’s current overcommit policy. If the requested commitment cannot be admitted, the shell reports fork: Cannot allocate memory.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is different from a simple “free RAM” test. A machine can show apparently available memory while still being unable to admit another process because of committed address space, reserved memory, unavailable swap, a cgroup limit imposed by the VPS host, or a brief allocation spike. A process can also fail while the kernel is preserving emergency reserves for root and for critical system work.

The most useful distinction is between physical availability and commitment. MemAvailable estimates RAM that can be given to applications without swapping heavily. Committed_AS is the amount of virtual memory the kernel has promised to processes. CommitLimit is the policy ceiling for those promises. A fork can be rejected when Committed_AS is close to CommitLimit, even if free appears non-zero.

#1 Best Overall
Timetec 32GB KIT (2x16GB) DDR4 2400MHz (PC4-2400T) PC4-19200 UDIMM Desktop RAM – 288-Pin 1.2V CL17 Non-ECC Unbuffered DIMM Memory Module Upgrade
  • Capacity – 32GB RAM KIT (2 x 16GB Modules) Speed up to 2400MHz Non-ECC Unbuffered 288-Pin 1.2V UDIMM.
  • Specs – Black PCB Color and Dual Rank (2Rx8).
  • Compatibility – Designed for selected DDR4 Desktop PCs and workstations that support 288-Pin UDIMM memory. NOT compatible with Laptop SODIMM slots.
  • Installation – Plug-and-Play Upgrade, Quick and Easy to Install, no expertise required (please refer to your system's manual for guidelines).
  • Warranty – All Timetec products are high-quality and rigorously tested to meet stringent standards. Backed by Timetec Limited Lifetime Warranty and professional technical support based in the United States.

Recover access before changing anything

Do not close your only working root shell while the VPS is close to exhaustion. If SSH cannot create another session or command, use the provider’s web or serial console, or an already-open privileged shell. Avoid launching package managers, editors, backups and parallel service restarts until you know how much headroom remains; each can create several processes at once.

Capture a baseline in one compact command sequence:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
free -h
swapon --show
df -h
grep -E 'MemAvailable|SwapFree|SwapTotal|CommitLimit|Committed_AS' /proc/meminfo
sysctl vm.overcommit_memory vm.overcommit_ratio vm.overcommit_kbytes vm.user_reserve_kbytes

The final sysctl command may report an unavailable key on kernels that do not expose that setting; that is not itself an error condition. Save the output before killing processes or changing limits so you can compare the effect of each step.

First-response diagnostic runbook

1. Check RAM, swap and the filesystem

free -h shows total, used, available and swap figures. Focus on available, not merely the free column. A low MemAvailable combined with little or no SwapFree indicates genuine pressure. swapon --show confirms whether any swap device or file is active. If it prints no rows, the VPS currently has no active swap.

Use df -h to verify that the root filesystem has room for a swapfile and for logs. A full filesystem can prevent swap creation, log rotation and normal service recovery, producing symptoms that look like memory failure.

2. Compare commitment with its limit

Read the values from /proc/meminfo:

  • CommitLimit: the maximum committed address space under the current policy.
  • Committed_AS: the amount of address space already promised to processes.
  • SwapTotal and SwapFree: configured and currently unused swap.
  • MemAvailable: an estimate of RAM that can be allocated without severe reclaim.

On a strict-overcommit system, a Committed_AS value approaching CommitLimit is a direct warning that another fork or allocation may be refused. These numbers complement, rather than replace, process-level inspection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Find the largest processes

ps aux --sort=-%mem | head -n 20

Look for many Apache workers, PHP processes, database threads or an unexpectedly large command. The resident-memory percentage is a starting point, not a complete accounting of shared pages and future allocations. Still, it reveals whether one service or a rapidly multiplying worker pool is consuming the budget.

4. Check for kernel OOM activity

dmesg -T | grep -i -E 'out of memory|oom|killed process'
journalctl -k --no-pager | grep -i -E 'out of memory|oom|killed process'

Some VPS environments restrict access to kernel logs; an empty result does not prove that no kill occurred. If the kernel has already killed workers, record which service was selected and whether failures recur during traffic peaks.

Why “free memory” can look fine

Commit accounting is separate from the free column

Linux can reserve address space for processes that have not yet touched every page. Forking must account for the child’s potential use, so a process may be denied even when physical pages are not all occupied. The kernel’s overcommit policy determines how conservative that accounting is.

Rank #2
A-Tech Server 16GB Kit (2 x 8GB) 2Rx8 PC3L-12800E DDR3 1600MHz ECC Unbuffered UDIMM 240-Pin Dual Rank DIMM 1.35V Workstation Server Memory RAM Upgrade Stick Modules (A-Tech Enterprise Series)
  • Capacity: 16GB (2x 8GB Modules) | Type: DDR3 240-Pin | Speed: 1600MHz PC3-12800 / (PC3-12800E) | ECC Type: ECC-UDIMM (ECC Unbuffered DIMM) | Rank: 2Rx8 (Dual Rank x8) | Voltage: 1.35V
  • Designed for ECC UDIMM Compatible Servers/Workstations (Rated Speeds & ECC Capabilities are CPU Dependent). Not Compatible with Desktops/Laptops.
  • ECC Types can not be mixed | All installed modules must be ECC UDIMMs in order to function properly | A maximum of eight ranks per memory channel can be installed at once
  • All A-Tech memory modules undergo stringent quality control testing to ensure dependable and reliable performance
  • Backed by A-Tech's Limited Lifetime Warranty + Tech Support Team available to help before and after your purchase

Reserves protect recovery operations

Linux keeps reserves so privileged processes can recover a distressed system. Under strict overcommit, reducing user_reserve_kbytes to zero can allow a process to consume the reserve; subsequent attempts to execute even a simple command can then produce the same fork error. Do not “fix” the incident by deleting safety reserves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Provider and cgroup ceilings may be lower than the VPS’s advertised RAM

A hosting control group can cap memory or swap independently of what the guest kernel reports. If free shows capacity but allocations fail at a repeatable threshold, ask the provider for the container or cgroup memory limit and current usage. A guest-level tuning change cannot raise a host-enforced ceiling.

Short spikes matter

Compiling code, rotating logs, importing a database, restarting several services or handling a burst of PHP requests can create a temporary peak. The process may exit before you run free, leaving a reassuring snapshot after the failed fork. Correlate failures with traffic and scheduled jobs rather than relying on one observation.

Add swap when it is absent, but use it correctly

Swap contributes to the commit limit and can provide emergency headroom on a 1 GB machine. It is storage, not a substitute for RAM: sustained swapping makes requests slow and can still end in an out-of-memory kill. Follow the VPS provider’s supported swap procedure first, because some platforms disallow swapfiles or require a particular block device.

For a conventional Linux VPS that permits a swapfile, a typical procedure is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon --show
free -h

If fallocate is unsupported or creates an unsuitable file on the provider’s storage, use the provider’s documented alternative rather than improvising. To activate the file after reboot, add an /etc/fstab entry only when the provider permits it:

/swapfile none swap sw 0 0

Recheck SwapTotal, SwapFree, MemAvailable and the commit fields after enabling swap. Swap may resolve admission failures caused by an overly small commit limit, but it will not cure an Apache or database workload that continuously exceeds the physical capacity of the instance.

Understand vm.overcommit_memory before changing it

The kernel setting has three modes:

Mode Meaning Operational consequence
0 Heuristic overcommit The kernel estimates whether an allocation is likely to succeed.
1 Always overcommit Most commitment checks are relaxed; failures can be deferred until RAM and swap are exhausted.
2 Strict overcommit Total committed address space is limited to swap plus a configurable portion of RAM.

In mode 2, the default RAM component is 50 percent of physical memory unless vm.overcommit_ratio or vm.overcommit_kbytes changes it. Inspect CommitLimit, Committed_AS, swap and user_reserve_kbytes before making a policy decision.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Setting vm.overcommit_memory=1 is not a universal repair. It may make the immediate fork succeed by allowing promises the machine cannot keep, then increase the chance of severe reclaim and an OOM-killer event later. Documentation for database deployments warns that mode 1 disables overcommit handling and can increase overload risk. If you test a change, do it temporarily, record the original value, and monitor both memory pressure and service stability:

Rank #3
A-Tech Server 32GB Kit (2x16GB) DDR4 2400MHz PC4-19200 ECC UDIMM 2Rx8 Dual Rank 1.2V ECC Unbuffered DIMM 288-Pin Server & Workstation RAM Memory Upgrade Modules (A-Tech Enterprise Series)
  • A-Tech RAM Memory compatible for select DDR4 Server and Workstation systems only; (*WILL NOT WORK with Desktop or Laptop Computers/PCs*)
  • 32GB RAM Kit (2 x 16GB Modules); DDR4 DIMM 288 Pin; Speeds up to 2400MHz PC4-19200 (PC4-2400T)
  • ECC Unbuffered UDIMM; 2Rx8 - Dual Rank x8; JEDEC DDR4 standard 1.2V
  • Improves system performance, workload capacity, and reduces bottlenecks by increasing memory (RAM) resources
  • Note: This memory is ECC Unbuffered and cannot be mixed with different ECC types such as ECC Registered, ECC Load Reduced, or Non-ECC Unbuffered; (Memory compatibility can vary among different system models and their installed components; please verify compatibility and follow memory channel guidelines to ensure maximum performance)
sysctl vm.overcommit_memory
sudo sysctl -w vm.overcommit_memory=0

The example restores heuristic mode only if that was the previous policy; substitute the value you actually recorded. Do not write a permanent setting to /etc/sysctl.conf until the workload has been observed under the chosen policy and recovery reserves remain intact.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Tune Apache and PHP as one memory budget

Cap Apache concurrency

Prefork-style Apache starts a separate process for each active worker. Every PHP-capable worker can therefore be expensive, and a sudden increase in MaxRequestWorkers can exhaust a 1 GB host before the database is counted. Measure representative worker resident memory, reserve RAM for the operating system and database, then set MaxRequestWorkers (or the equivalent concurrency directive for your MPM) to a value that fits the measured budget.

Remove modules the application does not use and avoid running multiple copies of the same web stack. After changing the limit, validate the configuration before restarting and watch the worker count during peak traffic. A lower ceiling may queue requests, but that is safer than allowing unbounded process creation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a bounded PHP-FPM pool where compatible

PHP-FPM can separate PHP worker limits from the web-server parent. Set pm.max_children from observed PHP worker resident memory, not from a copied distribution default. Include idle workers, process-manager overhead and non-PHP services in the calculation. A pool that is too large recreates the original problem; one that is too small trades memory safety for request queueing and latency.

Account for scheduled jobs

Queue workers, command-line PHP scripts, image processing and deployment hooks run outside normal web concurrency. Schedule heavy jobs away from traffic peaks or give them explicit limits. A single import can overlap with the maximum web pool and database buffers, exceeding the combined budget even when each component looks safe in isolation.

Reduce database pressure without guessing

MySQL or MariaDB may reserve substantial buffer memory before query workload is considered. Inspect the database process resident set and connection count, then compare them with the memory left after Apache, PHP, the kernel and monitoring agents are accounted for.

  • Lower an oversized buffer pool or query cache only after checking application performance requirements.
  • Reduce maximum connections when the application does not need the configured ceiling.
  • Use connection pooling or application-side limits to prevent bursts of simultaneous sessions.
  • Measure again after each change; a smaller cache can increase disk I/O and query latency.

Do not tune the database in isolation. On a 1 GB VPS, the safe total is the sum of database resident memory, the maximum web/PHP workers, the operating system, swap activity and any scheduled jobs—not the database’s nominal configuration alone.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Decision tree: the fix that matches the evidence

Observed condition Next action What success looks like
No active swap and low MemAvailable Add provider-supported swap, then retest during the workload that triggered the error. Swap is visible in swapon --show; commit headroom and shell access remain stable.
Many Apache/PHP workers or a rising worker count Lower web concurrency and use a bounded PHP-FPM pool where the application supports it. Worker count stays within the measured RAM budget without repeated OOM events.
Database resident memory dominates Reduce buffers or connection limits while checking query and latency impact. Database memory falls and the application retains acceptable performance.
Mode 2 with Committed_AS near CommitLimit Review swap, ratio or kilobyte limits and recovery reserves before changing policy. Commit headroom is restored without deleting reserves or causing later OOM kills.
Failures continue after measured tuning Move to a VPS with more RAM or a managed plan that provides memory monitoring. The workload operates below capacity during normal peaks and maintenance jobs.

Common mistakes and safer alternatives

  • Relying on free alone: inspect MemAvailable, SwapFree, CommitLimit and Committed_AS together.
  • Setting overcommit mode 1 reflexively: understand that deferred failure can become an OOM-killer event; preserve the original setting until you have evidence.
  • Adding huge swap and declaring victory: swap provides headroom but does not make sustained RAM overuse fast or safe.
  • Killing random processes from the only shell: preserve a console session and identify the service consuming memory first.
  • Copying Apache, PHP-FPM or database defaults: calculate limits from measured per-worker and resident memory on this specific 1 GB host.
  • Restarting everything simultaneously: stagger restarts so startup allocations do not create a second peak.

When upgrading is the correct fix

If the VPS still reaches its memory or commit ceiling after swap, concurrency and database settings are measured and bounded, the workload has exceeded the safe operating envelope of 1 GB. More tuning can only reduce throughput or reliability. Upgrade RAM or move to a larger managed VPS, preferably one with host-level memory monitoring and a console for recovery. Treat that as a capacity decision, not as a failure of Linux configuration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.