0
点赞
收藏
分享

微信扫一扫

添加虚拟内存,不添加硬盘的方式

在linux中,当物理内存mem不足时,就会使用虚拟内存(swap分区)

例如增加2G虚拟内存,操作如下:

1.查看内存大小

[root@localhost
~]# free -m

[ root@localhost 
f ree 
1 
-m 
Mem: 
Swap : 
total 
972 
2047 
used 
579 
21 
f ree 
85 
2026 
shared 
21 
buff/cache 
307 
available 
175 
[root@localhost


2.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)

[root@localhost
~]# dd if=/dev/zero of=h bs=1M count=1024


3.目录空间大小

[root@localhost
~]# du -sh h


4.格式化为交换分区文件

[root@localhost
~]# mkswap h   #建立swap的文件系统


5.启用交换分区文件:

[root@localhost
~]# swapon h  #启用swap文件


6.查看下扩充后的内存

[root@localhost
~]# free -m  #查看swap添加了1G内存


[ root@localhost 
free -m 
Mem: 
Swap : 
total 
972 
3071 
used 
570 
20 
f ree 
73 
3051 
shared 
21 
buff/cache 
328 
available 
181 
[root@tocathost





7.使系统开机时自启用,在文件/etc/fstab中添加一行:


/root/swapfile
swap swap defaults 0 0


8.关闭某个分区

[root@localhost ~]# swapoff h

[ root@localhost 
free -m 
Mem: 
Swap : 
total 
972 
2047 
used 
570 
20 
free 
74 
2027 
sha red 
21 
buff/cache 
328 
available 
182 
[root@localhost



举报

相关推荐

0 条评论