[转载]How To Add Swap on Ubuntu 12.04
How To Add Swap on Ubuntu 12.04
Aug 17, 2012 Linux Basics Ubuntu
About Linux Swapping
Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a “linux swap” can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a system to harness more memory than was originally physically available.
However, swapping does have disadvantages. Because hard disks have a much slower memory than RAM, virtual private server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.
Check for Swap Space
Before we proceed to set up a swap file, we need to check if any swap files have been enabled on the VPS by looking at the summary of swap usage.
sudo swapon -s
An empty list will confirm that you have no swap files enabled:
Filename Type Size Used Priority
Check the File System
After we know that we do not have a swap file enabled on the virtual server, we can check how much space we have on the server with the df
command. The swap file will take 256MB— since we are only using up about 8% of the /dev/sda, we can proceed.
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda 20907056 1437188 18421292 8% /
udev 121588 4 121584 1% /dev
tmpfs 49752 208 49544 1% /run
none 5120 0 5120 0% /run/lock
none 124372 0 124372 0% /run/shm
Create and Enable the Swap File
Now it’s time to create the swap file itself using the dd command :
sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
“of=/swapfile” designates the file’s name. In this case the name is swapfile.
Subsequently we are going to prepare the swap file by creating a linux swap area:
sudo mkswap /swapfile
The results display:
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb
Finish up by activating the swap file:
sudo swapon /swapfile
You will then be able to see the new swap file when you view the swap summary.
swapon -s
Filename Type Size Used Priority
/swapfile file 262140 0 -1
This file will last on the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.
Open up the file:
sudo nano /etc/fstab
Paste in the following line:
/swapfile none swap sw 0 0
Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.
You can do this with the following commands:
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
[转载]How To Add Swap on Ubuntu 12.04的更多相关文章
- How To Add Swap on Ubuntu 14.04
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 How To Add Swap on ...
- [转]Ubuntu 12.04 安装屏保
From:http://www.howtogeek.com/114027/how-to-add-screensavers-to-ubuntu-12.04/ How to Add Screensaver ...
- Get back Typing Break in Ubuntu 12.04 & 11.10(转载)
转自:http://ubuntuguide.net/get-back-typing-break-in-ubuntu-12-04-11-10 Since Ubuntu 11.10 Oneiric, th ...
- Ubuntu 12.04的gnome classic panel添加程序快捷键(转载)
How to add applets to the Gnome classic panel in Ubuntu 12.04 转自:http://www.borfast.com/blog/how-add ...
- 【NS2】Ubuntu 12.04 LTS 中文输入法的安装(转载)
本文是笔者使用 Ubuntu 操作系统写的第一篇文章!参考了红黑联盟的这篇文章:Ubuntu 12.04中文输入法的安装 安装 Ubuntu 12.04 着实费力一番功夫,老是在用 Ubuntu 来引 ...
- [转载] Ubuntu 12.04下安装git,SSH及出现的Permission denied解决办法
如何安装ssh http://os.51cto.com/art/201109/291634.htm 仅需要阅读至成功开启ssh服务即可 http://www.linuxidc.com/Linux/20 ...
- ubuntu 12.04 alt+tab无法切换窗口的问题(转载)
转自:http://www.2cto.com/os/201209/153282.html ubuntu 12.04 alt+tab无法切换窗口的问题 安装cpmpiz配置管理程序. sudo ...
- Ubuntu 12.04 设置终端字体为文泉驿(转载)
转自:http://my.oschina.net/uniquejava/blog/98480 0.说明 在gnome-terminal终端中看习惯了文泉驿微米黑字体,没想到从11.10升级到 ...
- Ubuntu 12.04 root默认密码? 如何使用root登录? (转载)
转自:http://www.lupaworld.com/article-219280-1.html 在安装Ubuntu 12.04时并没有设置root的密码,登录的时候也没有使用root账户.当我们使 ...
随机推荐
- Android的图片缓存ImageCache(转)
为什么要做缓存? 在UI界面加载一张图片时很简单,然而如果需要加载多张较大的图像,事情就会变得更加复杂.在许多情况下(如ListView.GridView或ViewPager等的组件),屏 ...
- visio如何让动态连接线的单箭头变成双箭头?
1 选中线,右击,然后选择“格式”,“线条” 2 3
- Lucene.net 全文检索 盘古分词
lucene.net + 盘古分词 引用: 1.Lucene.Net.dll 2.PanGu.Lucene.Analyzer.dll 3.PanGu.HighLight.dll 4.PanGu.dll ...
- loj 1167(二分+最大流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26881 思路:我们可以二分最大危险度,然后建图,由于每个休息点只能 ...
- MySQL级联删除的问题
一.FOREIGN KEY 的定义分为两种:列级约束和表级约束 .列及约束的话,可以在列定义的同时,定义外键约束.比如 如果有2张表,主表:T1(A1 )) 要在从表T2中定义外键列这可以: Crea ...
- IM即时通讯实现原理
即时通讯(Instant Messenger,简称IM)软件多是基于TCP/IP和UDP进行通讯的,TCP/IP和UDP都是建立在更低层的IP协议上的两种通讯传输协议.前 者是以数据流的形式,将传 ...
- Base64编码保存到文件服务器
byte[] buffer = Convert.FromBase64String(param.Base64Code); System.Net.WebClient webClient = new Sys ...
- Callable接口、Runable接口、Future接口
1. Callable与Runable区别 Java从发布的第一个版本开始就可以很方便地编写多线程的应用程序,并在设计中引入异步处理.Thread类.Runnable接口和Java内存管理模型使得多线 ...
- BootSrap学习
1.当row1里边有2个或多个col的时候,如果位置在后边的col的高度大于位置在前边的col,就可能会导致下一个row2在满足col-xs-*在满足和为12的情况下错乱分行.解决办法是强行给row1 ...
- 我的c++学习(2)比较两个数字大小
#include "stdafx.h" #include<iostream> using namespace std; int max(int i, int j){ / ...