Immediate Fix (Method 1): Increasing Your Swap File
The fastest way to stop Kali Linux from crashing due to memory exhaustion is to increase your Swap space. This provides a “safety net” on your hard drive when your physical RAM is completely full.
Follow these commands to create a 4GB swap file immediately. This acts as virtual memory to prevent the desktop environment from freezing during intensive tasks.
# Disable existing swap
sudo swapoff -a
# Create a 4GB swap file
sudo fallocate -l 4G /swapfile
# Set correct permissions
sudo chmod 600 /swapfile
# Set up the swap area
sudo mkswap /swapfile
# Enable the swap
sudo swapon /swapfile
# Make it permanent by adding to fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Technical Explanation: The Linux OOM Killer
When Kali Linux runs out of physical RAM and has no available swap space, the kernel triggers a mechanism called the “Out of Memory (OOM) Killer.” This utility protects the system’s core by force-terminating high-memory processes.
On a Kali system, the OOM Killer often targets resource-heavy tools like Firefox, Burp Suite, or Metasploit. When these critical processes are killed unexpectedly, it results in the desktop environment crashing or returning you to the login screen.

Alternative Methods to Prevent Crashes
Method 2: Adjusting “Swappiness” Levels
You can control how aggressively Kali uses the swap file by changing the “swappiness” value. A lower value keeps more data in physical RAM, while a higher value moves data to the disk sooner.
# Check current swappiness (default is usually 60)
cat /proc/sys/vm/swappiness
# Set swappiness to 10 (recommended for SSDs)
sudo sysctl vm.swappiness=10
Method 3: Limiting Resource-Heavy Applications
If you are running Kali in a Virtual Machine (VM), ensure you have allocated at least 4GB of RAM in your hypervisor settings. Closing background tabs in Firefox can also significantly reduce the memory footprint during penetration testing.
| Solution | Difficulty | Effectiveness |
|---|---|---|
| Increase Swap File | Low | Very High |
| Adjust Swappiness | Medium | Moderate |
| Allocate More VM RAM | Low | High |