Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1678726
  • 博文数量: 391
  • 博客积分: 8464
  • 博客等级: 中将
  • 技术积分: 4589
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-13 15:12
个人简介

狮子的雄心,骆驼的耐力,孩子的执著!

文章分类

全部博文(391)

文章存档

2023年(4)

2018年(9)

2017年(13)

2016年(18)

2014年(7)

2013年(29)

2012年(61)

2011年(49)

2010年(84)

2009年(95)

2008年(22)

分类: LINUX

2011-07-16 00:22:59

a) Login as the root user

b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=2048 count=524288

You can turn it into:
# dd if=/dev/zero of=/swapfile1 bs=1M count=2048

This means that the block size is 1 MB, so count=512 means “I need 512 megs”, there is no need to do any other calculations.

c) Set up a Linux swap area:
# mkswap /swapfile1

d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1

e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab

Append following line:
/swapfile1 swap swap defaults 0 0

So next time Linux comes up after reboot, it enables the new swap file for you automatically.

g) How do I verify swap is activated or not?
Simply use free command:
$ free -m

设置实际内存和swap的使用比率


1、输入代码:

sysctl -q vm.swappiness

输出:

vm.swappiness = 60

2、更改swappiness值为10:

sysctl vm.swappiness=10

输出:

vm.swappiness = 10
OR
echo 10 > /proc/sys/vm/swappiness

3、为了永久生效,更改/etc/sysctl.conf文件:

vi /etc/sysctl.conf

在最末端添加:

vm.swappiness=10

保存,并重启机器。
这样你就将值由60改为10,这可以大大降低系统对于swap的写入,建议内存为512m或更多的朋友采用此方法。如你你发现你对于swap的使用极少,可以将值设为0。这并不会禁止你对swap的使用,而是使你的系统对于swap的写入尽可能的少,同时尽可能多的使用你的实际内存。这对于你在切换应用程序时有着巨大的作用,因为这样的话它们是在物理内存而非swap分区中。

小贴士: 1G内存推荐值为5 , 2G内存推荐值为3 ,不推荐把值设为0

/etc/sysctl.conf

  1. kernel.shmall = 4294967296
  2. net.netfilter.nf_conntrack_max = 1000000
  3. kernel.unknown_nmi_panic = 0
  4. kernel.sysrq = 1
  5. fs.file-max = 1000000
  6. vm.swappiness = 10
  7. fs.inotify.max_user_watches = 10000000
  8. net.core.wmem_max = 327679
  9. net.core.rmem_max = 327679
  10. net.ipv4.conf.all.send_redirects = 0
  11. net.ipv4.conf.default.send_redirects = 0
  12. net.ipv4.conf.all.secure_redirects = 0
  13. net.ipv4.conf.default.secure_redirects = 0
  14. net.ipv4.conf.all.accept_redirects = 0
  15. net.ipv4.conf.default.accept_redirects = 0
  16. fs.notify.max_queued_events = 3276792
  17. net.ipv4.neigh.default.gc_thresh1 = 2048
  18. net.ipv4.neigh.default.gc_thresh2 = 4096
  19. net.ipv4.neigh.default.gc_thresh3 = 8192
  20. net.ipv6.conf.all.disable_ipv6 = 1

From:

阅读(925) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~