【Linux】服务器卡死,重启报错: INFO: task blocked for more than 120 seconds

一、问题背景

业务突然不正常,后台检查服务进程,发现es集群中有服务器节点夯住没有反应,看监控磁盘IO完全消失了。

SSH到有问题的目标服务器,无法连接,测试 目标机器的22端口却是通的,测试其他业务端口也是通的,也就是说服务器处于假死装状态了。

二、问题分析、处理办法

仔细阅读打印信息发现关键信息是“hung_task_timeout_secs”,通过搜索,发现这是linux kernel的一个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 lot of memory.

The problem is solved in later kernels。

一般情况下,Linux会把可用内存的40%的空间作为文件系统的缓存。

当缓存快满时,文件系统将缓存中的数据整体同步到磁盘中。但是系统对同步时间有最大120秒的限制。

如果文件系统不能在时间限制之内完成数据同步,则会发生上述的错误。

这通常发生在内存很大的系统上。系统内存大,则缓冲区大,同步数据所需要的时间就越长,超时的概率就越大。

Linux会设置40%的可用内存用来做系统cache,当flush数据时这40%内存中的数据由于和IO同步问题导致超时(120s),所将40%减小到10%,避免超时。

缩小文件系统缓存大小

降低缓存占内存的比例,比如由40%降到10%,这样的话需要同步到磁盘上的数据量会变小,IO写时间缩短,会相对比较平稳。

文件系统缓存的大小是由内核参数vm.dirty_ratio 和 vm.dirty_backgroud_ratio控制决定的。

vm.dirty_background_ratio指定当文件系统缓存脏页数量达到系统内存百分之多少时(如5%)就会触发pdflush/flush/kdmflush等后台回写进程运行,将一定缓存的脏页异步地刷入外存。

vm.dirty_ratio则指定了当文件系统缓存脏页数量达到系统内存百分之多少时(如10%),系统不得不开始处理缓存脏页(因为此时脏页数量已经比较多,为了避免数据丢失需要将一定脏页刷入外存),在此过程中很多应用进程可能会因为系统转而处理文件IO而阻塞。

通常情况下,vm.dirty_ratio的值要大于vm.dirty_background_ratio的值。

# sysctl -w  vm.dirty_background_ratio=5

# sysctl -w  vm.dirty_ratio=10

# sysctl -a | grep  "dirty"

# vim  /etc/sysctl.conf

##############################

vm.dirty_background_ratio=5

vm.dirty_ratio=10

###############################

# sysctl -p

三、参考

[Windows/Linux]判别服务器: 虚拟机 | 物理机 ?

http://t.zoukankan.com/johnnyzen-p-13576842.html

Linux 出错 “INFO: task java: xxx blocked for more than 120 seconds.” 的3种解决方案

https://www.shuzhiduo.com/A/MAzAQAZpz9

https://www.cnblogs.com/xibuhaohao/p/11972200.html

What does “task mysqld:xxx blocked for more than 120 seconds” mean?

https://unix.stackexchange.com/questions/181505/what-does-task-mysqldxxx-blocked-for-more-than-120-seconds-mean

Linux 日志报错 xxx blocked for more than 120 seconds

https://www.cnblogs.com/kerrycode/p/5783501.html

INFO: task java:27465 blocked for more than 120 seconds不一定是cache太大的问题

https://www.shuzhiduo.com/A/kPzORlNwdx

INFO: task mysqld:26208 blocked for more than 120 seconds

https://www.shuzhiduo.com/A/gGdX2LgYJ4

Linux Kernel Crash–hung_task_timeout_secs 

http://blog.csdn.net/napolunyishi/article/details/17576739 

How to fix hung_task_timeout_secs and blocked for more than 120 seconds problem 

http://blog.csdn.net/wyzxg/article/details/44236263 

关于修改 sysctl.conf,如何使该文件在系统重启之后生效 

http://blog.csdn.net/u010616985/article/details/44563931 

文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别 

http://blog.sina.com.cn/s/blog_448574810101k1va.html 

一次内核hung task分析 

http://blog.chinaunix.net/uid-14528823-id-4406510.html

Guess you like

Origin blog.csdn.net/michaelwoshi/article/details/119857911