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 ...
 
随机推荐
- eclipse中自动生成serialVersionUID
			
serialVersionUID作用: 序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性. 如果你修改代码重新部署后出现序列化错误,可以考虑给相应的类增加seri ...
 - 第02组 Alpha冲刺(1/6)
			
队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 如何进行团队代码的版本管理 如何使用微信云开发 如何使用管理微信开发团队 接下来的计划 沟通前后端成员,监督.提醒他们尽快 ...
 - Maven 基本概念——根目录、项目创建、坐标
			
1. MavenProjectRoot(项目根目录) |----src | |----main | | |----java ——存放项目的.java文件 ...
 - Java的策略和保护域
			
参考文章: (1)java之jvm学习笔记十(策略和保护域) https://blog.csdn.net/yfqnihao/article/details/8271415
 - svn在cleanup 时,提示privious operation has not finished,解决方案
			
在updated代码时,svn 提示 上一次操作失败,需要cleanup. 执行cleanup时,提示:cleanup失败,因为上一次操作失败,请先执行cleanup.很幽默的提示. svn的“.sv ...
 - Java 通过SFTP上传图片功能
			
1.需要在pom.xml文件中引用jsch的依赖: <dependency> <groupId>com.jcraft</groupId> <artifactI ...
 - Python【每日一问】30
			
问: [基础题]:一个足球队在寻找年龄在10岁到12岁的小女孩(包括10岁和12岁)加入.编写一个程序,询问用户的性别(m表示男性,f表示女性)和年龄,然后显示一条消息指出这个人是否可以加入球队,询问 ...
 - [原创]K8Cscan插件之Host2IP(批量域名解析/主机名转IP)
			
0x001 前言 在内网渗透中,有时候通过域或日志导出一些机器名,或者管理员备分文件等方式获取 只有主机名或者域名时,就需要先解析出IP获取相关IP或IP段,才好进行下一步扫描. 0x002 用法 首 ...
 - 手机上的unity路径
			
转载自:https://www.xuanyusong.com/archives/2656 Application.dataPath路径在PC上无论是Editor还是运行时毫无压力非常万能,但是在手机上 ...
 - intellij idea快速通过mapper跳转到xml文件
			
安装完之后重启idea即可!