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 标注类别…...
【网络】每天掌握一个Linux命令 - iftop
在Linux系统中,iftop是网络管理的得力助手,能实时监控网络流量、连接情况等,帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...
基于服务器使用 apt 安装、配置 Nginx
🧾 一、查看可安装的 Nginx 版本 首先,你可以运行以下命令查看可用版本: apt-cache madison nginx-core输出示例: nginx-core | 1.18.0-6ubuntu14.6 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages ng…...
DeepSeek 技术赋能无人农场协同作业:用 AI 重构农田管理 “神经网”
目录 一、引言二、DeepSeek 技术大揭秘2.1 核心架构解析2.2 关键技术剖析 三、智能农业无人农场协同作业现状3.1 发展现状概述3.2 协同作业模式介绍 四、DeepSeek 的 “农场奇妙游”4.1 数据处理与分析4.2 作物生长监测与预测4.3 病虫害防治4.4 农机协同作业调度 五、实际案例大…...

保姆级教程:在无网络无显卡的Windows电脑的vscode本地部署deepseek
文章目录 1 前言2 部署流程2.1 准备工作2.2 Ollama2.2.1 使用有网络的电脑下载Ollama2.2.2 安装Ollama(有网络的电脑)2.2.3 安装Ollama(无网络的电脑)2.2.4 安装验证2.2.5 修改大模型安装位置2.2.6 下载Deepseek模型 2.3 将deepse…...

RSS 2025|从说明书学习复杂机器人操作任务:NUS邵林团队提出全新机器人装配技能学习框架Manual2Skill
视觉语言模型(Vision-Language Models, VLMs),为真实环境中的机器人操作任务提供了极具潜力的解决方案。 尽管 VLMs 取得了显著进展,机器人仍难以胜任复杂的长时程任务(如家具装配),主要受限于人…...
【LeetCode】3309. 连接二进制表示可形成的最大数值(递归|回溯|位运算)
LeetCode 3309. 连接二进制表示可形成的最大数值(中等) 题目描述解题思路Java代码 题目描述 题目链接:LeetCode 3309. 连接二进制表示可形成的最大数值(中等) 给你一个长度为 3 的整数数组 nums。 现以某种顺序 连接…...
【Elasticsearch】Elasticsearch 在大数据生态圈的地位 实践经验
Elasticsearch 在大数据生态圈的地位 & 实践经验 1.Elasticsearch 的优势1.1 Elasticsearch 解决的核心问题1.1.1 传统方案的短板1.1.2 Elasticsearch 的解决方案 1.2 与大数据组件的对比优势1.3 关键优势技术支撑1.4 Elasticsearch 的竞品1.4.1 全文搜索领域1.4.2 日志分析…...
Vue 模板语句的数据来源
🧩 Vue 模板语句的数据来源:全方位解析 Vue 模板(<template> 部分)中的表达式、指令绑定(如 v-bind, v-on)和插值({{ }})都在一个特定的作用域内求值。这个作用域由当前 组件…...

消防一体化安全管控平台:构建消防“一张图”和APP统一管理
在城市的某个角落,一场突如其来的火灾打破了平静。熊熊烈火迅速蔓延,滚滚浓烟弥漫开来,周围群众的生命财产安全受到严重威胁。就在这千钧一发之际,消防救援队伍迅速行动,而豪越科技消防一体化安全管控平台构建的消防“…...

Neko虚拟浏览器远程协作方案:Docker+内网穿透技术部署实践
前言:本文将向开发者介绍一款创新性协作工具——Neko虚拟浏览器。在数字化协作场景中,跨地域的团队常需面对实时共享屏幕、协同编辑文档等需求。通过本指南,你将掌握在Ubuntu系统中使用容器化技术部署该工具的具体方案,并结合内网…...