dirty pages , swapiness 查看SWAP占用进程
文章说了这么多的意思 就是不要过度分配不用的内存。虽然脏块不会写入swap,但是占了物理内存,浪费空间,可能导致进行了很多不必要的交换(虽然判断很少要进swap,判断要不要也要时间。。。)。
To verify which PIDs are using swap area - bellow command can be used:
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r
和top f s 效果一样
有第三方网页也评论说,将 vm.swappiness 设置为 10 将仅在分配了 90% 的可用内存时才使用交换空间 - 这是不正确的,因为 vm.swappiness 不是这样工作的(它的缓存页面窃取率与由于内存不足而导致的交换率)类似的设置 vm.swappines 为 100 并不意味着将在启动后立即使用交换空间。
Applies to:
Linux OS - Version Oracle Linux 5.1 to Oracle Linux 9.0 [Release OL5U1 to OL9]
Oracle Cloud Infrastructure - Version N/A and later
Linux x86
Linux x86-64
Goal
This document help us to explain the dirty pages in Oracle Linux
Solution
Whenever application/database process(进程) needs to add virtual page(VM,现在内存管理机制) into physical memory but no free physical pages are left ,OS must clear-out remaining old pages.
Now if old page had not been written (未改动)at all then this one does not need to be saved it can be simply recovered from the the data file.
But if old page has been modified already then it must be preserved somewhere so application/database can re-used later on - this is called dirty page.(数据库中的脏块)
OS stores such dirty pages in swap files ( so it can be removed from physical memory so another 'new' page can be stored in physical memory ) 为什么不直接写入file?OS也有commit一说
If lots of data will be removed from page cache to dirty page area(swap的过程) - this might cause significant IO bottleneck if actual swap device is located on local disk ( sda ) and more-over cause further issues if local disk is used as well by local root ( OS ) disk. 硬盘同时给OS和swap用,大部分的情况。
Page cache in Linux is just a disk cache (page cache等于disk cache) which brings additional performance to OS which helps with intensive high read/writes on files.
Further details can be found in km note:
How to Check Whether a System is Under Memory Pressure (Doc ID 1502301.1)
As 'sub' (子,附属)product of page cache is dirty page - which was explained in above example case.
Dirty pages can be also observed whenever application will write to file or create file - first write will happen in page cache area - hence creating a file which 10MB file can be really fast:
内存中申请页面
# dd if=/dev/zero of=testfile.txt bs=1M count=100
10+0 records in
10+0 records out
10485760 bytes (100 MB) copied, 0,1121043 s, 866 MB/s
Its because that file is created in memory region not actual disk - hence response time is really fast.
Under the OS such thing will be noted in /proc/meminfo and more over in 'Dirty:
Before above command will get executed - note-down the /proc/meminfo and 'Dirty' row:
# more /proc/meminfo | grep -i dirty
Dirty: 96 kB
After command is executed:
# more /proc/meminfo | grep -i dirty
Dirty: 102516 kB
Periodically OS or application/database will initiate sync which will write actual testfile.txt to disk:
操作系统或应用程序/数据库将定期启动同步,application 也可以发起sync操作
# more /proc/meminfo | grep -i dirty
Dirty: 76 kB
Now Oracle Database for example does not allow to do such writes into memory region as if OS will crash or if SAN LUn will fail - data will be compromised.
That's why Oracle Database requires data to be 'in-sync' hence all writes needs to be confirmed by backend like disk/lun before database will throw more write requests.
Normally Databases/Application periodically drop cache hence dirty pages are written to disk in small chunks.(drop cache 导致自动同步)
In some cases dirty pages can grow in size as maybe application/database did not configured page cache mechanism properly. OS 和application共同管理page cache
So dirty pages can write to swap files ( Swap area ) but also to special region in disk ( LUN/file-system ) 可以写swap 也可以直接写file
If for example we create more than 100MB swap file which will be re-used later from swap file we might cause uncecessary IO issues on swap device.
Enterprise systems store swap files and swap area on OS under solid state drives ( SSD ) or dedicated LUN hence local disk performance won't be impacted ( as normally swap region is created on Local disk ) swap盘也要专用
In some cases application/database might have issues internally and dirty pages will be written as swap files but will be never re-used this will cause swap area to grow and cause uncessary IOs on local disk and lead to large swap usage under OS.
To find out at what stage OS will try to dump dirty pages back to disk layer please check official kernel documentation around Virtual Memory here and look for settings like:
vm.dirty_background_ratio
vm.dirty_ratio
vm.swappiness
and
dirty_background_ratio
dirty_ratio
dirty_background_bytes
dirty_expire_centisecs
Above settings needs to be tuned per Database/Application requirement as OS does not have any 'best practice' setting for them - they are tuned per DB/APP load/configuration 它们是根据 DB/APP 负载/配置进行调整的
Whenever application/database will demand memory pages to be free on physical memory - OS tends to keep everything in page cache - hence OS will need to re-allocate some of the pages and mark them as dirty. 新分配出的memory pages都是dirty块,如果块未改动就不要留(同上 Now if old page had not been written (未改动)at all then this one does not need to be saved it can be simply recovered from the the data file.)
This process is works fine if application/database end are properly tuned and scaled 调整和扩展- otherwise it will cause really aggressive swappiness to occur - as OS will need to write all dirty pages back to swap disk - this can be controlled via vm.swappiness setting.
If application/database will do agreessive负面 swappiness it might cause serious IO writes on swap device and lead to serious system stalls系统停顿 - always make sure that application/databases are properly configured in terms of memory management.
As explained not all pages will be marked as dirty - mostly unused pages will get discarded 丢弃rather than marked as dirty ( it all depends if pages which already are allocated were modified or not )
上面说了这么多的意思 就是不要过度分配不用的内存。虽然脏块不会写入swap,但是占了浪费空间,进行了不必要的交换
To verify which PIDs are using swap area - bellow command can be used:
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r
和top f s 效果一样
Releasing 'consumed' swap space is really limited, normally if PID exits properly or simply gets shutdown swap space will be re-claimed but killing PID or if it ends-up abnormally like segfault might still leave swap space consumed. Another option is to reboot as doing swapoff and swapon command can cause serious issues or even lead to system panic state.甚至导致系统崩溃状态。 正常退出的可以释放swap 非正常的可以kill了也不会释放
To understand why swap is still consumed even if swappines is set to 0 - please refer to the KM here
References
NOTE:2328563.1 - Oracle Linux: Setting vm.swappiness=0 Does Not Completely Disable Swap Usage
---------------------------Setting vm.swappiness=0 Does Not Completely Disable Swap Usage
Why adding vm.swappiness=0 to /etc/sysctl.conf does not completely disable swap usage ?
Solution
Explanation on vm.swappiness setting from kernel documentation:
Swappiness
This control is used to define how aggressive the kernel will swap
memory pages. Higher values will increase agressiveness, lower values
decrease the amount of swap. A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.
So if there is swap present, it'll be used if needs be. vm.swappiness=0 discourages the kernel from using it, but doesn't prevent it.
Below example from TOP command under OL7 might be confusing:
top - 12:21:27 up 2 days, 16:57, 4 users, load average: 1.62, 1.95, 2.13
Tasks: 539 total, 1 running, 538 sleeping, 0 stopped, 0 zombie
%Cpu(s): 13.8 us, 3.7 sy, 0.0 ni, 79.2 id, 3.0 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem : 36383529+total, 1715556 free, 32909801+used, 33021720 buff/cache
KiB Swap: 5388604 total, 103444 free, 4185160 used. 33684252 avail Mem
Available mem is shown as 30GB free but best is to verify /proc/meminfo where MemAvailable is specified:
cat /proc/meminfo | grep MemAvailable
MemAvailable: 2440244 kB
What is MemAvailable:
An estimate of how much memory is available for starting new applications, without
swapping.
Calculated from MemFree, Reclaimable, the size of the file LRU lists, and the
low watermarks in each zone.
The estimate takes into account that the system needs some page cache to function well,
and that not all reclaimable slab will be reclaimable, due to items being in use.
The impact of those factors will vary from system to system.
Hence even if system shows 30GB as free actual MemAvailable is quiet low and it might cause higher swap usage even if setting swappiness is set to 0
Another explanation of swap usage might be related to dirty pages km note: 2304722.1 or missing Database tuning which is explained in 1295478.1
There are 3rd party web pages which also comment that setting vm.swappiness to 10 will make swap space only utilized if 90% of free memory is allocated - this is not true as vm.swappiness does not work like this ( its page steal ratio from cache vs swapping due to insufficient memory ) similar setting vm.swappines to 100 does not mean swap will be used immediately after boot.
正常设置60%,所以到40%内存使用时就考虑使用swap,这个是对的啊!!居然说人家错
Official statement on vm.swappiness can be found in official kernel memory documentation here
As side note 顺便说一句- swap usage can be lowered by enabling hugepages - but this will only apply mostly to Oracle Database cases as enabling hugepages won't stop system or application layer from swapping. hugepages只能用于SGA,pga不能避免
Reference km ntoe:
HugePages on Oracle Linux 64-bit (Doc ID 361468.1)
And statement:
"The HugePages configuration described in this document does not cause the O/S components to use HugePages. HugePages will be used by applications which explicitly make use of HugePages in their code (like majority of Oracle RDBMS SGA given proper configuration). Therefore, you will still see swap usage on the system as the regular O/S components, or non-HugePages-aware applications use swappable pages."
Also executing well known command on 3rd party websites, eg:
# swapoff -a && swapon -a
Is not supported or either recommended - if system already struggle with memory and swap - customers should validate their configuration settings or properly tune APP/DB end:
How to Calculate Memory Usage on Linux (Doc ID 1630754.1)
Rather than disabling swap device and dumping off allocated pages in swap device 这个是dump回内存还是 file??
Hence unexpected results from above commands won't be debug'd by Oracle Linux support in case of issues ( as during dumping-out of swap device, lots of services/pids might still relay on things put in swap device leading to uncontrolled results )
(例如,在转储交换设备期间,许多服务/PID 可能仍会中继放入交换设备的内容,从而导致不受控制的结果 )
------
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)
当几乎所有可用的物理内存 (RAM) 都开始在 Linux 中使用时,内核将开始将页面换出到交换空间(磁盘空间),或者更糟糕的是,它可能会开始换出整个进程。另一种情况是它开始使用内存不足 (OOM) Killer 杀死进程。-------- 进程进到swap中,而不是cache page
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.
由于上述情况,如果任何内存受限的应用程序正在运行(如数据库),如果启动了交换,则大多数情况下不会恢复。得是SGA才行
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
结论
- 确保总 SGA、PGA 适合 RAM,并为进程空间和系统服务留出一些不错的内存。有关更多信息,请参阅数据库安装指南
- 考虑在 Linux 上使用 HugePages
- 非常小心内存配置 (HugePages, Automatic Memory Management, Swap, VLM)
- 持续监控操作系统的内存使用情况和交换情况
相关文章:

dirty pages , swapiness 查看SWAP占用进程
文章说了这么多的意思 就是不要过度分配不用的内存。虽然脏块不会写入swap,但是占了物理内存,浪费空间,可能导致进行了很多不必要的交换(虽然判断很少要进swap,判断要不要也要时间。。。)。 To verify whic…...

Spring Boot项目更改项目名称
背景:新项目开始前,往往需要初始化功能,拿到基础版本后更改项目对应的名称等信息。 更改步骤如下: 1、修改目录名称。 打开本地项目,右键修改项目名称。 2、修改maven项目的pom依赖 修改parent及modules项目名称&…...

Hive SQL基础语法及查询实践
目录 基础语法 1. 官网地址 2. 查询语句语法 基本查询(Select…From) 数据准备 (0)原始数据 (1)创建部门表 (2)创建员工表 (3)导入数据 全表和特定列查…...

k8s service如何实现流量转发
1 基本概念 Service:在Kubernetes(K8s)中,Service用于将流量转发到后端的Pod中。Service提供了一种稳定的网络入口,尽管后端的Pod可能会动态改变 kube-proxy: kube-proxy是Kubernetes集群中的核心组件之一࿰…...

每日一练:K个一组翻转链表
25. K 个一组翻转链表 - 力扣(LeetCode) 一、题目要求 给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表。 k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍&#x…...

昨晚,OpenAI震撼发布o1大模型!我们正式迈入了下一个时代。
大半夜的,OpenAI抽象了整整快半年的新模型。 在没有任何预告下,正式登场。 正式版名称不叫草莓,草莓只是内部的一个代号。他们的正式名字,叫: 为什么取名叫o1,OpenAI是这么说的: For complex …...

MySql8.x---开窗函数
1、定义 语法结构: ** 开窗函数|聚合函数 over([分组函数] [排序函数] [自定义窗口]) ** 分组函数:partition by ...,根据指定的字段对表分组,分组字段可以有多个。省略时表示整个表为一组。 排序函数:order by ...&…...

图文讲解HarmonyOS应用发布流程
HarmonyOS应用的开发和发布过程可以分为以下几个步骤:证书生成、应用开发、应用签名和发布。 1. 证书生成: 在开始开发HarmonyOS应用之前,首先需要生成一个开发者证书。开发者证书用于标识应用的开发者身份并确保应用的安全性。可以通过Har…...

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)
原文链接: https://tecdat.cn/?p37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预…...

经典负载调制平衡放大器(LMBA)设计-从理论到ADS仿真
经典负载调制平衡放大器(LMBA)设计-从理论到ADS仿真 ADS工程下载:经典负载调制平衡放大器(LMBA)设计-从理论到ADS仿真-ADS工程 参考论文: An Efficient Broadband Reconfigurable Power Amplifier Using Active Load…...

Web开发:基础Web开发的支持
创建项目: 添加依赖: <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://mav…...

【LeetCode每日一题】——LCR 168.丑数
文章目录 一【题目类别】二【题目难度】三【题目编号】四【题目描述】五【题目注意】六【题目示例】七【题目提示】八【解题思路】九【时间频度】十【代码实现】十一【提交结果】 一【题目类别】 优先队列 二【题目难度】 中等 三【题目编号】 LCR 168.丑数 四【题目描述…...

Day7 | Java框架 | SpringMVC
Day7 | Java框架 | SpringMVC SpringMVC简介SpringMVC 概述入门案例入门案例工作流程分析Controller 加载控制与业务bean加载控制(SpringMVC & Spring)PostMan 请求与响应请求映射路径请求方式(不同类型的请求参数)࿱…...

【网络通信基础与实践第二讲】包括互联网概述、互联网发展的三个阶段、互联网的组成、计算机网络的体系结构
一、互联网概述 计算机网络是由若干节点(node)和连接这些节点的链路(link)组成。 网络之间还可以通过路由器互联起来,这就构成了一个覆盖范围更大的计算机网络。这样的网络称为互联网。 网络把许多计算机连接在一起…...

CentOS7下安装Ruby3.2.4的实施路径
一、CentOS版本 [userzt ~]$ cat /etc/os-release NAME"CentOS Linux" VERSION"7 (Core)" ID"centos" ID_LIKE"rhel fedora" VERSION_ID"7" PRETTY_NAME"CentOS Linux 7 (Core)" ANSI_COLOR"0;31" CPE…...

Redis 实现原理或机制
Redis 是一个高性能的、基于内存的键值对存储系统,广泛用于缓存、会话管理、排行榜和消息队列等场景。它的高效性得益于其独特的实现原理和机制,Redis支持丰富的数据结构和多种持久化、复制、集群和发布/订阅功能,提供了灵活性和高可用性。 …...

使用程序方式获取与处理MySQL表数据
8.1 执行多条语句获取 MySQL 表数据 8.1.1 MySQL 中的常量 8.1.2 MySQL 中的变量 1.用户变量 用户可以在表达式中使用自己定义的变量,这样的变量称为用户变量。 用户变量在使用前必须定义和初始化,如果使用没有初始化的变量&#x…...

计算机网络(五) —— 自定义协议简单网络程序
目录 一,关于“协议” 1.1 结构化数据 1.2 序列化和反序列化 二,网络版计算器实现准备 2.1 套用旧头文件 2.2 封装sock API 三,自定义协议 3.1 关于自定义协议 3.2 实现序列化和反序列化 3.3 测试 三,服务器实现 3.1…...

开源模型应用落地-qwen2-7b-instruct-LoRA微调-unsloth(让微调起飞)-单机单卡-V100(十七)
一、前言 本篇文章将在v100单卡服务器上,使用unsloth去高效微调QWen2系列模型,通过阅读本文,您将能够更好地掌握这些关键技术,理解其中的关键技术要点,并应用于自己的项目中。 使用unsloth能够使模型的微调速度提高 2 - 5 倍。在处理大规模数据或对时间要求较高的场景下,…...

[数据集][目标检测]车油口挡板开关闭合检测数据集VOC+YOLO格式138张2类别
数据集格式:Pascal VOC格式YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):138 标注数量(xml文件个数):138 标注数量(txt文件个数):138 标注类别…...

Delphi 的 RSA 库 LockBox
LockBox 是用于 Delphi 的一套加密/解密控件 最早是一套商业控件,后来开源了。再后来,又有一个新版本的 LockBox,和旧版本完全不同。 旧版本的 LockBox 叫 LockBox 2;新版本的叫 LockBox 3。 这两个控件,都可以通过…...

element UI学习使用(1)
https://element.eleme.cn/2.6/#/zh-CN/component/container vue模块库,可复制直接使用 1、搜索框、下拉搜索框 <el-form :inline"true" class"demo-form-inline"><el-form-item label"结果搜索"><el-inputplaceho…...

如何搞定日语翻译?试试这四款工具
写一篇字数800-1000字的软文,用翻译新手的角度分享福昕翻译在线、福昕翻译客户端、海鲸AI翻译以及彩云翻译在翻译日语时候的表现,要求口语化表达。 最近对于一些轻小说突然感兴趣了,所以我开始尝试各种翻译工具来帮助我搞定日语翻译。今天&am…...

【STM32】独立看门狗(IWDG)原理详解及编程实践(上)
本篇文章是对STM32单片机“独立看门狗(IWDG)”的原理进行讲解。希望我的分享对你有所帮助! 目录 一、什么是独立看门狗 (一)简介 (二)、独立看门狗的原理 (三)、具体操…...

前端框架大观:探索现代Web开发的基石
目录 引言 一、前端框架概述 二、主流前端框架介绍 2.1 React 2.1.1 简介 2.1.2 特点 2.1.3 代码示例 2.2 Vue.js 2.2.1 简介 2.2.2 特点 2.2.3 代码示例 2.3 Angular 2.3.1 简介 2.3.2 特点 2.3.3 代码示例 三、其他前端框架与库 四、前端框架的选择 五、结…...

16 训练自己语言模型
在很多场景下下,可能微调模型并不能带来一个较好的效果。因为特定领域场景下,通用话模型过于通用,出现多而不精。样样通样样松;本章主要介绍如何在特定的数据上对模型进行预训练; 训练自己的语言模型(从头开…...

udp网络通信 socket
套接字是实现进程间通信的编程。IP可以标定主机在全网的唯一性,端口可以标定进程在主机的唯一性,那么socket通过IP端口号就可以让两个在全网唯一标定的进程进行通信。 套接字有三种: 域间套接字:实现主机内部的进程通信的编程 …...

LG AI研究开源EXAONE 3.0:一个7.8B双语语言模型,擅长英语和韩语,在实际应用和复杂推理中表现出色
EXAONE 3.0介绍:愿景与目标 EXAONE 3.0是LG AI研究所在语言模型发展中的一个重要里程碑,特别是在专家级AI领域。 “EXAONE”这个名称源自于“ EX pert A I for Every ONE”,反映了LG AI研究所致力于将专家级别的人工智能能力普及化的承诺。这…...

【mysql】mysql之主从部署以及介绍
本站以分享各种运维经验和运维所需要的技能为主 《python零基础入门》:python零基础入门学习 《python运维脚本》: python运维脚本实践 《shell》:shell学习 《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战 《k8…...

Invoke-Maldaptive:一款针对LDAP SearchFilter的安全分析工具
关于Invoke-Maldaptive MaLDAPtive 是一款针对LDAP SearchFilter的安全分析工具,旨在用于对LDAP SearchFilter 执行安全解析、混淆、反混淆和安全检测。 其基础是 100% 定制的 C# LDAP 解析器,该解析器处理标记化和语法树解析以及众多自定义属性&#x…...