Linux Memory — From RAM to WordPress Hosting
We now go one level deeper.
Previously:
Internet
↓
Nginx
↓
PHP-FPM
↓
WordPress
↓
MySQL
↓
Linux processes
Now ask:
Where do those processes actually live while they are running?
The answer begins with:
RAM
1. What Is RAM?
RAM means:
Random Access Memory
It is the computer’s fast working memory.
When a program is running:
Program on disk
↓
loaded into RAM
↓
CPU executes it
2. Disk vs RAM
Your VPS has storage:
SSD / NVMe
and memory:
RAM
They are different.
Disk
Stores data persistently:
WordPress files
PHP files
MySQL database
logs
images
RAM
Holds data actively being used:
running programs
temporary data
cached data
kernel data
3. RAM Is Temporary
If the server loses power:
RAM
↓
contents disappear
But:
SSD
↓
data remains
assuming the storage itself isn’t damaged.
4. Why Programs Need RAM
Suppose you have:
/usr/sbin/nginx
on disk.
When Nginx runs:
nginx executable
↓
RAM
↓
process
The CPU works with memory rather than directly executing the program from the storage device in the normal model.
5. CPU + RAM
Think:
CPU
│
▼
RAM
│
▼
Disk
Very roughly:
CPU
=
does calculations
RAM
=
working area
Disk
=
persistent storage
6. Why RAM Is Faster Than Disk
RAM is designed for fast random access.
Storage devices are persistent but generally slower than RAM for active memory access.
Therefore operating systems try to keep actively used information in memory.
7. Linux Memory Is Not Just “Free or Used”
Run:
free -h
You might see something like:
total used free shared buff/cache available
Mem: 8Gi 3Gi 1Gi ... ... ...
Swap: 2Gi ... ...
The exact values depend on your server.
8. free -h
This is one of the most important commands for server administration:
free -h
The:
-h
means human-readable units.
9. Total Memory
Example:
total = 8 GiB
means the system has roughly 8 GiB of RAM available to the operating system, subject to hardware/platform reservations.
10. Used Memory
The meaning of “used” depends on the Linux memory accounting model and version.
Don’t immediately assume:
used = bad
Linux intentionally uses otherwise-unused RAM for useful caching.
11. Free Memory
free is memory that is currently unused.
But:
Low free memory does not automatically mean the server is out of memory.
Linux can reclaim cache when applications need memory.
12. Available Memory
This is one of the most useful values.
Conceptually:
available
=
memory Linux estimates it can make available to applications
without severe memory pressure
So when checking:
free -h
pay close attention to:
available
not just:
free
13. Buffers and Cache
Linux uses memory to cache data.
Conceptually:
Disk
↓
RAM cache
↓
faster future access
For example:
WordPress file
↓
read from disk
↓
cached in RAM
Later access may be faster.
14. Why Linux Uses “Unused” RAM
Suppose:
8 GB RAM
and applications only require:
3 GB
Linux can use some of the remaining memory for:
filesystem cache
instead of leaving it completely idle.
15. Cache Can Be Reclaimed
Suppose an application suddenly needs more memory.
Linux can reclaim suitable filesystem cache.
Conceptually:
Cache
↓
reclaim
↓
RAM available to application
Therefore:
cache ≠ permanently occupied application memory
16. Important Hosting Principle
Do not say:
My VPS has only 500 MB free, therefore it is full.
Instead inspect:
free -h
and look at:
available
plus swap and actual process usage.
17. Process Memory
Every process consumes memory.
For example:
Nginx
↓
RAM
PHP-FPM
↓
RAM
MySQL
↓
RAM
18. Multiple PHP Workers
Suppose PHP-FPM has:
10 workers
Each worker may use some amount of memory.
Conceptually:
PHP worker 1 → 100 MB
PHP worker 2 → 100 MB
PHP worker 3 → 100 MB
...
The actual usage varies substantially by WordPress site, plugins, workload, PHP version, and request.
19. Why Worker Count Matters
Suppose you configure:
pm.max_children = 50
That does not mean the server will always consume 50 × some fixed amount.
But under sufficient load, many workers can become active simultaneously.
If each active worker becomes memory-heavy:
many workers
↓
high RAM consumption
20. Simplified Capacity Model
For planning, think:
Total RAM
-
OS
-
MySQL
-
Nginx
-
PHP-FPM
-
other services
-
safety margin
=
RAM available for growth
This is much more useful than simply counting websites.
21. Website Count Does Not Determine RAM
For example:
10 static websites
may require very little application memory.
While:
3 busy WordPress websites
with heavy plugins may require substantially more.
So:
number of websites
≠
memory requirement
22. WordPress Is Dynamic
A WordPress request can involve:
Nginx
↓
PHP-FPM
↓
WordPress
↓
plugins
↓
theme
↓
database
Each layer can consume resources.
23. Example Request
User visits:
https://example.com/shop
The request may trigger:
Nginx
↓
PHP worker
↓
WordPress
↓
WooCommerce
↓
plugins
↓
MySQL queries
This can require substantially more CPU and RAM than serving a simple static HTML file.
24. Virtual Memory
Linux doesn’t simply give every process a raw piece of physical RAM.
It provides:
Virtual Memory
Conceptually:
Process
↓
Virtual address space
↓
Linux memory management
↓
Physical RAM
25. Why Virtual Memory?
It gives processes an abstraction where each process has its own virtual address space.
This provides:
isolation
flexibility
memory protection
efficient sharing
26. Process Isolation
Imagine:
PHP process A
and:
PHP process B
They should not normally be able to arbitrarily overwrite each other’s memory.
The operating system’s memory protection mechanisms help enforce this separation.
27. Virtual Address
A process might use an address such as:
0x7f123456
That is a virtual address.
The CPU’s memory-management hardware and Linux determine where the corresponding data resides in physical memory.
28. Pages
Memory is managed in units called:
Pages
A common page size is:
4 KiB
though systems can support other page sizes.
Conceptually:
Virtual memory
│
├── Page
├── Page
├── Page
└── Page
29. Page Table
Linux and the CPU use:
Page Tables
to map virtual addresses to physical memory.
Conceptually:
Virtual Page
↓
Page Table
↓
Physical Page
30. Why This Is Powerful
A process can think it has a large continuous address space even though its physical memory may be:
spread across different physical pages
The operating system manages the mapping.
31. Memory Protection
Page-level permissions can distinguish memory as:
readable
writable
executable
This is an important part of modern operating-system security.
32. Stack
A process has a:
Stack
The stack is commonly used for things such as:
function calls
local variables
return information
Conceptually:
Process
├── Code
├── Heap
├── Stack
└── Other mappings
33. Heap
The:
Heap
is memory used dynamically by programs.
For example:
program running
↓
needs more dynamic memory
↓
heap allocation
PHP and other software make extensive use of dynamically allocated memory.
34. Code / Text Segment
The executable code of a program is mapped into memory.
Conceptually:
Process memory
│
├── Code
├── Data
├── Heap
└── Stack
The exact layout is more complex on modern systems.
35. Shared Libraries
Programs often use shared libraries.
For example:
PHP
↓
shared libraries
Rather than every process keeping a completely separate copy of identical library code, the operating system can share suitable memory pages.
36. Shared Memory
Multiple processes can sometimes share memory intentionally.
This can improve efficiency for some workloads.
Conceptually:
Process A
↘
Shared Memory
↗
Process B
37. Swap
Now we reach an important server concept:
Swap
Swap is storage space that Linux can use as backing for memory pages when appropriate.
It can be:
swap partition
or:
swap file
38. Swap File
You previously worked with swapfile concepts on your VPS.
A swap file might be:
/swapfile
Linux can use it as swap space.
39. Is Swap RAM?
No.
This distinction is critical.
RAM
=
physical memory
Swap
=
storage used as backing for memory management
40. Why Is Swap Much Slower?
RAM is designed for memory access.
Storage is much slower for random memory-style access.
So:
RAM
↓
fast
while:
Swap
↓
much slower
The exact performance depends on the storage device and workload.
41. Swap Is Not a Replacement for RAM
Don’t think:
8 GB RAM
+
8 GB swap
=
16 GB fast RAM
It is not.
A better model is:
8 GB RAM
+
8 GB emergency/backing capacity
with significant performance penalties if heavily relied upon.
42. Why Servers Use Swap
A small amount of swap can be useful.
It can provide additional breathing room during temporary memory pressure and can help the system avoid immediate failure in some situations.
But sustained heavy swapping usually indicates insufficient memory or a workload/configuration problem.
43. Swap Usage
Check:
free -h
You might see:
Swap:
total
used
free
You can also run:
swapon --show
44. swapon --show
This shows configured active swap devices/files.
Example:
/swapfile
45. Disk vs Swap
Don’t confuse:
/var/www/
with:
/swapfile
Both may reside on the same SSD, but they serve completely different purposes.
46. Memory Pressure
Suppose:
RAM = almost full
and applications keep requesting memory.
Linux may:
reclaim cache
↓
compress memory if configured
↓
use swap when appropriate
↓
eventually encounter allocation failure
47. OOM
OOM means:
Out Of Memory
If Linux cannot satisfy memory demands, the system may invoke the:
OOM Killer
48. OOM Killer
The Linux kernel can terminate selected processes to recover memory.
Conceptually:
RAM exhausted
↓
memory allocation failure
↓
OOM handling
↓
process killed
↓
memory recovered
49. Why This Is Dangerous for Hosting
Imagine:
MySQL
PHP-FPM
Nginx
all running.
If memory pressure becomes severe, a critical process could be terminated.
Then:
WordPress
↓
database unavailable
or:
Nginx
↓
stops responding
50. Check Kernel Logs
For memory-related events:
dmesg | grep -i oom
or:
journalctl -k | grep -i oom
Depending on permissions and configuration, you may need:
sudo dmesg
51. Memory Monitoring
Use:
free -h
for a quick summary.
Use:
top
for live process-level information.
52. top Memory Columns
In top, you’ll see information such as:
VIRT
RES
SHR
%MEM
These require some explanation.
53. VIRT
VIRT represents the process’s virtual memory footprint/address space.
It is not the same as physical RAM actually occupied.
Therefore:
VIRT = 2 GB
does not necessarily mean:
RAM = 2 GB
54. RES
RES means resident memory.
It is a useful approximation of the amount of physical RAM currently resident for the process, although shared memory accounting means it should not be interpreted as a simple billable per-process total.
55. SHR
SHR represents memory associated with shared pages/mappings.
Again, process memory accounting is more complicated than simply adding all RES values.
56. Why Can’t You Simply Add Everything?
Suppose:
PHP worker A
RES = 100 MB
PHP worker B
RES = 100 MB
Some pages may be shared.
Therefore:
100 + 100
doesn’t necessarily mean:
200 MB of unique physical RAM
57. ps
You can inspect memory usage:
ps aux --sort=-%mem | head
This lists processes sorted by memory usage.
58. Find the Biggest Memory Users
A useful command:
ps aux --sort=-rss | head
This sorts approximately by resident memory.
59. Typical Hosting Memory Consumers
On a WordPress VPS, significant memory users can include:
MySQL
PHP-FPM
Nginx
system services
monitoring software
control panels
backup tools
The exact ranking varies by workload.
60. MySQL Memory
MySQL uses memory for:
buffer pool
connections
sort buffers
temporary structures
table caches
other internal structures
For InnoDB-heavy WordPress installations, the buffer pool is particularly important.
61. InnoDB Buffer Pool
We will go deeper later, but understand the basic concept now:
MySQL
↓
InnoDB
↓
Buffer Pool
↓
RAM
The buffer pool caches frequently used table and index pages in memory.
62. Why Buffer Pool Helps
Without caching:
query
↓
disk
↓
data
With a useful cache:
query
↓
buffer pool
↓
data
Memory access can be much faster than storage access.
63. WordPress Memory
A WordPress request can use memory for:
PHP runtime
WordPress core
theme
plugins
query results
objects
buffers
Heavy plugins can increase memory requirements.
64. PHP Memory Limit
WordPress/PHP may have limits such as:
memory_limit = 256M
This means a PHP process/request may be restricted by PHP’s memory limit.
It does not mean:
the server has exactly 256 MB for PHP
65. PHP Memory Limit vs VPS RAM
Suppose:
VPS RAM = 8 GB
and:
PHP memory_limit = 256M
This does not mean you can safely run:
32 PHP workers
without considering their actual memory use and other processes.
66. Worker Capacity
A simplified planning model:
PHP memory per busy worker
×
maximum concurrent workers
=
potential PHP memory demand
Then add:
MySQL
Nginx
OS
other services
safety margin
67. Example
Suppose actual PHP worker RSS under your workload is approximately:
80 MB
and you allow:
20 workers
Very roughly:
80 × 20
=
1600 MB
So PHP could potentially consume around:
1.6 GB
under conditions where all 20 workers reach that memory footprint.
This is a planning approximation, not a guaranteed fixed consumption.
68. Add MySQL
Suppose:
PHP = 1.6 GB
MySQL = 2 GB
Nginx + OS + other = 1 GB
Then:
≈ 4.6 GB
before additional headroom and caching behavior are considered.
An 8 GB server could be reasonable for such a workload, but actual measurements should drive the final configuration.
69. Why “How Many Websites Can I Host?” Has No Simple Answer
Because:
website count
is not the correct capacity metric.
Better metrics are:
requests per second
concurrent PHP requests
PHP worker memory
database workload
database memory
disk I/O
CPU usage
RAM usage
70. Static vs WordPress
Compare:
Static HTML
with:
WordPress + WooCommerce + plugins
The second usually requires considerably more server-side processing.
Therefore a server might host:
hundreds of low-traffic static sites
while handling far fewer:
high-traffic dynamic WordPress sites
depending on architecture and resources.
71. Memory and Concurrency
This is one of the deepest hosting concepts.
Imagine:
100 visitors
arrive at once.
If every request requires a PHP worker:
100 concurrent PHP requests
could create substantial memory pressure.
But caching can change the situation dramatically.
72. Page Cache
If a WordPress page can be served from cache:
Visitor
↓
Nginx/page cache
↓
HTML
PHP may not run for every request.
This can reduce:
CPU
RAM
database load
73. Full-Page Cache
Without cache:
Visitor
↓
Nginx
↓
PHP
↓
WordPress
↓
MySQL
With effective full-page caching:
Visitor
↓
Cache
↓
HTML
This is a major reason caching is important in hosting.
74. Object Cache
WordPress can also use object caching.
Conceptually:
WordPress
↓
Object Cache
↓
cached database-related objects
Systems such as Redis can be used for this purpose.
75. Database Cache
MySQL/InnoDB also has its own caching mechanisms.
So a real request can benefit from multiple layers:
Browser cache
↓
CDN cache
↓
Nginx/page cache
↓
Object cache
↓
MySQL/InnoDB buffer pool
↓
Disk
Each layer can reduce work at the next layer.
76. Memory Hierarchy
Now you can see a bigger picture:
CPU registers
↓
CPU cache
↓
RAM
↓
SSD/NVMe
↓
Remote storage/network
Generally:
higher
speed
↑
lower
capacity
closer to the CPU.
77. Why Caching Exists Everywhere
Caching exists because different storage/memory layers have different speeds.
Example:
CPU
↓
L1/L2/L3 cache
↓
RAM
↓
SSD
A good system tries to keep frequently needed data closer to where it is used.
78. Memory Pressure and Hosting
When your server approaches serious memory pressure:
RAM
↓
cache reclaim
↓
swap
↓
slowdown
↓
OOM risk
Therefore a professional hosting server should not operate continuously at the absolute edge of available memory.
79. Practical Monitoring
Start with:
free -h
Then:
top
Then:
ps aux --sort=-%mem | head -20
Then inspect swap:
swapon --show
80. Check Memory Pressure
On Linux systems that expose it, you can inspect:
cat /proc/meminfo
This provides detailed kernel memory accounting.
81. /proc/meminfo
You will see values such as:
MemTotal
MemFree
MemAvailable
Buffers
Cached
SwapTotal
SwapFree
There are many more.
Don’t try to memorize them all yet.
82. The /proc Filesystem
This introduces another important Linux concept.
/proc
is a virtual filesystem exposing information about:
processes
kernel
memory
CPU
system configuration
It is not an ordinary disk directory containing regular stored files.
83. Process Information
For a process:
/proc/PID/
contains information about that process.
For example:
ls /proc/1
shows information related to PID 1.
84. Memory Information
cat /proc/meminfo
gives a much deeper view of system memory.
85. CPU Information
cat /proc/cpuinfo
shows processor information.
Again, you don’t need to memorize it now.
86. Linux Memory Mental Model
Memorize this:
Program
↓
Process
↓
Virtual Memory
↓
Pages
↓
Physical RAM
And when RAM becomes constrained:
RAM pressure
↓
reclaim cache
↓
swap if needed
↓
OOM risk
87. WordPress Hosting Mental Model
For your VPS:
VPS RAM
│
┌────────────┼────────────┐
▼ ▼ ▼
Nginx PHP-FPM MySQL
│ │
PHP workers Buffer Pool
│ │
└──────┬─────┘
▼
WordPress
The number of PHP workers and the database workload are major capacity considerations.
88. Most Important Commands
Memorize these:
free -h
top
ps aux --sort=-%mem | head
swapon --show
cat /proc/meminfo
nproc
89. The Complete Architecture So Far
USER
│
▼
DOMAIN
│
▼
DNS
│
▼
IP
│
▼
TCP
│
▼
TLS
│
▼
HTTP
│
▼
NGINX PROCESS
│
▼
PHP-FPM PROCESS
│
▼
WORDPRESS
│
▼
MYSQL PROCESS
│
▼
INNODB BUFFER POOL
│
▼
RAM
│
▼
CACHE / DISK
And underneath everything:
CPU
+
RAM
+
STORAGE
+
LINUX KERNEL
Lesson 052 — Core Principle
The key idea is:
RAM is the active working space of the server, and every running service competes for it.
For WordPress hosting, the most important memory consumers are often:
PHP-FPM workers
+
MySQL/InnoDB
+
OS
+
Nginx
+
other services
And the most important capacity concept is:
RAM capacity
≠
number of websites
Instead:
RAM capacity
=
concurrent workload
+
process memory
+
database memory
+
OS/services
+
safety margin
Next Lesson — 053
Linux Storage — From / to Your WordPress Files
We will go deeper into:
Disk
↓
Partition
↓
Filesystem
↓
Mount
↓
Directory
↓
File
↓
Inode
↓
Permissions
↓
Ownership
↓
Hard link
↓
Symbolic link
↓
Disk space
↓
Inode space
Then we will map exactly how your hosting structure works:
/storage/websites/
├── domain1/
├── domain2/
├── learn.cresignsys.com/
└── shop.cresignsys.com/
and why a website can have plenty of disk space but still fail because of permissions, inodes, mounts, or filesystem problems.
Leave a Reply