11.14. Adding Swap Space
前一頁 | 章 11. 設定與效能調校(Tuning) | 下一頁

## 11.14. Adding Swap Space

No matter how well you plan, sometimes a system does not run as you expect. If you find you need more swap space, it is simple enough to add. You have three ways to increase swap space: adding a new hard drive, enabling swap over NFS, and creating a swap file on an existing partition.

For information on how to encrypt swap space, what options for this task exist and why it should be done, please refer to 節 18.17, “Encrypting Swap Space” of the Handbook.

### 11.14.1. Swap on a New Hard Drive

The best way to add swap, of course, is to use this as an excuse to add another hard drive. You can always use another hard drive, after all. If you can do this, go reread the discussion of swap space in 節 11.2, “一開始的規劃” of the Handbook for some suggestions on how to best arrange your swap.

### 11.14.2. Swapping over NFS

Swapping over NFS is only recommended if you do not have a local hard disk to swap to; NFS swapping will be limited by the available network bandwidth and puts an additional burden on the NFS server.

### 11.14.3. Swapfiles

You can create a file of a specified size to use as a swap file. In our example here we will use a 64MB file called `/usr/swap0`. You can use any name you want, of course.

範例 11.1. Creating a Swapfile on FreeBSD

1. Be certain that your kernel configuration includes the memory disk driver (md(4)). It is default in `GENERIC` kernel.

   device md # Memory "disks"

2. Create a swapfile (`/usr/swap0`):

   `#` `dd if=/dev/zero of=/usr/swap0 bs=1024k count=64`

3. Set proper permissions on (`/usr/swap0`):

   `#` `chmod 0600 /usr/swap0`

4. Enable the swap file in `/etc/rc.conf`:

   swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.

5. Reboot the machine or to enable the swap file immediately, type:

   `#` `mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0`

前一頁 | 上一層 | 下一頁
11.13. Tuning Kernel Limits | 起始頁 | 11.15. Power and Resource Management

本文及其他文件，可由此下載： ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。

若有 FreeBSD 方面疑問，請先閱讀 FreeBSD 相關文件，如不能解決的話，再洽詢 <questions@FreeBSD.org>。
關於本文件的問題，請洽詢 <doc@FreeBSD.org>。