Why does my Red Hat Enterprise Linux (RHEL) system swap despite of having free RAM?

简介: Why does my Red Hat Enterprise Linux (RHEL) system swap despite of having free RAM?Swapping in a linux system happens under two conditions.1) Anonymous mapped memory.2) Oversized workload abusing memory overcommit.In our problem, only point 1 is valid. So, we will discuss that here.

Why does my Red Hat Enterprise Linux (RHEL) system swap despite of having free RAM?
Swapping in a linux system happens under two
conditions.
1) Anonymous mapped memory.
2) Oversized workload abusing memory overcommit.
In our problem, only point 1 is valid. So, we will discuss that here.

1) Anonymous mapped memory
Only pages which aren't filesystem backed i.e. doesn't have in disk place, gets swapped. The pages which aren't filesystem backed are called anonymous pages. This can be checked in /proc/meminfo file with the AnonPages field. Unmapped pages are those which are not present in address space of any process. they are not present in page tables. But anon mapped memory is present in page table and exists in process address space. Since they are anon, they are the candidates to be swapped.

The page frame reclaim algorithm (PFRA) performs periodic reclaiming in a linux system. It does this by two methods. One is by kswapd which invoke shrink_zone( ) and shrink_slab( ) to reclaim pages from the LRU (Least Recently Used) lists and another is cache_reap( ) function which reclaims unused slabs from the slab allocator.

Now, the entire RAM is divided into zones, as can be seen in /proc/zoneinfo . Each zone in memory has a field called pages(low). Now, the function __alloc_pages( ) might discover that there are zones where the pages(free) is less than pages(low) and then it will invoke kswapd kernel thread. This indicates that the kernel is reclaiming some pages to avoid the aggressive 'low on memory' or 'out of memory' conditions.

But why do it? We have try_to_free_pages() which does the direct path reclaiming. So why we can't just sit around and wait for low on memory condition and then work. Because that will be inefficient. Because, apart from user space processes, kernel can also request pages in interrupt context. That means it can't wait until free pages are discovered. And if there is some critical code that has already acquired an exclusive lock and wants memory, we have to satisfy it. So, to be on the safe side, we have kswapd doing the reclaim. Now, this reclaim is also done from the LRU list. Meaning, only the inactive pages in the anonymous memory region are reclaimed.

Summing up, every time we hit the page allocator, i.e. whenever some memory allocation is being done, the low, high and free watermarks in a memory zone are checked and if it finds that the zone is not balanced, kswapd wakes up and balances the zone. The logic is, why would kernel want some modified anon pages to lie around for a longer time when it can sort out the allocation in a better way.

Other notes
There are two other properties of virtual memory which you should consider in these circumstances:

   •   When the kernel needs contiguous memory for some reason, and memory is fragmented, this is handled as if the system were low on memory, and swapping can occur.
   •   The kernel strongly prefers to make NUMA-local allocations, often to the point of swapping rather than making an allocation on another node.


This is the default expected behaviour under a linux system. This is how the PFRA works.

Check /proc/meminfo file and note the counters of SwapTotal and SwapFree .

---https://access.redhat.com/solutions/406253

相关文章
|
3天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
13 2
|
4天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
11 3
|
2月前
|
Docker 容器
14 response from daemon: open \\.\pipe\docker_engine_linux: The system cannot find the file speci
14 response from daemon: open \\.\pipe\docker_engine_linux: The system cannot find the file speci
28 1
|
3月前
|
Ubuntu Linux 测试技术
下载ISO镜像的方法 Debian、Red Hat 、CentOS、Ubuntu、Kali Linux🌐
Debian、Red Hat、CentOS、Ubuntu与Kali Linux均为知名Linux发行版。下载Debian须访问官网并按计算机架构选ISO文件。Red Hat下载通常需订阅账户,可从官网登录后获取。CentOS可从官网或镜像站点下载,注意CentOS 8已停更。Ubuntu下载简便,官网直接选取版本及架构即可。Kali Linux专为安全测试设计,官网提供直接下载ISO镜像服务。
549 0
|
4月前
|
消息中间件 Linux
【Linux】进程间通信——system V(共享内存 | 消息队列 | 信号量)(下)
【Linux】进程间通信——system V(共享内存 | 消息队列 | 信号量)(下)
63 0
|
4月前
|
消息中间件 存储 Linux
【Linux】进程间通信——system V(共享内存 | 消息队列 | 信号量)(上)
【Linux】进程间通信——system V(共享内存 | 消息队列 | 信号量)(上)
71 0
|
5月前
|
Ubuntu Oracle 关系型数据库
Linux操作系统最著名的两大系列Red Hat和Debian
Linux操作系统最著名的两大系列Red Hat和Debian
173 2
|
5月前
|
消息中间件 Linux
【Linux】System V 消息队列(不重要)
【Linux】System V 消息队列(不重要)
|
5月前
|
消息中间件 算法 Unix
【Linux】System V 共享内存
【Linux】System V 共享内存
|
6月前
|
存储 Linux
Redhat Enterprise Linux磁带机简单操作
Redhat Enterprise Linux磁带机简单操作
64 2