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 ...
随机推荐
- wkhtmltopdf cpdf HTML转pdf 及pdf合并
将 html 转为 pdf :wkhtmltopdf wkhtmltopdf 是一个使用 webkit 网页渲染引擎开发的用来将 html 转成 pdf 的工具,可以跟多种脚本语言进行集成来转换文档. ...
- 团队作业第五次—项目冲刺-Day1
Day1 项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 hunter--冲刺集合 团队名称 hunter小组 作业目标 最终做出 ...
- Spring Security教程之整合SpringMVC(六)
一.前言 Spring Security系列教程中,前五篇为同一人所写,而本文是博主依据第三方文章整合而出,与前五篇文章的作者不是同一系列. 但本文以前五篇文章为基础,在前面文章所建立的Spring ...
- Gamma阶段第十次scrum meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91(持续完成) # ...
- Gamma阶段第七次scrum meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91(持续完成) # ...
- 一文让你彻底理解准确率,精准率,召回率,真正率,假正率,ROC/AUC
参考资料:https://zhuanlan.zhihu.com/p/46714763 ROC/AUC作为机器学习的评估指标非常重要,也是面试中经常出现的问题(80%都会问到).其实,理解它并不是非常难 ...
- 单词uranolite陨石uranolite英语
陨石(uranolite)是指来自地球以外太阳系其他天体的碎片,绝大多数来自位于火星和木星之间的小行星,少数来自月球(40块)和火星(40块).全世界已收集到4万多块陨石样品,石陨石主要成分是硅酸盐. ...
- [更新] Jetbrains IntelliJ IDEA 2019 的许可证密钥
亲测有效.转载目的:提供一种方法,当然可以看一下原网站的更新及其他方法.转载:[更新] Jetbrains IntelliJ IDEA 2019 的许可证密钥(100%工作),By Gideon ...
- MySQL之简介以及数据类型(一)
一:关系型数据库 所谓的关系型数据库RDBMS,是建立在关系模型基础上的数据库,借助于集合代数等数学概念和方法来处理数据库中的数据. 二:关系型数据库的主要产品: oracle:在以前的大型项目中使用 ...
- drf--ModelSerializers序列化
目录 drf--ModelSerializers序列化 项目准备 配置 settings.py 路由 多表设计 表关系分析 创建models 模型序列化 自定义模型序列化 api/serializer ...