MYSQL SWAP 内存 vm.swappiness

news2024/9/21 3:24:57

oracle database 没有这个说法

对于 vm.swappiness 内核参数使用 0 或 1 的值存在一些混淆。

关于 vm.swappiness 的困惑来自于这样一个事实:在较旧的 Red Hat 内核中,vm.swappiness 的值为 0 会导致最少量的交换以避免内存不足的情况。在较新的内核中(从 RHEL 内核 2.6.32-303 开始​​),值为 0 将完全禁用交换,但值为 1 将提供最少量的交换以避免内存不足的情况。

对于专用的 MySQL 服务器,建议将 vm.swappiness 的值设置为 1。在较旧的内核中,0 和 1 之间的实际差异并不大,但 1 是避免较新内核中出现 OOM 情况的安全设置(当然,假设有一些交换空间可用)。

要将 vm.swappiness 设置为 1 并使其在重启后保持不变:

---MySQL 服务器使用的内存被内核交换出去并不罕见,这并不一定意味着存在内存泄漏或 MySQL 服务器使用了过多的内存。内核有一个名为 vm.swappiness 的设置,它控制将主内存中的页面交换到磁盘而不是从页面缓存中移出页面的积极程度。默认设置为 60,在其他正常环境中可能会导致此行为。如果您担心并且不希望系统在正常运行期间使用交换,请将 vm.swappiness 值设置为 1。使用以下命令完成此操作:

Can swap be disabled on a MySQL server?

Solution

You can disable swap on most Linux systems, however it isn't recommended unless you have an abundance of free memory.

The normal tuning guidelines given about the InnoDB buffer pool and memory usage, take into account the system automatically swapping unused pages to disk. If you disable swap, the system will not page out unused pages and therefore you may require more RAM to cover the needs of the system. You can also run afoul of the OOM-Killer job in the kernel, more easily crashing your MySQL server when any memory pressure builds up (like during backups).
考虑到系统自动将未使用的页面交换到磁盘。如果禁用交换,系统将不会将未使用的页面换出,因此您可能需要更多 RAM 来满足系统的需求。

既然您知道了风险,我建议您不要禁用交换,而是调整交换系数。swapiness
You could very well end up killing MySQL nightly when system jobs run and backups run. Cannot give you any exact numbers of how much memory you will need, you need to observe each system independently and decide if they can run safely without swap indefinitely. Disabling swap can also impact your database performance because the Kernel must reduce the disk cache size to accommodate the needs of applications. If you have any MyISAM tables, these are directly affected by page cache. Binary logging is also affected by page cache, because the kernel caches binlog writes unless you have sync_binlog enabled.

Now that you know the risks, I recommend that you don't disable swap, but adjust the swappiness factor instead.

Here is an article discussing this parameter.

Applies to:

MySQL Server - Version 5.6 and later
Information in this document applies to any platform.

Goal

How can I determine if MySQL is growing due to a memory leak?
 

Solution

MySQL maintains many internal buffers that grow until they reach the configured maximum size. The largest of these buffers is typically the Innodb buffer pool. On a busy server with many tables this buffer can grow to the configured size quite quickly, however on servers where the dataset is small it is possible that the buffer pool never fully initializes. In this case it can appear that MySQL has a memory leak, but in fact the the buffer pool is growing continuously over a longer period of time, to meet the configured size. Only once all buffers have been fully allocated can you evaluate whether there is a memory leak. A memory leak will look like a non-cyclic pattern of memory usage over a longer period of time; cycles typically repeat from week to week as daily query loads form a pattern. If the memory usage only grows over a multi-week period, *and* your buffers are all fully allocated, then you may have a memory leak.

To monitor the actual usage of the mysqld process, you can use a command like this:

shell> ps -ovsz,rss -p $(pidof mysqld)

(This assumes there is only one mysqld process on the host.)

Another way to monitor for memory leaks in MySQL 5.7 is to have the Performance Schema memory instruments enabled (preferably in my.cnf), then monitor the total usage and individual usages like:

To get total current memory usage:

mysql> SELECT * FROM sys.memory_global_total;

To get individual contributions:

mysql> SELECT EVENT_NAME, COUNT_ALLOC, COUNT_FREE, sys.format_bytes(SUM_NUMBER_OF_BYTES_ALLOC) AS TotalAlloc,
sys.format_bytes(SUM_NUMBER_OF_BYTES_FREE) AS TotalFree, sys.format_bytes(CURRENT_NUMBER_OF_BYTES_USED) AS CurrentUsage,
sys.format_bytes(HIGH_NUMBER_OF_BYTES_USED) AS MaxUsed
FROM performance_schema.memory_summary_global_by_event_name
WHERE CURRENT_NUMBER_OF_BYTES_USED > 0
ORDER BY CURRENT_NUMBER_OF_BYTES_USED DESC;

MySQL Server - Version 5.6 and later
Linux x86
Linux x86-64

Goal

Should I use 0 or 1 for vm.swappiness?
 

Solution

These instructions are valid for Red Hat Enterprise Linux and Oracle Linux systems, but should be similar for other Linux distros.

There is some confusion about using a value of 0 or 1 for the vm.swappiness kernel parameter.

The confusion about vm.swappiness comes from the fact that in older Red Hat kernels, a value of 0 for vm.swappiness resulted in the minimal amount of swapping to avoid an out of memory condition. In newer kernels (as of RHEL kernel 2.6.32-303), a value of 0 will completely disable swap, but a value of 1 will provide the minimal amount of swapping to avoid an out of memory condition.

The recommendation is to set vm.swappiness to a value of 1 for a dedicated MySQL server.  There is not much practical difference between a value of 0 and a value of 1 on older kernels, but 1 is the safe setting to avoid an OOM condition on newer kernels (assuming that some swap space is available, of course).

To set vm.swappiness to 1 and make it persistent across reboots:

echo "vm.swappiness=1" >> /etc/sysctl.conf

sysctl -p

Note that for RHEL 8/OEL 8, this does not apply.  Refer instead to:  Doc ID 2992034.1  

RHEL 9 returns to the behavior documented here.

Purpose

This document talks about Linux swapping and it's nature briefly with references to database workloads.

Scope

This document is useful for Linux and database administrators for configuring, evaluating and monitoring systems.

Details

Linux OS is a virtual memory system like any other modern operating system. The Virtual Memory Management system of Linux includes:

  • Paging
  • Swapping
  • HugePages
  • Slab allocator
  • Shared memory

When almost all of the available physical memory (RAM) is started to be used in Linux, the kernel will start to swap out pages to the swap (disk space), or worse it may start swapping out entire processes. One another scenario is that it starts killing processes using the Out-of-Memory (OOM) Killer (See Document 452000.1)
 

Swap Usage on Linux

To check swap usage on Linux  use one of below:

  • free: Seek for low (or zero) values for Swap / used:

# free -m
             total       used       free     shared    buffers     cached
Mem:          4018       3144        873          0         66       2335
-/+ buffers/cache:        742       3276
Swap:         4690          0       4690

  • meminfo: Seek for SwapTotal = SwapFree

# grep Swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:       4803392 kB
SwapFree:        4803380 kB

  • top: Look for low (preferably zero) values of Swap / used:

# top

...
Mem:   4115320k total,  3219408k used,   895912k free,    68260k buffers
Swap:  4803392k total,       12k used,  4803380k free,  2390804k cached
...

  • vmstat: Look for si / so values to be zero:

# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0     12 871592  69308 2405188    0    0   103    36  275  500 14 13 71  1

Why is Swapping Bad

Especially on Linux  try to avoid swapping because:

  • The swapping potentially makes every memory page access a thousand (or more) times slower (and Linux swapping mechanism is not specifically fast).
  • As more memory swapped, more operations take longer time
  • As operations take longer time, more requests come in to be served
  • The demand for resources exponentially increase

Due to scenario above, if any memory bound application is running (like a database), if swapping is started, most of the time there is no recovering back.

The Oracle Database SGA pages are pageable on Linux by default, and potentially those pages can be swapped out if system runs out of memory. Using HugePages  is one of the methods to make the Oracle SGA not to be swapped out at all, still one needs to be careful about the configuration. To learn all about HugePages please read Document 361323.1 and references.

Conclusions

  • Make sure total SGA, PGA fit in the RAM also leaving some decent memory for process spaces and system services. See the database installation guides for more information
  • Consider using HugePages on Linux
  • Be very careful with memory configuration (HugePages, Automatic Memory Management, Swap, VLM)
  • Monitor OS continuously for memory usage and swapping

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2150984.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Python游戏开发中的16个关键概念

大家好!今天我们要聊的是Python游戏开发中的一些关键概念。无论是初学者还是有一定经验的开发者,了解这些概念都将有助于你更好地掌握游戏开发的基础。接下来,我们将从简单的概念入手,逐步过渡到更复杂的技巧。 文末有惊喜福利 1.…

如何选择适合客户运营团队的帮助中心搭建工具?8款工具盘点

在竞争激烈的商业环境中,客户运营团队需要高效、便捷的工具来搭建帮助中心,以提升客户服务质量和用户体验。选择合适的帮助中心搭建工具,不仅能提高团队工作效率,还能增强客户满意度和忠诚度。本文将为您盘点八款适合客户运营团队…

FC优化配置

1.集群扩容CNA时打开bmc 2.给rhel7虚拟机安装tools-需要重启虚拟机 3.FC上创建集群 资源池右击创建集群(物理机大于10台,分业务类型创建集群) (解决集群内主机挂了,动态调整) (解决集群内个别…

vulnhub(11):derpnstink(hydra爆破用户名和密码、验证的文件上传)

端口 nmap主机发现 nmap -sn 192.168.159.120/24 ​ Nmap scan report for 192.168.159.120 Host is up (0.00020s latency). ​ 120是新出现的机器,他就是靶机 nmap端口扫描 nmap -Pn 192.168.159.120 -p- --min-rate 10000 -oA nmap/scan 扫描开放端口保存到 nma…

C#为任意组件开发登录功能的记录

非常简单,直接给出代码: 数据库操作类 这个无需多言就是简单的包含了数据操作的内容,允许你在这一个类中写完关于本地数据库或者云数据库操作的逻辑,与登录逻辑分开哦。 注意,如果你的软件要给别人运行使用&#xf…

电脑连接手机热点只能登陆qq和微信 浏览器无法正常上网的原因

电脑连接手机热点只能登陆qq和微信 浏览器无法正常上网的原因 浏览器有报错dns错误 但是火绒无法正常修复 DNS配置异常 chrome报错DNS_PROBE_FINISHED_BAD_CONFIG 错误原因在ipv4dns服务器他的地址,如果是自动获取 是192.168.208.143 和ipv4地址冲突,导致不正常,我查看本机…

【南方科技大学】CS315 Computer Security 【Lab3 Format String Vulnerability】

目录 Lab OverviewLab TasksTask 1: The Vulnerable ProgramTask 2: Understanding the Layout of the StackTask 3: Crash the ProgramTask 4: Print Out the Server Program’s MemoryTask 5: Change the Server Program’s MemoryTask 6: Inject Malicious Code into the Se…

【第十一章:Sentosa_DSML社区版-机器学习分类】

目录 11.1 逻辑回归分类 11.2 决策树分类 11.3 梯度提升决策树分类 11.4 XGBoost分类 11.5 随机森林分类 11.6 朴素贝叶斯分类 11.7 支持向量机分类 11.8 多层感知机分类 11.9 LightGBM分类 11.10 因子分解机分类 11.11 AdaBoost分类 11.12 KNN分类 【第十一章&…

С++第十三节课 string初体验

一、string类的相关函数 string实际上也就是一个管理字符的顺序表! 如果我们需要遍历一个字符串,怎么实现? 我们可以通过下标访问操作符 size实现字符串的遍历! int main() {string s1("hello world");// 遍历一个字…

玩具车检测系统源码分享

玩具车检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer Visio…

zynq SDK 关于SD卡报错

在修改了BD的部分代码之后,重新综合工程生成bit,之后刷新hdf文件,在SDK端就出现了SD卡相关的函数未定义的报错: Description Resource Path Location Type E:\Work\VivadoPrj\Prj1\project_1\project_1.sdk\Test\Debug/…/src/hel…

arm开发板通信

c语言复习 查询Ubuntu版本(18.04)和内核(5.4) 查询使用软件的版本号 arm开发板通信- 直播视频-- 项目第二天下午 2024-09-20 linux和windows下操作开发板前提是开发板中已经导入系统 以下是具体操作 linux下开发板的操作 li…

Java项目实战II基于Java+Spring Boot+MySQL的读书笔记共享平台(开发文档+数据库+源码)

目录 一、前言 二、技术介绍 三、系统实现 四、论文参考 五、核心代码 六、源码获取 全栈码农以及毕业设计实战开发,CSDN平台Java领域新星创作者,专注于大学生项目实战开发、讲解和毕业答疑辅导。获取源码联系方式请查看文末 一、前言 在信息爆炸…

无人机黑飞打击技术详解

随着无人机技术的普及,无人机“黑飞”(未经授权或违反规定的飞行)现象日益严重,对公共安全、隐私保护及重要设施安全构成了严重威胁。为有效应对这一挑战,各国政府和安全机构纷纷研发并部署了一系列无人机黑飞打击技术…

龙头名企HR数字创新:超8成参调企业上线电子签

近日,法大大与人力资源智享会(以下简称“智享会”)联合发布了《第七届人力资源共享服务中心研究报告》(点击阅读及下载:最新!《第七届人力资源共享服务中心研究报告》重磅来袭),该报…

反转字符串中的单词--力扣151

反转字符串中的单词 题目思路代码 题目 思路 题目的难点在于首先要清除多余的空格,并且单词之间要留一个空格,首单词前和末尾单词后不能有多余空格。我们使用双指针去除所有的空格,然后在处理完一个单词后手动加一个单词。具体思路是当快指针…

李沐 过拟合和欠拟合【动手学深度学习v2】

模型容量 模型容量的影响 估计模型容量 难以在不同的种类算法之间比较,例如树模型和神经网络 给定一个模型种类,将有两个主要因素: 参数的个数参数值的选择范围 VC维

GBDT算法原理及其公式推导过程

GBDT(Gradient Boosting Decision Tree,梯度提升决策树)是一种集成学习方法,主要用于回归和分类任务。它的基本思想是通过迭代地构建一系列弱学习器(通常是决策树),并将这些弱学习器组合成一个强…

C++11 新的类功能

前言 上一期我们对右值引用和完美转发作了介绍,本期我们接着上期继续介绍C11的新的类功能! 目录 前言 • 新的类功能 默认成员函数 类成员变量初始化 强制生成默认函数的关键字default 禁止生成默认成员函数的关键字delete 继承和多态中的final…

流动网红打卡车!苏州金龙海格双层巴士带你体验别样津门津韵

近日,由文化和旅游部主办,天津市文化和旅游局等单位承办的2024中国文化旅游产业博览会在天津拉开帷幕,展会期间,来自全国各地的文旅产品精彩亮相。而在天津交通集团展台,来自苏州金龙海格客车制造的网红双层观光“音乐…