修改树莓派SWAP交换文件大小来自国外网站

How to change Raspberry Pi's Swapfile Size on Raspbian

11 Feb 2015 Written by Shane Pfaffly

Reason Why

Ever get the dreaded error:

Virtual memory exhausted: Cannot allocate memory

With the first iterations of Raspberry Pi the Model A comes with 256mb of memory. While the Raspberry Pi B comes with a modest 512mb of memory. For most applications this amount of memory is actually quiet a bit. As soon as you start compiling your own binaries this amount starts to seem dismal.

*Insert reason why swap on flash-based memory is bad here.

Limitations

The Raspbian distribution comes with a 100mb swapfile. This is actually a bit on the small side. A general rule of thumb is swapfile size should be about twice as much as the available RAM on the machine. In the examples below I have a Raspberry Pi B+. So the amount of swap I use is 1024mb.

Commands

We will change the configuration in the file */etc/dphys-swapfile *:

sudo nano /etc/dphys-swapfile

The default value in Raspbian is:

CONF_SWAPSIZE=100

We will need to change this to:

CONF_SWAPSIZE=1024

Then you will need to stop and start the service that manages the swapfile own Rasbian:

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

You can then verify the amount of memory + swap by issuing the following command:

free -m

The output should look like:

total     used     free   shared  buffers   cached
Mem:           435       56      379        0        3       16
-/+ buffers/cache:       35      399
Swap:         1023        0     1023

Finished!

That should be enough swap to complete any future compiles I may do in the future.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值