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. java 懒汉式--初步解决安全问题

    2016-07-28 00:10:14 懒汉式: class text { public String k;       private static text t=null;//右边代码结构比上边饿 ...

  2. 完全用 GNU/Linux 工作(转)

    转自:http://www.chinaunix.net/old_jh/4/16102.html 看到一半,实在太长,但已觉得很好,转来分享一下. 完全用 GNU/Linux 工作 - 摈弃 Windo ...

  3. 纯js制作遮罩层对话框 -- g皓皓

    //本文支持js在线工具测试.转载请注明出处. <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> < ...

  4. 感性体验 Android 5.0 Lollipop

    引言 Android5.0大概是在11月下旬开始进行OTA推送,博主手上的这台五太子(Nexus 5)也在前几天收到了Google的推送,博主当然是按耐不住赶紧FQ升级啦,但无奈的是这个大版本更新包有 ...

  5. MVC中的区域

    authour: chenboyi updatetime: 2015-05-03 08:26:30 friendly link:   目录: 1,思维导图 2,AreaRegistration类的Re ...

  6. uva10561 - Treblecross

    Treblecross is a two player game where the goal is to get three `X' in a row on a one-dimensional bo ...

  7. laravel框架——composer导入laravel

    第一种: composer create-project --prefer-dist laravel/laravel 名称 "5.2.*"第二种: composer global ...

  8. java 双重检查模式

    java 双重检查模式 在并发环境下 兼顾安全和效率 成例(Idiom)是一种代码层次上的模式,是在比设计模式的层次更具体的层次上的代码技巧.成例往往与编程语言密切相关.双重检查成例(Double C ...

  9. Solr4.8.0源码分析(8)之Lucene的索引文件(1)

    Solr4.8.0源码分析(8)之Lucene的索引文件(1) 题记:最近有幸看到觉先大神的Lucene的博客,感觉自己之前学习的以及工作的太为肤浅,所以决定先跟随觉先大神的博客学习下Lucene的原 ...

  10. 【Java】环境变量的配置

    注意点 1.环境变量不能有空格,比如C:\Program Files 2.JAVA_HOME:D:\Java\jdk1.7.0_67------------->注意不能加;分号