Adding Swap Files

If you do not have free disk space to create a swap partition and you do need to add swap space urgently, you can use a swap file as well. From a performance perspective, it does not even make that much difference if a swap file is used instead of a swap device such as a partition or a logical volume, and it may help you fixing an urgent need in a timely manner.  (如果没有多余的磁盘空间来增加交换分区,可使用交换文件代替。从性能方面来看,swap file跟swap device没多少区别)

To add a swap file, you need to create the file first. The  dd if=/dev/zero of=/ swapfile bs=1M count=100  command would add 100 blocks with a size of 1 Mebibyte from the /dev/zero device (which generates 0s) to the /swapfile file. The result is a 100 MiB file that can be configured as swap. To do so, you can follow the same procedure as for swap partitions. First use  mkswap /swapfile  to mark the file as a swap file, after which you can use  swapon /swapfile  to active it.

例如:把原来的swap空间大小从2147MB添加到2247MB

[root@rhel7 ~]# free -m
total used free shared buff/cache available
Mem:
Swap:
[root@rhel7 /]# touch swapfileTest
[root@rhel7 /]# dd if=/dev/sda of=/swapfileTest bs=1M count=
+ records in
+ records out
bytes ( MB) copied, 1.45588 s, 72.0 MB/s
[root@rhel7 /]# mkswap /swapfileTest
mkswap: /swapfileTest: warning: don't erase bootbits sectors
(dos partition table detected). Use -f to force.
Setting up swapspace version , size = KiB
no label, UUID=c011c102-304a-4cb2--2c69500a82a8
[root@rhel7 /]# swapon /swapfileTest
swapon: /swapfileTest: insecure permissions , suggested. -----有提示,需要设置权限#chmod 0600 /swapfileTest
[root@rhel7 /]# free -m --比原来的2147添加的100MB
total used free shared buff/cache available
Mem:
Swap:
[root@rhel7 /]#

将配置写入到etc/fstab文件中,否则重启系统后不生效:

# vi  /etc/fstab,增加如下行

/swapfileTest             swap          swap    defaults        0 0

Adding Swap Files的更多相关文章

  1. Adding basic files · lcobucci/jwt@aad22ed · GitHub

    Skip to content   Features Business Explore Marketplace Pricing   This repository Sign in or Sign up ...

  2. What are Unix swap (.swp) files?

    原文: http://www.networkworld.com/article/2931534/it-management/what-are-unix-swap-swp-files.html ---- ...

  3. 如何在Linux上使用文件作为内存交换区(Swap Area)

    交换区域(Swap Area)有什么作用? 交换分区是操作系统在内存不足(或内存较低)时的一种补充.通俗的说,如果说内存是汽油,内存条就相当于油箱,交换区域则相当于备用油箱. Ubuntu Linux ...

  4. [转载]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 i ...

  5. 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 ...

  6. How To Add Swap Space on Ubuntu 16.04

    Introduction One of the easiest way of increasing the responsiveness of your server and guarding aga ...

  7. How to Add Swap on CentOS

    About Linux Swapping Linux RAM is composed of chunks of memory called pages. To free up pages of RAM ...

  8. Linux Swap交换分区介绍总结

    Swap交换分区概念   什么是Linux swap space呢?我们先来看看下面两段关于Linux swap space的英文介绍资料: Linux divides its physical RA ...

  9. mm/swap

    /* *  linux/mm/swap.c * *  Copyright (C) 1991, 1992  Linus Torvalds */ /* * This file should contain ...

随机推荐

  1. 探讨CMake中关于RPATH的使用

    最近研究CMake,发现CMake对于RPATH的管理也非常人性化.官方说法是当动态库的编译也和执行档在同级目录下的时候,CMake会自动给执行档加入适当的RPATH.具体可以通过readelf -d ...

  2. js 判断url的?后参数是否包含某个字符串

    function GetQueryString(name){    var reg=eval("/"+name+"/g");   var r = window. ...

  3. .NET,你真的 知道了吗

    搞清自己是干什么的 有人问你是做什么的,回答是:"我是做,NET开发的",有的人也会问:"那.NER.是什么?"刚开始我认为是一个开打工具,后认为是一个平台,一 ...

  4. MapReduce概念(转)

    昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解MapReduce的概念(根据他们的反馈).我成功地向技术听众们(主要是Java程序员,一些Fl ...

  5. location对象位置操作,进行跳转

    location位置操作,进行跳转 location.assign("http://www.baidu.com") 跳转,打开新的url 等价于,将location.href或wi ...

  6. c语言Winpcap编程构造并接收解析arp包

    /* 程序功能: 1.构造arp包,并发送.程序参数顺序:源IP.目的IP.mac地址.flag 2.获取网络中的ARP数据包,解析数据包的内容.程序参数:日志文件名 winpacp中文技术文档(基本 ...

  7. C# Attribute

    Attribute 是C#非常重要的一块内容,需要研究一下. Attribute  的简单使用:简而言之,就是可以自定义通用标志位,而不是在每个所需的类型中分别增加标志位. //class专用attr ...

  8. nil、Nil、NULL与NSNull的区别--备用

    我们来分别介绍一下这四种类型: 一.nil 我们给对象赋值时一般会使用object = nil,表示我想把这个对象释放掉: 或者对象由于某种原因,经过多次release,于是对象引用计数器为0了,系统 ...

  9. java的类加载机制

    1.概述 Class文件由类装载器装载后,在JVM中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息:如构造函数,属性和方法等,Java允许用户借由这个Class ...

  10. Java中堆内存(heap)和栈内存(stack)的区别

    在Java代码中,常常会使用到这样的类的声明实例化: Person per = new Person(); //这其实是包含了两个步骤,声明和实例化 Person per = null; //声明一个 ...