October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

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

A practical runbook for diagnosing “fork: Cannot Allocate Memory” on a 1 GB LAMP VPS, including commit accounting, swap, Apache/PHP limits, database tuning, and overcommit risks.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“fork: Cannot allocate memory” means Linux refused to create another process because its memory-admission rules could not guarantee the child’s address space. It does not necessarily mean every byte of physical RAM is already occupied. On a 1 GB LAMP VPS, the usual causes are missing swap, Apache/PHP worker growth, oversized database buffers, strict overcommit limits, or a provider/cgroup ceiling. Capture the state from a console, check commit statistics rather than only free, then reduce concurrency or database memory before changing overcommit policy. If failures continue after measured tuning, the instance has outgrown 1 GB.

What the fork error actually means

Linux creates a process with the fork() system call. The child initially resembles the parent, so the kernel must account for the memory the child could eventually need, even when copy-on-write means few pages are copied immediately. The kernel applies its virtual-memory policy before admitting that new process. If the potential commitment cannot be covered under the current policy, the shell reports an error such as -bash: 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.

That admission decision is different from asking how many pages are currently unused. A host can show apparently acceptable “free” memory while still lacking commit headroom, swap, reserved recovery space, or permission within a VPS cgroup. A short-lived spike from a package operation, PHP request, backup, or database connection can also make a fork fail between two memory samples.

Linux exposes the figures needed to distinguish these cases in /proc/meminfo. MemAvailable describes memory the kernel estimates can be allocated without swapping heavily; SwapFree shows immediately unused swap; CommitLimit is the current upper bound for committed address space; and Committed_AS is the amount already promised. In strict overcommit mode, an allocation that would push the latter beyond the former is rejected.

#1 Best Overall
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)

The policy is selected by vm.overcommit_memory:

  • Mode 0: heuristic overcommit. The kernel makes a reasoned estimate about whether a commitment is safe.
  • Mode 1: always overcommit. Admission checks are relaxed, but eventual physical exhaustion can trigger a more destructive out-of-memory event.
  • Mode 2: strict accounting. Total committed address space cannot exceed swap plus a configurable portion of RAM. The kernel documentation describes the default RAM component as 50 percent of physical memory.

Strict mode also protects a user reserve. The kernel documentation describes a failure mode in which setting user_reserve_kbytes to zero lets a process consume the reserve; subsequent attempts to execute commands then produce the same fork error. That is why a server may stop accepting even simple diagnostic commands while an existing session remains alive.

First response: preserve access and capture evidence

Do not begin by killing random processes or repeatedly reconnecting over SSH. Each new shell is another fork() request. Keep an existing root shell open, or use the VPS provider’s web console or serial console before making changes. If no session can spawn a command, the provider console is the recovery path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Record the state before intervention. Run the following from the surviving shell and save the output:
free -h
swapon --show
df -h
grep -E 'MemAvailable|SwapFree|CommitLimit|Committed_AS|SwapTotal' /proc/meminfo

df -h matters because a full filesystem can prevent a swapfile or service operation even when RAM is the original symptom. The combined memory output gives both ordinary headroom and commit-accounting headroom.

  1. Find the largest resident processes.
ps aux --sort=-%mem | head -n 20

Look for a rapidly growing Apache process family, many PHP workers, a database with an unexpectedly large resident set, or an unrelated job such as a backup, import, compiler, or malware scanner. A single snapshot identifies suspects; repeat it after a minute if the machine is still responsive to see whether a family is expanding.

Rank #2
OWC 32GB Memory RAM Kit Compatible with Synology DiskStation DS723+ DS923+
  • OWC 32GB UPGRADE: Consists of 2pcs of 16GB DDR4 2666MHz PC4-21300 CL19 2RX8 ECC SO-DIMM 1.2V 260-pin Memory Modules Compatible with Synology part numbers D4ECSO-2666-16G, D4ES01-16G
  • Compatible for Synology NAS DiskStation, RackStation, FlashStation, & NVR DVA Servers models: DS1522+, DS1618+, DS1621+, DS1621xs+, DS1819+, DS1821+, DS2419+, DS2419+II, DS2422+, DS3018xs, DS3617xs, DS3617xsII, DS3622xs+, DVA3219, DVA3221, FS1018, RS1221+, RS1221RP+, RS822+, RS822RP+
  • INCREASED PERFORMANCE: Memory Upgrades are the Most Effective and Easy Way to Boost the Performance of Your Server, Micro Server or NAS System
  • INDUSTRY LEADING: Consumer Friendly Advanced Replacement Program and Limited Lifetime Warranty, which Includes Free Tech Support by Other World Computing
  • EASY INSTALLATION: In Most Cases Installing Memory is an Easy DIY project. Watch our OWC Basic Installation Video for help.
  1. Check whether the kernel killed anything.
dmesg | tail -n 100
journalctl -k

Search the output for OOM-killer messages, rejected allocations, and the names of terminated processes. A logged OOM kill indicates that the machine reached a later stage of exhaustion; it does not prove that the earlier fork refusal had the same immediate cause.

  1. Inspect the active overcommit policy and reserves.
sysctl vm.overcommit_memory vm.overcommit_ratio vm.overcommit_kbytes vm.user_reserve_kbytes

On a mode-2 host, compare Committed_AS with CommitLimit, and note whether the configured ratio or absolute kilobyte value is unusually restrictive. Confirm that user_reserve_kbytes has not been set to zero as an attempted optimization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Change one variable at a time. Re-run the memory and process checks after each intervention. Avoid parallel package installs, simultaneous service restarts, and large database operations while the host is close to its limit; those activities create additional processes exactly when admission is failing.

How to read the numbers

Metric or observation What it tells you What to do next
MemAvailable Estimated RAM that can be given to new work without severe reclaim. Use it with process growth and swap data; do not treat it as the sole fork criterion.
SwapTotal or swapon --show reports none The host has no configured swap device or file. Follow the VPS provider’s supported swapfile procedure, then verify with swapon --show.
Low SwapFree Configured swap is already heavily occupied. Reduce active memory demand and investigate why; adding more swap does not fix a sustained RAM shortage by itself.
Committed_AS close to CommitLimit Commit accounting is near its admission ceiling, especially important in mode 2. Review swap and overcommit settings while preserving reserves; also reduce the workload’s promised memory.
Large Apache/PHP process count Web concurrency, rather than one oversized process, is consuming the budget. Cap Apache workers or PHP-FPM children using measured resident memory.
Large database resident set MySQL or MariaDB buffers, connections, or caches are taking a substantial share. Lower oversized buffers or connection limits after checking application requirements.
OOM-killer entries in the kernel log The host reached physical or cgroup exhaustion at some point. Identify the killed service, reduce peak demand, and consider a larger instance if the pattern repeats.

When no swap is configured

A 1 GB VPS with Swap: 0 0 0 has no emergency backing store for cold pages and a smaller commit limit under policies that count swap. A Huawei Cloud troubleshooting example shows the fork message in precisely such a no-swap state. That makes absent swap an important diagnostic branch, not proof that swap alone caused every incident.

Use the provider’s documented method for creating and enabling a swapfile; providers can impose filesystem, image, or policy requirements. After enabling it, confirm that swapon --show lists the device and that SwapTotal in /proc/meminfo is nonzero. Re-run free -h, the commit-field query, and the process listing before deciding whether the error is resolved.

Rank #3
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.

Swap supplies headroom for bursts and contributes to the commit limit, but it is storage, not additional fast RAM. If PHP workers or database queries continuously page, latency will rise and the service may remain unusable. Treat swap as a safety margin while reducing resident demand; do not use it to justify unlimited worker counts.

Control Apache and PHP memory together

Apache prefork growth

In a prefork-style Apache configuration, each PHP-capable worker is a separate process. The parent can therefore create many copies whose resident memory adds up quickly. A configuration that is comfortable on a multi-gigabyte server can exhaust a 1 GB machine during a traffic burst.

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

Measure representative Apache/PHP worker sizes in ps, reserve RAM for the kernel, database, and web-server parent, and set MaxRequestWorkers (or the equivalent concurrency limit for the active MPM) so the product fits the remaining budget. Remove modules the application does not use. Lowering the limit may produce queued requests or higher latency, but that is safer than allowing every request to create another memory-heavy process.

Bounded PHP-FPM pools

Where the application and Apache integration support it, PHP-FPM separates PHP worker concurrency from the web-server parent. Set pm.max_children from observed per-worker resident memory and the RAM left after the operating system, Apache, and database are accounted for. Do not copy a distribution default without measuring; a pool that is “small” on another host can still exceed this VPS’s budget.

Rank #4
A-Tech 128GB Kit (8x16GB) DDR4 2133MHz PC4-17000 ECC RDIMM 2Rx4 Dual Rank 1.2V ECC Registered DIMM 288-Pin Server & Workstation RAM Memory Upgrade Modules (A-Tech Enterprise Series)
  • A-Tech RAM Memory compatible for select DDR4 Servers & Workstation systems only; (*WILL NOT WORK with Desktop Computers, Laptop Computers, or PCs of any kind*)
  • 128GB RAM Kit (8 x 16GB Modules); DDR4 DIMM 288 Pin; Speeds up to 2133MHz PC4-17000 (PC4-2133P)
  • ECC Registered RDIMM; 2Rx4 - Dual Rank x4; JEDEC DDR4 standard 1.2V
  • Improves system performance, workload capacity, and reduces bottlenecks by increasing memory (RAM) resources
  • Note: This memory is ECC Registered and cannot be mixed with different ECC types such as ECC Unbuffered, 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)

After changing either limit, watch worker counts, request queues, MemAvailable, and swap activity during the busiest normal period. A lower process ceiling is successful when it prevents fork failures without merely moving the same pressure into an unbounded queue.

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

Keep MySQL or MariaDB inside the same 1 GB budget

The database competes with Apache and PHP for the same physical memory. Buffer pools, per-connection buffers, table caches, and connection limits can reserve substantial memory before query workload is considered. Use the process listing to establish the database resident set, then compare it with the application’s actual concurrency and query needs.

  • Reduce an oversized global buffer or cache only after checking the workload impact.
  • Lower maximum connections when the application cannot legitimately use the configured peak.
  • Account for per-connection memory, not just the headline buffer pool; simultaneous complex queries can create a short-lived spike.
  • Retest web requests and representative database operations after each adjustment.

Percona warns that setting vm.overcommit_memory to 1 disables overcommit handling and can increase the chance of memory overload and OOM-killer invocation. Making that change to accommodate a database or an ORM allocation can therefore trade an immediate fork refusal for a less predictable service-wide crash.

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

Should you change vm.overcommit_memory?

Do not use sysctl -w vm.overcommit_memory=1 as a universal repair. Mode 1 changes the admission policy; it does not create RAM or swap. Allocations that were previously rejected may succeed, only to fail later when pages must be materialized and the kernel has nowhere safe to put them.

Best Value
Sale
CORSAIR Vengeance LPX DDR4 RAM 32GB (2x16GB) Up to 3200MHz CL16-20-20-38 1.35V Intel XMP AMD EXPO Computer Memory – Black (CMK32GX4M2E3200C16)
  • Disclaimer: Maximum Speed requires overclocking/PC BIOS adjustments. Maximum speed and performance depend on system components, including motherboard and CPU
  • Hand-sorted memory chips ensure high performance with generous overclocking headroom
  • VENGEANCE LPX is optimized for wide compatibility with the latest Intel and AMD DDR4 motherboards
  • A low-profile height of just 34mm ensures that VENGEANCE LPX even fits in most small-form-factor builds
  • A solid aluminum heatspreader efficiently dissipates heat from each module so that they consistently run at high clock speeds

If the host is in mode 2, inspect all of the related values before choosing a policy:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • vm.overcommit_ratio and vm.overcommit_kbytes determine the configurable RAM component of the strict limit.
  • CommitLimit and Committed_AS show how close the machine is to that limit at the moment you sample it.
  • user_reserve_kbytes protects space needed by users and administrators to continue launching commands; do not eliminate that reserve to gain a few more megabytes for the workload.

A policy change is justified only when you understand why the current mode rejects a legitimate allocation, have recovery-console access, and have a workload-specific reason supported by measurements. Apply it temporarily if possible, monitor kernel logs and swap pressure, and be prepared to revert it. For a small production VPS, reducing memory demand is usually less risky than relaxing accounting.

A practical decision tree

Observed condition Priority action Expected trade-off
No swap and little headroom Add provider-supported swap, verify it, and retest. More burst headroom, but swap is slower than RAM and cannot support unlimited load.
Apache/PHP process family is large Lower Apache concurrency or set a bounded PHP-FPM pm.max_children based on measured worker size. Requests may queue or slow under peak traffic instead of crashing the host.
Database resident memory dominates Reduce oversized buffers and connection limits while validating application behavior. Lower cache hit rates or concurrency may increase query latency.
Mode 2 with CommitLimit near Committed_AS Review swap, ratio/kilobyte settings, and user reserves; reduce promised memory before relaxing policy. Strict accounting remains safe, but the application may need lower concurrency.
Failures continue after measured tuning Move to a larger managed VPS or cloud instance with memory monitoring. Higher capacity and cost; avoids operating permanently beyond a 1 GB envelope.

Recovery mistakes to avoid

  • Trusting one “free memory” number: fork admission also depends on commit accounting, swap, reserves, cgroups, and transient spikes.
  • Launching more diagnostics during exhaustion: repeated SSH attempts, editors, and package managers all need new processes.
  • Disabling reserves: setting user_reserve_kbytes to zero can leave the system unable to execute even basic commands under strict accounting.
  • Raising concurrency to hide a queue: more Apache workers or PHP children increase the probability of another fork failure.
  • Assuming swap is a cure: swap helps absorb bursts; sustained paging means the workload needs less memory or a larger server.
  • Changing several variables at once: you lose the ability to identify which adjustment helped and can make rollback difficult.

Preventing a repeat on a 1 GB VPS

Keep a small operational record of the values that were safe during normal and peak traffic: Apache worker count, PHP-FPM children, database resident memory, MemAvailable, SwapFree, CommitLimit, and Committed_AS. Review it after deployments, traffic changes, database imports, and configuration updates.

Set alerts before the kernel starts rejecting forks. A useful alert combines low available RAM, rising swap usage, a narrowing gap between CommitLimit and Committed_AS, and abnormal growth in Apache, PHP, or database processes. Keep console access and a tested rollback path for sysctl and service-limit changes.

Finally, treat repeated incidents after tuning as a capacity signal rather than a configuration puzzle. Apache/PHP concurrency, database buffers, the operating system, and the kernel all have to fit inside the same 1 GB allocation. When normal demand leaves no safe reserve, upgrading the VPS is the reliable fix.

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.

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.