java swap_java环境内存不够导致swap

java环境内存不够导致swap

云服务器默认不支持创建swap,所以部分场景下需要 创建一个文件让文件成为swap。

#1.创建一个文件块

[root@oldboyedu01-nb ~]# dd if=/dev/zero of=/tmp/100m bs=1M count=100

100+0 records in

100+0 records out

104857600 bytes (105 MB) copied, 0.935927 s, 112 MB/s

[root@oldboyedu01-nb ~]# file /tmp/100m

/tmp/100m: data

#2.变成swap

[root@oldboyedu01-nb ~]# mkswap /tmp/100m

mkswap: /tmp/100m: warning: don't erase bootbits sectors

on whole disk. Use -f to force.

Setting up swapspace version 1, size = 102396 KiB

no label, UUID=1b2aea27-a092-4345-806f-b95b8d33873a

[root@oldboyedu01-nb ~]# file /tmp/100m

/tmp/100m: Linux/i386 swap file (new style) 1 (4K pages) size 25599 pages

#3.swap生效

[root@oldboyedu01-nb ~]# swapon /tmp/100m

[root@oldboyedu01-nb ~]# free -h

total used free shared buffers cached

Mem: 3.9G 398M 3.5G 248K 65M 134M

-/+ buffers/cache: 198M 3.7G

Swap: 867M 0B 867M

[root@oldboyedu01-nb ~]# swapon -s

Filename Type Size Used Priority

/dev/sda2 partition 786428 0 -1

/tmp/100m file 102396 0 -2

#4.swap永久生效

###方法1. /etc/rc.local

swapon /tmp/100m

###方法2. /etc/fstab

/tmp/100m swap swap defaults 0 0

[root@oldboyedu01-nb ~]# free -h

total used free shared buffers cached

Mem: 3.9G 398M 3.5G 248K 65M 134M

-/+ buffers/cache: 199M 3.7G

Swap: 867M 0B 867M

Linux的特点:会把使用过的命令和数据临时存放在内存中 cache和buffer,所以上面真实可用空间为3.7G。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值