> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.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
```
