IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

Linux 64位, MySQL, Swap & Memory 优化

Penner Blog 2009-10-21 22:10:31 累计浏览 5,670 次
本机暂存

    MySQL的性能优化文章有很多,这里介绍个通过优化Swap & Memory来提高性能的方法。

    The VM for Linux prefers system cache over application memory. What does this mean? The best way I can explain is by example.

    Imagine you have 32 GB of RAM

    MySQL is set to take 20 GB of RAM for a process based buffer and up to 6M for the various thread buffers.

    Over a period of time the box swaps. The only thing that is running is mysql and its memory size is around 21GB for resident memory. Why does swap grow when there is plenty of memory? The reason is when a memory alloc is needed (thread based buffer is tickled) the VM will choose to use swap over allocating from the system cache, when there is not enough free memory.

    DO NOT TURN OFF SWAP to prevent this. Your box will crawl, kswapd will chew up a lot of the processor, Linux needs swap enabled, lets just hope its not used.

    So how do you stop Nagios pages because of swap usage? Well if you have a few choices.

    reboot the box

    or

    stop mysql && swapoff -a;swapon -a;

    or just

    swapoff -a;swapon -a;

    (注意!如果你在MySQL正在使用Swap时执行,会把MySQL搞死,所以执行前一定要反复确认Swap没有被使用。)

    Doing the latter command is rather scary and fun at the same time. Because you can either crash mysql or not. I just did the swap* commands live, I was very certain nothing was using swap and it worked. YAY no more pages and I didn’t have to shut down the service!

    参考文章:

    http://mysqldba.blogspot.com/2008/05/linux-64-bit-mysql-swap-and-memory.html

相关日志

今天卸载Mysql时碰到的问题 (0) MySQL4.1/5.0中字符集_chinese_ci和_bin的区 (0) MySQL Proxy 编译安装 By CentOS (1)

同分类推荐文章

  1. 使用deepseek进行Oracle恢复,引起重大故障 (2026-06-22 10:56:00)
  2. 接手一个只差临门一脚的数据库恢复 (2026-06-18 00:13:09)
  3. 我做了一个 AI 版的 StarRocks 升级风险扫描工具,直接帮我定位到一个风险 (2026-06-15 01:00:00)

查看更多 数据库 文章 →

建议继续学习

  1. 用Hyer来进行网站的抓取 (累计阅读 158,251)
  2. MySQL数据库在实际应用一些方面的介绍 (累计阅读 36,399)
  3. WordPress插件开发 -- 在插件使用数据库存储数据 (累计阅读 29,164)
  4. Mysql监控指南 (累计阅读 21,351)
  5. 由浅入深探究mysql索引结构原理、性能分析与优化 (累计阅读 16,523)
  6. Linux如何统计进程的CPU利用率 (累计阅读 16,308)
  7. 我的 RHCA 之路 (累计阅读 14,013)
  8. Linux内存点滴 用户进程内存空间 (累计阅读 13,230)
  9. 给程序员新手的一些建议 (累计阅读 13,089)
  10. 在Apache2.2.XX下安装Mod-myvhost模块 (累计阅读 13,057)