Linux系統出現hung_task_timeout_secs和blocked for more than 120 seconds的解決方法


 

Linux系統出現系統沒有響應。 在/var/log/message日志中出現大量的 “echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.” “blocked for more than 120 seconds”錯誤。

問題原因:

默認情況下, Linux會最多使用40%的可用內存作為文件系統緩存。當超過這個閾值后,文件系統會把將緩存中的內存全部寫入磁盤, 導致后續的IO請求都是同步的。將緩存寫入磁盤時,有一個默認120秒的超時時間。 出現上面的問題的原因是IO子系統的處理速度不夠快,不能在120秒將緩存中的數據全部寫入磁盤。IO系統響應緩慢,導致越來越多的請求堆積,最終系統內存全部被占用,導致系統失去響應。

解決方法:

根據應用程序情況,對vm.dirty_ratio,vm.dirty_background_ratio兩個參數進行調優設置。 例如,推薦如下設置:
# sysctl -w vm.dirty_ratio=10
# sysctl -w vm.dirty_background_ratio=5
# sysctl -p

如果系統永久生效,修改/etc/sysctl.conf文件。加入如下兩行:
#vi /etc/sysctl.conf

vm.dirty_background_ratio = 5
vm.dirty_ratio = 10

sysctl -p

 

最近遇到過一個問題:

apache服務器的負載飆升到700多,導致無法提供正常的http服務,此時查看系統日志時,發現:

Jan  4 09:57:03 locasv107 kernel: INFO: task httpd:18463 blocked for more than 120 seconds.
Jan  4 09:57:03 locasv107 kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.

諸如此類的報警日志。

查詢了資料后對於該參數的了解為后台對進行的任務由於超時而掛起
從以上的報錯信息也給出了簡單的解決方案,就是禁止該120秒的超時:echo 0 > /proc/sys/kernel/hung_task_timeout_secs
隨后詢問了主機工程師:給出方案是按照告警里的提示將該提醒disable

后續詢問后給出如下解釋:
This is a know bug. By default Linux uses up to 40% of the available memory for file system caching.
After this mark has been reached the file system flushes all outstanding data to disk causing all following IOs going synchronous.
For flushing out this data to disk this there is a time limit of 120 seconds by default.
In the case here the IO subsystem is not fast enough to flush the data withing 120 seconds.
This especially happens on systems with a lof of memory.

The problem is solved in later kernels and there is not “fix” from Oracle.
I fixed this by lowering the mark for flushing the cache from 40% to 10% by setting “vm.dirty_ratio=10″ in /etc/sysctl.conf.
This setting does not influence overall database performance since you hopefully use Direct IO and bypass the file system cache completely.
告知是linux會設置40%的可用內存用來做系統cache,當flush數據時這40%內存中的數據由於和IO同步問題導致超時(120s),所將40%減小到10%,避免超時。

 

轉載:https://www.cnblogs.com/wshenjin/p/7093505.html

https://blog.csdn.net/yanggd1987/article/details/42388421


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM