# Performance Optimization for Low Memory Systems

If you are running Ubuntu on a machine with 4GB or 8GB of RAM, running heavy browsers and AI models will quickly exhaust your memory. These three configurations are mandatory for system stability.

### Installing ZRAM

Theory: ZRAM creates a compressed block device directly *inside* your RAM. Instead of moving inactive data to the slow SSD, Ubuntu compresses it in the RAM. This makes a 4GB machine perform as if it has 6GB+.

Bash

```
sudo apt install zram-config -y
```

### Adding Swap Memory

Theory: Swap is "emergency memory" located on your hard drive. If your RAM is 100% full, the OS moves data to Swap to prevent a total system crash.

If you didn't create a Swap partition during setup, create a Swap file:

Bash

```
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
```

*(To make this permanent, you must add `/swapfile none swap sw 0 0` to your `/etc/fstab` file).*

### Reducing Swappiness

Theory: "Swappiness" dictates how aggressively Linux moves data from RAM to your Swap. By default, Ubuntu's swappiness is 60, meaning it moves data to the slow disk too early. For lower memory systems, lowering this value forces the OS to utilize your fast RAM as much as possible.

Bash

```
# Open the system control file
sudo nano /etc/sysctl.conf

# Scroll to the bottom and add this line:
vm.swappiness=10

# Save (Ctrl+O, Enter), Exit (Ctrl+X), and apply changes:
sudo sysctl -p
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shankar-lab.gitbook.io/mylearning/ubuntu-installation-guide/performance-optimization-for-low-memory-systems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
