當前位置:才華齋>計算機>作業系統>

如何調整Linux系統中swap大小

作業系統 閱讀(8.1K)

使用free命令帶上m引數,檢視swap檔案大小,官方建議在RAM是2到4.5G時,swap是RAM的2倍;如果RAM大於等於4G則swap等於RAM即可

如何調整Linux系統中swap大小

也可用cat 檢視etc目錄下的s檔案,如下圖

建立一個swap檔案

########

dd if=/dev/zero of=/tmp/swap bs=1MBcount=1024

########

以下僅供參考:不用看

Creating a swap file

First of, make sure the file system the disk you wish to swap on is properly mounted. For the purposes of this tutorial we will assume the disk is mounted as/mntand we want to use the file/mnt/or swapping.

使用下面的命令建立一個1G的swap檔案

Use the following command to create a 1024MB file that we will use for swapping

########

dd if=/dev/zero of=/mnt/ bs=1024MBcount=1

########

製作一個swap檔案,如果覺得繁瑣,可以將mkswap檔案掛載到tmp目錄下,例如:

########

mkswap /tmp/swap

########

以下僅供參考:不用看

Preparing the swap file

Before we enable the swap file we must first set it up. The following command accomplishes just that:

########

mkswap /mnt/

########

使用swapon 啟動/tmp/swap

########

swapon /tmp/swap

########

使用一個swap分割槽,如果已經有一個swap分割槽,該步驟可以省略

以下僅供參考:不用看

Using a swap partition

Setting up a swap partition is a bit more difficult, as the partition must be first created then formatted using the linux-swap file system. Once that is done, assuming the swap partition is at/dev/scsi/host0/bus0/target0/lun0/part5(common for v24 USB drives with mutiple partitions), the only command that needs be issued is:

再次使用free檢視增加後的swap大小

如果只想增加swap大小,請忽略以下的操作(重要!!)

如果不使用剛才增加的1G的swap檔案,使用下面的swapoff命令,可以關閉,這樣swap檔案就縮小了1G

使用swapoff關閉swap檔案

########

swapoff /tmp/swap

########