Linux Swap故障之 swapoff failed: Cannot allocate memory
目录
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的更多相关文章
- 关于阿里云ESC上go语言项目编译6l: running gcc failed: Cannot allocate memory
(1)前段时间将自己的阿里云服务器上的系统由centos 6.5换为了ubuntu 14,其他的硬件配置都没有发生改变,将服务器上的数据恢复并且重新安装了golang的编译环境后,发现使用go bui ...
- mprotect() failed: Cannot allocate memory
遇到这个问题是在測试项目的性能时发现的,每一个对象分配一页大小的空间然后mprotect() 保护起来,当系统分配3W多个页的时候会出现这个问题. google到在一份邮件列表中也曾提到该问题.htt ...
- 解决Failed to allocate memory: 8转
解决Failed to allocate memory: 8 昨天换了x64的Win7,发现在Eclipse上启动模拟器的时候存在问题,当设置的模拟器分辨率大于400×800的时候会出现 Failed ...
- Android 启动模拟器是出现“Failed to allocate memory: 8”错误提示的原因及解决办法
某天,Android 启动模拟器是出现“Failed to allocate memory: 8”错误,模拟器无法启动,如下图: 原因:设置了不正确AVD显示屏模式,4.0版默认的模式为WVGA800 ...
- Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 (转)
Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8http://www.crifan.com/android_emulator_ ...
- Failed to allocate memory: 8
Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...
- 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8
[问题] 折腾: [已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 过程中,增大对应AVD的内存为2G后,结果无法启 ...
- fork failed.: Cannot allocate memory
在做压力测试时候: [root@666 ok]# webbench -c 5000 -t30 http://10.100.0.61/ Webbench - Simple Web Benchmark 1 ...
- 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory
[已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 结论是: 当前有个bug: 默认是通过 hw.ramSize=1024 ...
随机推荐
- 箭头函数的this指向
es6的箭头函数中this指向是跟普通function中的this指向不同的,普通function的this指向取决于调用function的对象, 而箭头函数的this指向取决于声明它的对象,看下面这 ...
- spring学习-ApplicationContext-spring上下文深入理解
4月份开始复习一遍spring相关知识.让自己巩固一下spring大法的深奥益处,所以就看了大佬的博客,转载留下来日后继续研读.认为重点的标记为红色 以下文章内容转载自:http://www.cnbl ...
- 某邀请赛misc key家用完整版
目录 题目下载 提示 解题过程 1.提取RGB值 2.找到key 3.循环异或,得到flag 反思 题目下载 题目名:key 提示 提取钥匙中特殊颜色的RGB循环异或KEY值 解题过程 1.提取RGB ...
- python安装 hanlp +使用 坑坑坑。。。填填填。。。
刚开始用都不知道要怎么安装,包括什么文件.百度了下发现正常安装就可以用,不用下多余的东西,但是但是但是但是但是但是但是但是 用pycharm安装不行,pip安装不行,也是见鬼了. 解决方法: 1.手动 ...
- GTD时间管理
GTD就是Getting Things Done的缩写,翻译过来就是"把事情处理完",是一个管理时间的方法.GTD的核心理念概括就是必须记录下来要做的事,然后整理安排并使自己一一去 ...
- Element 表单验证,不清空数据,仅仅取消表单字段校验
重置表单 this.$refs['ageForm'].resetFields() // 表单重置 仅清空校验 this.$refs['ageForm'].clearValidate() // 清除验证
- maven中pom的继承以及dependencies与dependencyManagement的区别
https://blog.csdn.net/zzm3280/article/details/84952623 分类专栏: maven 本文转自:https://blog.csdn.net/liut ...
- EF之DataBase添加新表
由于需要新增的XML数据较多,可以另起项目,将新增的XML数据复制到原来的EF
- C# 填充客户端提交的值到T对象
/// <summary> /// 填充客户端提交的值到 T 对象 如appinfo = AppConvert.To<Appinfo>(context.Reques ...
- 2019 创蓝253java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.创蓝253等公司offer,岗位是Java后端开发,因为发展原因最终选择去了创蓝253,入职一年时间了,也成为 ...