swappiness swapon 可在线做

memory中 buff/cache如果缓存的是磁盘中的file,当申请磁盘读写时可以从cache中找到的话可以提高database的读写性能,但是ASM好像不行,所以如果确保内存足够,是否可以考虑disable swap?

MOS未有明确说明。

Applies to:

Oracle Cloud Infrastructure - Database Service - Version N/A to N/A [Release 1.0]
Information in this document applies to any platform.

Goal

+ Why Swap is being Consumed when Physical Memory is Available in DBaaS System or in any Linux System.

#free -m
  total used free shared buffers cached
Mem: 120616 115746 4869 167 390 44187
-/+ buffers/cache: 71169 49447
Swap: 2047 1614 433

Solution

+  It's normal for Linux systems to start swapping before the RAM is filled up. This is done to improve performance and responsiveness:

Performance is increased because sometimes RAM is better used for disk cache than to store program memory. So it's better to swap out a program that's been inactive for a while, and instead keep often-used files in cache.

RAM给cache更好,而不是给program(也就是程序进程,比如不常用的进程)


Responsiveness is improved by swapping pages out when the system is idle, rather than when the memory is full and some program is running and requesting more RAM to complete a task.

+ In Linux, Swappiness is the rate at which kernel moves pages into and out of active memory. Swappiness can have a value of between 0 and 100

swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible. For Kernel version 3.5 and newer it disables swapiness.


swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

+ You may check the the swappiness value using below (ideally on latest Linux system it's set to 60)

[opc@rrr ~]$ cat /proc/sys/vm/swappiness
60
[opc@rrr ~]$

-----------如果内存足够,可以禁用swap----------------------

Goal

 Having the Swap enabled could lead to performance problems.

This document discusses under which circumstances you could disable the swap and how to do that.

Solution

In OCOM 3.x swap is enabled as it is in Palladion 2.x with a swapiness of 60 - which means the system will tend to swap memory even if there is RAM used for caching and could be potentially freed.

This might result in performance issues.

Technical background

Beside the RAM there is a so called Swap (in OCOM realized as partition, but could be in general also just a file), which is a virtual memory, where RAM content (pages) could be swapped-in in case there is not enough RAM available anymore.

This swap is located on the disc and since disc reads and writes are slower than reading from RAM, accessing memory pages there will result in a delay.

The cache in Linux is used to speed up reads from disc - content which has been read ones from disc is kept in memory, so that if there is a request for the same content later again, it has not to be read again from disc, but taken from memory. This is much faster then reading it from the disc.

The cache usually uses all free memory (fills up slowly as files are read from disc).

The RAM used for cache could be freed at any time if a program requests additional memory and there is no unused (free in atop, top and ps) RAM anymore.

However it could make sense to keep the cached files in the RAM and satisfy the request for additional memory by swapping (writing memory pages from the RAM into the slower Swap on disc) some currently not used memory pages of other running processes. This makes especially sense when you often have to read the same files again and again (for example with databases), to keep the fast file access performance.

On Linux systems the so called swapiness defines what should be done in case there is no unused memory anymore and a program requests more memory, whether it should be preferred to swap out memory pages currently not needed of other programs or to release memory from the cache.

In OCOM it is defined to be 60, which means the system tends to preserve the cache in RAM and swap out memory pages not used for some time.

 Conditions

  • there are performance issues which are disk related/related that memory needs to be re-swapped into RAM
    • atop shows in row DSK a high load during the issue happens
    • atop row PAG shows at that time scan
    • in atop the SWP row shows some used swap - the difference between "tot" and  "free" 
  • there is enough free RAM which could take the content of the swap
    • do free -m 
      • in row "-/+ buffers/cache:"  "free" tell how much RAM is actually available (if the disc cache would be freed)
      • in row "Swap:" "used" tells you how much memory is currently swapped
    • compare the value of free and Swap
      • if the value of free covers the "used" value of swap go ahead (make sure that free is some bigger (preferable some GBytes) than what is needed to get the amount from swap to RAM -> so that you still have some RAM free for caching or if a service needs exceptional more RAM than usually)
      • if there is just less more memory in "free" than in "used" for swap or less in "free" than in "used" for swap, you need to upgrade the RAM before you could proceed

Checking if swap is on

To check if swap is on or off, run "swapon -s" from the shell interface. If this command returns a non-empty output than the swap is on, for example:

root@ocsm:~# swapon -s
Filename                Type         Size       Used    Priority
/dev/sda1               partition    7999484    1201556    0
root@ocsm:~#

Here is how the output looks like if swap is off:

root@ocsm:~# swapon -s
Filename                                Type            Size    Used    Priority
root@ocsm:~#

Disabling temporarily

For testing whether a certain issue might be influenced by the usage of swap you might turn of the swap temporarily.

This action takes affect immediately, the content of the swap is written to the RAM.

The action stays in place till swapon -a is executed or the system is rebooted.

Deactivate the swap:

  • Login via ssh to the system
  • swapoff -a

Activate  the swap again:

  • Login via ssh to the system
  • swapon -a

Disabling permanently

  • Login via ssh
  • in /etc/fstab comment the line by setting a "#" in front:

UUID=347569f8-88d2-4ad1-8a04-01eacd2cd4ba    swap    swap    defaults    0    0

Please note: The UID might be different in your case, important is the "swap" entry.

To trigger the change use one of the options:

  • type swapoff -a
  • OR reboot (by entering "reboot")

To double check the current state, use command swapoff -s (see step "Checking if swap is on" above)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值