> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 增加系统内存

## 简介

Yocto 构建通常需要编译大型组件（如 LLVM），这些组件需要大量内存。如果没有足够的 RAM 或交换空间，构建可能会因内存不足（OOM）错误而失败。本节介绍增加可用系统内存并提高构建稳定性的方法。

## 增加交换空间

如果您的构建因 OOM 错误而失败，请将交换空间增加到至少 32 GB（推荐：64 GB）。运行以下命令调整交换文件的大小

```bash theme={null}
sudo su root
swapon --show
swapoff /swapfile
fallocate -l 64G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
free -h
```

## 增加 zram

您还可以增加压缩内存交换（zram）以提高内存使用效率

```bash theme={null}
modprobe zram
zramctl /dev/zram0 --algorithm zstd --size "$(($(grep -Po 'MemTotal:\s*\K\d+' /proc/meminfo)/2))KiB"
mkswap -U clear /dev/zram0
swapon --discard --priority 100 /dev/zram0
```
