linux增加虚拟内存

The swap space is an area of the hard disk that is used when the RAM runs out of memory. If your system has enough RAM it is generally not necessary to have swap space. However, if you have installed Linux without creating any swap partition and later want some swap space, you can easily do so. You can either create a swap partition or create a swap file.

The swap file approach is simpler and safer if you want to add swap space post OS installation. Beside, swap file and swap partition have the same performance now. I carried out the instructions I am giving here on Ubuntu 10.10, but it should work on any other distributions as well.

The first thing we need to do is create an empty file of the required size. To do this open the Terminal and execute the command given below. In this example I am creating a 3GB swap file. You will not probably need that much. So, enter your own value.

$ cd /

$ sudo dd if=/dev/zero of=swapfile bs=1M count=3000

To set it as 1GB, change the count value (3000 in the example above) to 1000, 1500 for 1.5GB etc.

Now change the file created to a swap file with the command below.

$ sudo mkswap swapfile

Turn on the swap file with the command,

$ sudo swapon swapfile

To ensure that the swap file is turned on automatically at system startup, open fstab.

$ sudo nano etc/fstab

And add the line given below. Save and close.

/swapfile none swap sw 0 0

That is it. You can check if the system is using the swap file you created with the command

$ cat /proc/meminfo

[source]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值