目录
swap分区关闭
方法1:释放内存缓存
方法2:允许内存overcommit

swap分区关闭
准备调整Linux下的swap分区的使用率。
在Linux下执行 swapoff -a -v报如下错误:
swapoff: /dev/mapper/cryptswap1: swapoff failed: Cannot allocate memory

上述错误原因分析:
  从上述的信息可以看出,当前Linux系统把/dev/mapper/cryptswap1这个设备当做了交换分区,如果当前改交换分区使用的容量大于系统当前剩余的内存,就会报这个错误,因为在关闭交换分区的时候,需要把分区的数据全部写入到内存,如果内存容量不足,就会导致这个错误。

解决:
方法1:释放内存缓存
# sync ; echo 3 > /proc/sys/vm/drop_caches #先把内存数据回写到磁盘,然后释放内存缓存
drop_caches接受的参数是1、2、3,分别清空pagecache、slab对象、pagecahce和slab对象

从 https://github.com/torvalds/linux/blob/master/Documentation/sysctl/vm.txt 可以找到对该文件参数的解释:
drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches

dirty状态的内存缓存不会被释放,如果要释放尽可能多的内存缓存,先执行命令sync,减少dirty状态的内存缓存。如果要disable,输入参数4,注意0不被接受:
上述方法可能不会成功,当你的swap分区使用太多的时候。

方法2:允许内存overcommit
overcommit_memory用来控制“用户空间申请内存时,是否进行内存容量判断(overcommit判断)以及是否批准:

When this flag is 0, the kernel attempts to estimate the amount
of free memory left when userspace requests more memory.

When this flag is 1, the kernel pretends there is always enough
memory until it actually runs out.

When this flag is 2, the kernel uses a "never overcommit"
policy that attempts to prevent any overcommit of memory.
Note that user_reserve_kbytes affects this policy.

设置的值为2表示不允许overcommit,这时候如果停掉swap,那么可用内存减少,用户空间的内存申请就可能触发overcommit被拒绝。

参考
https://www.lijiaocn.com/%E9%97%AE%E9%A2%98/2019/02/27/linux-swap-off-fail.html

Linux Swap故障之 swapoff failed: Cannot allocate memory的更多相关文章

  1. 关于阿里云ESC上go语言项目编译6l: running gcc failed: Cannot allocate memory

    (1)前段时间将自己的阿里云服务器上的系统由centos 6.5换为了ubuntu 14,其他的硬件配置都没有发生改变,将服务器上的数据恢复并且重新安装了golang的编译环境后,发现使用go bui ...

  2. mprotect() failed: Cannot allocate memory

    遇到这个问题是在測试项目的性能时发现的,每一个对象分配一页大小的空间然后mprotect() 保护起来,当系统分配3W多个页的时候会出现这个问题. google到在一份邮件列表中也曾提到该问题.htt ...

  3. 解决Failed to allocate memory: 8转

    解决Failed to allocate memory: 8 昨天换了x64的Win7,发现在Eclipse上启动模拟器的时候存在问题,当设置的模拟器分辨率大于400×800的时候会出现 Failed ...

  4. Android 启动模拟器是出现“Failed to allocate memory: 8”错误提示的原因及解决办法

    某天,Android 启动模拟器是出现“Failed to allocate memory: 8”错误,模拟器无法启动,如下图: 原因:设置了不正确AVD显示屏模式,4.0版默认的模式为WVGA800 ...

  5. Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 (转)

    Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8http://www.crifan.com/android_emulator_ ...

  6. Failed to allocate memory: 8

    Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...

  7. 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8

    [问题] 折腾: [已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 过程中,增大对应AVD的内存为2G后,结果无法启 ...

  8. fork failed.: Cannot allocate memory

    在做压力测试时候: [root@666 ok]# webbench -c 5000 -t30 http://10.100.0.61/ Webbench - Simple Web Benchmark 1 ...

  9. 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory

    [已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 结论是: 当前有个bug: 默认是通过 hw.ramSize=1024 ...

随机推荐

  1. C语言博客作业4——数组

    0.展示PTA总分 一维数组 二维数组 字符数组 1.本章学习总结 1.1学习内容总结 一维数组知识点: 无论是对一维数组还是二维数组进行应用时,我们对其下标的应用十分广泛. 1:一维数组的输入和遍历 ...

  2. rpm安装和卸载

    以jdk的卸载和安装为例. 1. 查找已安装的包名 $ rpm -q jdk jdk-1.7.0_79-fcs.x86_64 如果系统中有已经安装的jdk包,则会输出包名. 2. 卸载已安装的包 $ ...

  3. 日常运维--rsync同步工具

    rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而 ...

  4. QAbstractItemModel详细剖析 …&&... QAbstractTableModel

    从函数开始: QModelIndex QAbstractTableModel::sibling(int row, int column,  QModelIndex &idx) const;  ...

  5. DDD(Domain Driven Design) 架构设计

    一.为什么要分层 分层架构是所有架构的鼻祖,分层的作用就是隔离,不过,我们有时候有个误解,就是把层和程序集对应起来,就比如简单三层架构中,在你的解决方案中,一般会有三个程序集项目:XXUI.dll.X ...

  6. Guava---缓存之LRU算法

    随笔 - 169  文章 - 0  评论 - 292 GuavaCache学习笔记一:自定义LRU算法的缓存实现   前言 今天在看GuavaCache缓存相关的源码,这里想到先自己手动实现一个LRU ...

  7. Leetcode 5281. 使结果不超过阈值的最小除数

    又一次参赛,除了第一道Easy题和第二道Medium外,剩下的两道在有限时间内,要么没思路,要么思路不对,超时,要么有思路调试出错,还需多加练习! (这次的第三题,在循环从1开始,直到找到满足地为止, ...

  8. GitLab修改root用户密码

    GitLab是一个私有的Git仓库,具有较好的项目管理和用户管理能力.对于普通用户而言,通过系统的重置密码,接受邮件即可解决,可是GitLab的管理员账号,缺省的邮箱是一个不存在的邮箱地址,所以没有办 ...

  9. 接口性能指标TP90

    TP90,即,Top percentile 90, 前90%的意思. 这是一个常用于网站性能监控的指标.tp90是一个时间值,例如tp90=3ms,其含义是90%的请求,在3ms之内,可以得到响应. ...

  10. C# IE浏览器操作类

    using System; using System.Collections.Generic; using System.Drawing; using System.Runtime.InteropSe ...