看Linux内核前辈解Bug你会有什么感想

系统 Linux
正是只凭借这些debug信息,准确分析问题所在,才能体现出对block子系统的专业性,坐稳在这个子系统中的地位。如此熟练掌握一个子系统,真不易!

[[355896]]

本文转载自微信公众号「相遇Linux」,作者JeffXie。转载本文请联系相遇Linux公众号。

一名叫John Garry的人给Linux内核社区上报了一个bug, 说有人升级内核到V5.10-rcX之后,执行dd和sync之后看到进程有hang住的情况:

 

  1. Some guys internally upgraded to v5.10-rcX and start to see a hang after  
  2. dd + sync for a large file: 
  3. - mount /dev/sda1 (ext4 filesystem) to directory /mnt; 
  4. - run "if=/dev/zero of=test1 bs=1M count=2000" on directory /mnt; 
  5. - run "sync" 

系统提示打印hang住进程的堆栈信息:

 

  1. and get: 
  2.  
  3. [  367.912761] INFO: task jbd2/sdb1-8:3602 blocked for more than 120 
  4. seconds. 
  5. [  367.919618]       Not tainted 5.10.0-rc1-109488-g32ded76956b6 #948 
  6. [  367.925776] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" 
  7. disables this message. 
  8. [  367.933579] task:jbd2/sdb1-8     state:D stack:    0 pid: 3602 
  9. ppid:     2 flags:0x00000028 
  10. [  367.941901] Call trace: 
  11. [  367.944351] __switch_to+0xb8/0x168 
  12. [  367.947840] __schedule+0x30c/0x670 
  13. [  367.951326] schedule+0x70/0x108 
  14. [  367.954550] io_schedule+0x1c/0xe8 
  15. [  367.957948] bit_wait_io+0x18/0x68 
  16. [  367.961346] __wait_on_bit+0x78/0xf0 
  17. [  367.964919] out_of_line_wait_on_bit+0x8c/0xb0 
  18. [  367.969356] __wait_on_buffer+0x30/0x40 
  19. [  367.973188] jbd2_journal_commit_transaction+0x1370/0x1958 
  20. [  367.978661] kjournald2+0xcc/0x260 
  21. [  367.982061] kthread+0x150/0x158 
  22. [  367.985288] ret_from_fork+0x10/0x34 
  23. [  367.988860] INFO: task sync:3823 blocked for more than 120 seconds. 
  24. [  367.995102]       Not tainted 5.10.0-rc1-109488-g32ded76956b6 #948 
  25. [  368.001265] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" 
  26. disables this message. 
  27. [  368.009067] task:sync            state:D stack:    0 pid: 3823 ppid: 
  28. 3450 flags:0x00000009 
  29. [  368.017397] Call trace: 
  30. [  368.019841] __switch_to+0xb8/0x168 
  31. [  368.023320] __schedule+0x30c/0x670 
  32. [  368.026804] schedule+0x70/0x108 
  33. [  368.030025] jbd2_log_wait_commit+0xbc/0x158 
  34. [  368.034290] ext4_sync_fs+0x188/0x1c8 
  35. [  368.037947] sync_fs_one_sb+0x30/0x40 
  36. [  368.041606] iterate_supers+0x9c/0x138 
  37. [  368.045350] ksys_sync+0x64/0xc0 
  38. [  368.048569] __arm64_sys_sync+0x10/0x20 
  39. [  368.052398] el0_svc_common.constprop.3+0x68/0x170 
  40. [  368.057177] do_el0_svc+0x24/0x90 
  41. [  368.060482] el0_sync_handler+0x118/0x168 
  42. [  368.064478]  el0_sync+0x158/0x180 

并反馈8号硬队列绑定的第100号cpu上派发队列和完成队列不一致,但是没有inflight的情况,因为这个情况,苦恼了三天三夜,头发掉满了整个键盘。

 

  1. estuary:/sys/kernel/debug/block/sda/hctx8$ cat cpu100/dispatched 
  2. 3 0 
  3. estuary:/sys/kernel/debug/block/sda/hctx8$ cat cpu100/completed 
  4. 2 0 
  5. On cpu100, it seems completed is less than number dispatched. 
  6. /sys/devices/pci0000:74/0000:74:02.0/host0/port-0:0/end_device-0:0/target0:0:0/0:0:0:0/block/sda/sda1/inflight),  
  7. the number of inflight is 0. 

然后Ming Lei (自带音响出场)给出意见,需要收集/sys/kernel/debug/block/sda 目录和/sys/block/sda/device 目录下所有文件的输出:

 

  1. hello chenxiang, Can you collect the debugfs log via the following commands after the io 
  2. hang is triggered? 
  3.  
  4. 1) debugfs log: 
  5.  
  6.         (cd /sys/kernel/debug/block/sda && find . -type f -exec grep -aH . {} \;) 
  7.  
  8. 2) scsi sysfs info: 
  9.  
  10.         (cd /sys/block/sda/device && find . -type f -exec grep -aH . {} \;) 
  11.  
  12. Suppose the disk is /dev/sda. 

chenxiang 反馈:

 

  1. ~$ cd /sys/kernel/debug/block/sdb && find . -type f -exec grep  
  2. -aH . {} \; 
  3. ... 
  4. ./hctx9/tags:cleared=3891 
  5. ./hctx9/tags:bits_per_word=64 
  6. ./hctx9/tags:map_nr=63 
  7. ./hctx9/tags:alloc_hint={3264, 3265, 0, 3731, 2462, 842, 0, 0, 1278, 27,  
  8. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2424, 0, 0, 0,  
  9. 346, 3, 3191, 235, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  
  10. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 285, 0, 0, 0, 0, 0, 0, 0, 0, 0,  
  11. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1165, 538, 0,  
  12. 372, 277, 3476, 0, 0, 0, 111, 0, 2081, 0, 112, 0, 0, 0, 0, 904, 1127, 0,  
  13. 0, 0, 113, 0, 0, 0, 0, 0, 0, 321, 0} 
  14. ./hctx9/tags:wake_batch=8 
  15. ./hctx9/tags:wake_index=7 
  16. ./hctx9/tags:ws_active=0 
  17. ./hctx9/tags:ws={ 
  18. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  19. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  20. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  21. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  22. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  23. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  24. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  25. ./hctx9/tags:   {.wait_cnt=8, .wait=inactive}, 
  26. ./hctx9/tags:} 
  27. ./hctx9/tags:round_robin=1 
  28. ./hctx9/tags:min_shallow_depth=4294967295 
  29. ./hctx9/ctx_map:00000000: 00 
  30. ... 

Ming Lei 大神看了一下debug输出,小喝一杯大红袍,就直接建议去测试这个patch:

 

  1. Please try the following patch: 
  2.  
  3. diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c 
  4. index 60c7a7d74852..03c6d0620bfd 100644 
  5. --- a/drivers/scsi/scsi_lib.c 
  6. +++ b/drivers/scsi/scsi_lib.c 
  7. @@ -1703,8 +1703,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, 
  8.          break; 
  9.      case BLK_STS_RESOURCE: 
  10.      case BLK_STS_ZONE_RESOURCE: 
  11. -        if (atomic_read(&sdev->device_busy) || 
  12. -            scsi_device_blocked(sdev)) 
  13. +        if (scsi_device_blocked(sdev)) 
  14.              ret = BLK_STS_DEV_RESOURCE; 
  15.          break; 
  16.      default

chenxiang 测试反馈之后,问题解决,内心洋溢着Linux从业者单纯的喜悦,眼神中流露出满满的崇敬之情,恨不得以身相许:

 

  1. I have tested the patch  100+ times on two envirments(on which the issue  
  2. occurs frequently before), and 
  3. the issue doesn't occur. 

这样问题就解决了,我想如果是小编处理这个问题,我会要他触发一下crash,然后再慢慢分析,真是low了几百个 levels :)

正是只凭借这些debug信息,准确分析问题所在,才能体现出对block子系统的专业性,坐稳在这个子系统中的地位。

如此熟练掌握一个子系统,真不易!

 

责任编辑:武晓燕 来源: 相遇Linux
相关推荐

2020-06-08 09:11:47

Linux 内核Linux内核

2010-09-26 10:10:10

Linux内核

2022-08-01 11:32:57

Linux内核版本

2021-03-01 08:16:44

Linux 内核代码

2021-02-25 09:50:01

LinuxWindows内核

2014-05-13 15:00:59

2020-02-07 18:32:36

LinuxLinux内核5.6操作系统

2020-10-22 07:09:19

TCP网络协议

2009-12-17 15:18:47

2021-03-11 14:28:11

bugLinux内核

2021-03-18 09:52:05

bugLinux内核

2011-08-08 09:53:24

UbuntuLinux内核

2017-01-16 15:20:03

Linux内核Oops

2009-08-18 11:01:51

2016-01-05 11:38:59

Linux内核运行

2015-09-11 15:56:52

内核构建Linux

2020-01-17 19:10:32

Linux发行版内核

2021-06-26 07:04:24

Epoll服务器机制

2012-05-03 08:34:15

LinuxKconfig

2016-09-20 15:21:35

LinuxInnoDBMysql
点赞
收藏

51CTO技术栈公众号