調整linux內核儘量用內存,而不用swap

線上一臺服務器kswapd0佔用大量的cpu資源,導致負載過高,什麼是kswapd0?

調整linux內核儘量用內存,而不用swap

Linux uses kswapd for virtual memory management such that pages that havebeen recently accessed are kept in memory and less active pages are paged outto disk.
(what is a page?)…Linux uses manages memory in units called pages.
So,the kswapd process regularly decreases the ages of unreferencedpages…and at the end they are paged out(moved out) to disk

kswapd0進程的作用:它是虛擬內存管理中,負責換頁的,操作系統每過一定時間就會喚醒kswapd ,看看內存是否緊張,如果不緊張,則睡眠,在 kswapd 中,有2 個閥值,pages_hige 和 pages_low,當空閒內存頁的數量低於 pages_low 的時候,kswapd進程就會掃描內存並且每次釋放出32 個free pages,直到 free page 的數量到達pages_high。

分析結果是:
physical mem 不足,引起 swap 頻繁讀寫。
kswapd0 是系統的虛擬內存管理程序,如果物理內存不夠用,系統就會喚醒 kswapd0 進程,由 kswapd0 分配磁盤交換空間作緩存,因而佔用大量的 CPU 資源。

查看內存及swap使用率:發現還有空餘的內存,但是已經開始用swap了。
調整linux內核儘量用內存,而不用swap

內存使用到多少開始使用swap?
vm.swappiness 這個內核參數控制
/proc/sys/vm/swappiness

這個交換參數控制內核從物理內存移出進程,移到交換空間。該參數從0到100,當該參數=0,表示只要有可能就盡力避免交換進程移出物理內存;該參數=100,這告訴內核瘋狂的將數據移出物理內存移到swap緩存中。
The defaultvalue I’ve seen on both enterprise level Red Hat and SLES servers is 60.
To find out what the default value is on aparticular server, run:
sysctl vm.swappiness
The value is also located in/proc/sys/vm/swappiness.

PS:設置vm.swappiness=0 後並不代表禁用swap分區,只是告訴內核,能少用到swap分區就儘量少用到,設置vm.swappiness=100的話,則表示儘量使用swap分區,默認的值是60

調整內存參數,當內存使用率不足10%(開始是默認值60)時在使用swap,儘量避免使用swap,減少喚醒軟中斷進程,從而降低ksoftirqd進程對cpu的佔用。

調整linux內核儘量用內存,而不用swap

http://lxshopping.blog.51cto.com/4542643/1573947

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章