对于某些大型应用来说,SWAP 严重影响性能,尽可能避免使用:

The Linux kernel provides a tweakable setting that controls how often the swap file is used, called swappiness

A swappiness setting of zero means that the disk will be avoided unless absolutely necessary (you run out of memory), while a swappiness setting of 100 means that programs will be swapped to disk almost instantly.

Ubuntu system comes with a default of 60, meaning that the swap file will be used fairly often if the memory usage is around half of my RAM. You can check your own system's swappiness value by running:

one@onezero:~$ cat /proc/sys/vm/swappiness
60

As I have 4 GB of RAM, so I'd like to turn that down to 10 or 15. The swap file will then only be used when my RAM usage is around 80 or 90 percent. To change the system swappiness value, open /etc/sysctl.conf as root. Then, change or add this line to the file:

vm.swappiness = 10

Reboot for the change to take effect

You can also change the value while your system is still running

sysctl vm.swappiness=10

you can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.

To calculate your swap Formula

free -m (total) / 100 = A

A * 10

root@onezero:/home/one# free -m
total used free shared buffers cached
Mem: 3950 2262 1687 0 407 952
-/+ buffers/cache: 903 3047
Swap: 1953 0 1953

so total is 3950 / 100 = 39.5 * 10 = 395

so what it mean is that when 10 % 395 MB of ram left then it start using swapiness

https://en.wikipedia.org/wiki/Swappiness

http://stackoverflow.com/questions/10853074/swappiness-in-jvm

Linux 控制 配置 减少 交换分区 SWAP 虚拟内存使用的更多相关文章

  1. Linux 交换分区swap

    Linux 交换分区swap 一.创建和启用swap交换区 如果你的服务器的总是报告内存不足,并且时常因为内存不足而引发服务被强制kill的话,在不增加物理内存的情况下,启用swap交换区作为虚拟内存 ...

  2. Linux_交换分区SWAP

    一.交换分区SWAP 1️⃣:交换分区SWAP就是LINUX下的虚拟内存分区,它的作用是在物理内存使用完之后,将磁盘空间(也就是SWAP分区)虚拟成内存来使用. 2️⃣:交换分区一般指定虚拟内存的大小 ...

  3. Linux交换分区swap

    一.SWAP 说明 1.1 SWAP 概述 当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被 ...

  4. linux两种增加交换分区(swap)的方法

    在安装Oracle后,为使Oracle流畅运行,需要手动增加linux的交换分区(相当于Windows下的虚拟内存)的大小,本文介绍两种增加交换分区(swap)的方法. 第一种方法:新建分区 1.fd ...

  5. linux(centos8): 临时关闭/永久关闭交换分区swap?

    一,为什么要关闭swap? 1,swap的用途? swap 分区就是交换分区,(windows平台叫虚拟内存) 在物理内存不够用时, 操作系统会从物理内存中把部分暂时不被使用的数据转移到交换分区, 从 ...

  6. 小白自制Linux开发板 五. Debian文件系统制作,以及WIFI配置、交换分区配置

    该片文章将完整记录一个Debian的最小文件系统的生成,以及自定义配置WIFI组件.网络组件和交换分区配置 本文章参考:https://whycan.com/t_4236.htmlhttp://www ...

  7. Linux设置交换分区swap

    参考: http://www.vpser.net/opt/vps-add-swap.html https://www.zntec.cn/archives/vps-swap.html http://yz ...

  8. linux 交换分区 swap

    linux swap分区用来保证内存过载时也可以使用,是在磁盘级别对内存的一次扩展,swap分区必须是一个单独的分区 创建过程: 1.用fdisk 命令新建分区,在创建过程中通过L命令和t命令来调整分 ...

  9. Linux - 创建交换分区 swap

    购买的 1GB 内存的 Linux 小机器,在编译安装 PHP 的时候内存捉急,只好开启 swap 交换分区来增大内存. [root@VM_139_38_centos php-7.2.12]# cat ...

随机推荐

  1. <构建之法> 第四章 结对 读后感

    粗读 第四章主要讲的是关于结对合作的事项.大多数的软件开发都是团体性的,而合作的最小单位也就是两个人,这也是软件开发中的最佳实践.而结对中,我们能够更好的编写我们的代码,能够少一些担心,对自己的代码也 ...

  2. c#中关键词out和ref的区别

    c#中关键词out和ref用来表明以传引用的方式传递参数. 区别如下: 如果方法的参数用out标记,表示方法被调用前不需初始化参数,方法内不能读取此参数的值,在方法返回前必须向此参数写入值: 如果方法 ...

  3. leetcode105:Construct Binary Tree from Preorder and Inorder Traversal

    题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume t ...

  4. 解决Eclipse启动Tomcat时报Error loading WebappClassLoader错误

    最近新建了一个JSF项目(网上查到用Struts,Spring MVC也会如此),配置好以后用Eclipse启动Tomcat报了如下错误:严重: Error loading WebappClassLo ...

  5. Openstack命令行创建不同vlan段虚拟机

    默认使用nova-network的vlan模式,但是在使用默认的dashboard的时候,不能指定创建的虚拟机的使用网段,固定IP地址. 实际上该功能是在存在的,只是openstack的dashbbo ...

  6. Android中AIDL通信机制分析

    一.背景 ·1.AIDL出现的原因 在android系统中,每一个程序都是运行在自己的进程中,进程之间无法进行通讯,为了在Android平台,一个进程通常不能访问另一个进程的内存空间,所以要想对话,需 ...

  7. Android实现归属地查询功能

    实现归属地查询大体有两种方法可以实现,一种是通过归属地API进行查询,另一种是查询本地数据库.两种方法各有优劣,最好结合起来使用,我本次采用的是查询数据库的方法.首先需要从网上下载归属地数据库call ...

  8. miniUI datagrid 获取序号

    获取每一个row以后,其中的row._index字段和页面上显示的序号虽然看起来一样, 但是实际上不是同一个东西,如果用客户端排序模式,排序后,row._index和页面显示的序号就对不上了. 正确的 ...

  9. java并发编程参考资料

    1.java编程思想 2.java并发编程实战 3.java并发编程的艺术 4.http://www.infoq.com/cn/author/%E7%A8%8B%E6%99%93%E6%98%8E#文 ...

  10. UseFul Collection

    ....... 啦啦啦,test... http://bbs.csdn.net/topics/380175613 http://zhidao.baidu.com/question/580940892. ...