Bug 2193259

Summary: regression - transient stalls during write-intensive workload
Product: [Fedora] Fedora Reporter: Gabriel Somlo <somlo>
Component: kernelAssignee: fedora-kernel-btrfs
Status: CLOSED WORKSFORME QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 38CC: acaringi, adscvr, airlied, alciregi, bskeggs, bugzilla, fedora, hdegoede, hpa, jarodwilson, josef, kernel-maint, lgoncalv, linville, masami256, mchehab, ptalbert, steved
Target Milestone: ---Keywords: Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
URL: https://paste.centos.org/view/967d1fbb
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-30 13:14:59 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
dmesg output from hypervisor during guest stall
none
output of `lspci -vvnn`
none
debug/block/sda information
none
output of `cat /proc/mounts`
none
output from `echo w > /proc/sysrq-trigger; dmesg` before and after switching from bfq to mq-deadline
none
output from `echo w > /proc/sysrq-trigger; dmesg` after downgrading host kernel to 6.1.18 none

Description Gabriel Somlo 2023-05-04 22:12:28 UTC
installing vivado on a f38 libvirtd guest VM, running on a f38 hypervisor (host) machine, both running 6.2.14-300.fc38.x86_64 kernels, the guest stalls for several seconds at a time during disk writes.

The linked `dmesg` output (https://paste.centos.org/view/967d1fbb) was obtained by running `echo w > /proc/sysrq-trigger; dmesg | fpaste`

Reproducible: Always

Steps to Reproduce:
1. install up-to-date f38 hypervisor (host) running libvirtd
2. install up-to-date f38 guest VM, running write-intensive workload (in my case, I was installing vivado from an 80-gig downloaded tarball)
3. observe guest stalling occasionally (becoming unresponsive while writes get backed up). at that time, run `echo w > /proc/sysrq-trigger; dmesg` to collect similar data to mine
Actual Results:  
guest stalls intermittently during intensive write operations

Expected Results:  
guest stays responsive during intensive write operations

see dmesg output at https://paste.centos.org/view/967d1fbb

Comment 1 Gabriel Somlo 2023-05-04 22:15:39 UTC
Created attachment 1962385 [details]
dmesg output from hypervisor during guest stall

Comment 2 Chris Murphy 2023-05-05 01:32:35 UTC
Gabriel on IRC provided some additional information:

* Two identical hosts, one Fedora 36 (problem does not occur) and Fedora 38 (problem does occur). Fedora 36 host and guest use kernel 6.1.18.
* Hardware raid5, megaraid_sas driver, using bfq and mq-deadline IO schedulers

Gabriel can you run these commands?

sudo lspci -vvnn > lspci.txt

Then attach the file to this bug report. 

Next command you need to be root, e.g. sudo -i. Your terminal program of choice needs configured with a large scrollback as the following command may produce tens of thousands of lines. Copy/paste all lines into a file and attach to this bug report. Have the command ready to go in the remote ssh shell, but only enter it when the hang/stall occurs.

(cd /sys/kernel/debug/block/sda && find . -type f -exec grep -aH . {} \;)

Next, see if you can do some regression testing by switching kernels on the host:

* Fedora 36 host using kernel 6.2.14
* Fedora 38 host using kernel 6.1.18

Let's see if the problem follows the host kernel.

Comment 3 Gabriel Somlo 2023-05-05 11:53:54 UTC
Created attachment 1962539 [details]
output of `lspci -vvnn`

Comment 4 Gabriel Somlo 2023-05-05 12:48:05 UTC
Created attachment 1962546 [details]
debug/block/sda information

output from (cd /sys/kernel/debug/block/sda && find . -type f -exec grep -aH . {} \;)

Comment 5 Gabriel Somlo 2023-05-05 12:50:21 UTC
one other potentially relevant/interesting piece of information:

the hypervisor has 24 cores spread across 2 packages (two 12-core xeon CPUs).

If my guest VM is limited to 12 cores, I'm having a much harder time reproducing the issue, but the behavior is *really* apparent if I allocate 16 cores!

This happens regardless of whether the guest is running f36 or f38 (on the f38 hypervisor).

Comment 6 Chris Murphy 2023-05-12 04:33:00 UTC
Posted * 6.2 series regression, transient stalls during write intensive workloads * to the following upstream lists
https://lore.kernel.org/linux-btrfs/715c18c5-ee46-41e1-a115-203c88335e50@app.fastmail.com/T/#u
https://lore.kernel.org/linux-block/715c18c5-ee46-41e1-a115-203c88335e50@app.fastmail.com/T/#u
https://lore.kernel.org/linux-fsdevel/715c18c5-ee46-41e1-a115-203c88335e50@app.fastmail.com/T/#u
https://lore.kernel.org/linux-raid/715c18c5-ee46-41e1-a115-203c88335e50@app.fastmail.com/T/#u

Gabriel, can you install a 6.1.18 kernel on f38 and see if the problem goes away? I'd like to confirm this is a kernel issue and not a user space issue. 6.1.18 kernel is here, make sure to download the correct arch. You will need kernel, kernel-core, and kernel-modules. Download the RPMs and then in the same dir, run 'dnf install *rpm'. 
https://koji.fedoraproject.org/koji/buildinfo?buildID=2168432

Comment 7 Josef Bacik 2023-05-12 14:13:46 UTC
So mq-deadline still reproduces the problem?  From the sysrq we're just waiting on IO, which means I get to blame the layer below me.  However we could have changed the write patterns so it's exacerbating the problem.  Can I get cat /proc/mounts?  And this stall happens when you're untaring the 80gib tar or when you're downloading it?

Comment 8 Gabriel Somlo 2023-05-12 14:46:10 UTC
Created attachment 1964252 [details]
output of `cat /proc/mounts`

Stalls happen(ed) both during downloading via firefox *and* during untar-ing of the large 80G tar.gz

The problem is (was) intermittent, I've settled into an overall "sluggish" (compared to f36-on-f36) but stable (without seconds-long outright stalls) mode of operation since then.

I'm planning to reboot the hypervisor into the 6.1.18 kernel and downloading/untar-ing the same large file on a fresh guest to try and get an answer to Chris Murphy's suggested test at some point later today (I'm running things on that machine at the moment, and will need to get to a stable state before I can shut everything down).

Thanks all for looking into it!

Comment 9 Gabriel Somlo 2023-05-12 15:19:13 UTC
Created attachment 1964254 [details]
output from `echo w > /proc/sysrq-trigger; dmesg` before and after switching from bfq to mq-deadline

running one vivado and two yosys instances building fpga bitstream on the f38 guest on the f38 hypervisor, both running 6.2.14-300.fc38.x86_64 kernels.

Marked the spot in the log where I switched from `bfq` to `mq-deadline`
(`echo mq-deadline > /sys/block/sda/queue/scheduler`).

Ran `echo w > /proc/sysrq-trigger; dmesg` before and after the switch, got the kernel error output for each time, FWIW.

Will repeat experiment after downgrading hypervisor to 6.1.18.

Comment 10 Gabriel Somlo 2023-05-12 17:30:20 UTC
Created attachment 1964267 [details]
output from `echo w > /proc/sysrq-trigger; dmesg` after downgrading host kernel to 6.1.18

After downgrading the host/hypervisor kernel to 6.1.18, I re-ran the vivado+yosys+yosys bitstream compilation experiment.

The attached log shows the error I got while using `bfq` scheduling in `/sys/block/sda/queue/scheduler`.

After switching to mq-deadline, I could no longer trigger the error -- this is the one and only significant difference from before (when I was running kernel 6.2.14).

Comment 11 Gabriel Somlo 2023-05-12 18:19:18 UTC
I spoke too soon. With 6.1.18, I got the following *after* switching to mq-deadline:

[ 2756.132977] sysrq: Show Blocked State
[ 2756.133409] task:kworker/u48:5   state:D stack:0     pid:3613  ppid:2      flags:0x00004000
[ 2756.133419] Workqueue: writeback wb_workfn (flush-btrfs-1)
[ 2756.133432] Call Trace:
[ 2756.133435]  <TASK>
[ 2756.133441]  __schedule+0x35f/0x1360
[ 2756.133454]  ? rwb_trace_step+0x90/0x90
[ 2756.133465]  ? rwb_trace_step+0x90/0x90
[ 2756.133471]  ? wbt_done+0xc0/0xc0
[ 2756.133477]  schedule+0x5d/0xe0
[ 2756.133483]  io_schedule+0x42/0x70
[ 2756.133489]  rq_qos_wait+0xae/0x120
[ 2756.133496]  ? efi_partition+0x800/0x800
[ 2756.133502]  ? rwb_trace_step+0x90/0x90
[ 2756.133508]  wbt_wait+0x7a/0xc0
[ 2756.133515]  __rq_qos_throttle+0x23/0x40
[ 2756.133520]  blk_mq_submit_bio+0x2a5/0x5d0
[ 2756.133529]  __submit_bio+0xf5/0x180
[ 2756.133537]  submit_bio_noacct_nocheck+0x318/0x360
[ 2756.133543]  btrfs_submit_bio+0x228/0x240
[ 2756.133554]  submit_one_bio+0x71/0xc0
[ 2756.133559]  submit_extent_page+0x14f/0x510
[ 2756.133566]  ? page_vma_mkclean_one.constprop.0+0x1c0/0x1c0
[ 2756.133575]  ? __traceiter_remove_migration_pte+0x50/0x50
[ 2756.133580]  __extent_writepage_io.constprop.0+0x273/0x540
[ 2756.133588]  __extent_writepage+0x114/0x410
[ 2756.133594]  extent_write_cache_pages+0x14d/0x4e0
[ 2756.133603]  extent_writepages+0x6b/0x120
[ 2756.133609]  ? end_extent_writepage+0x100/0x100
[ 2756.133613]  do_writepages+0xb0/0x1b0
[ 2756.133624]  ? sched_clock_cpu+0xb/0xc0
[ 2756.133634]  __writeback_single_inode+0x3d/0x360
[ 2756.133640]  ? _raw_spin_lock+0x13/0x40
[ 2756.133647]  writeback_sb_inodes+0x1c5/0x470
[ 2756.133656]  __writeback_inodes_wb+0x4c/0xf0
[ 2756.133662]  wb_writeback+0x1f6/0x2d0
[ 2756.133669]  wb_workfn+0x32c/0x4a0
[ 2756.133677]  process_one_work+0x1c7/0x380
[ 2756.133684]  worker_thread+0x4d/0x380
[ 2756.133688]  ? _raw_spin_lock_irqsave+0x23/0x50
[ 2756.133694]  ? rescuer_thread+0x380/0x380
[ 2756.133697]  kthread+0xe9/0x110
[ 2756.133705]  ? kthread_complete_and_exit+0x20/0x20
[ 2756.133711]  ret_from_fork+0x22/0x30
[ 2756.133723]  </TASK>

Comment 12 Thorsten Leemhuis 2023-05-16 11:46:38 UTC
Not my area of expertise, but I wonder if this is https://bugzilla.kernel.org/show_bug.cgi?id=216961 all over again, which was never really solved (or do you disagree Chris?). From the looks of it switching away from BFQ helped there as well, but apparently at least for the reporter also didn't solve the problem completely. And FWIW, in that bug report there were indicators that 5.19.y was fine (but it was never rally verified). I thus wonder if it might be worth giving 5.19 a try, as I fear without a bisection we'll never get down to the cause, as Chris recent report to the lists (which brought me here) was met with silence.

Comment 13 Chris Murphy 2023-05-16 16:21:41 UTC
tl;dr: I'll work with Gabriel on finding last known good (possibly 5.19.0) and first known bad (possibly 6.0) and re-attempt to git bisect that, if he's willing.

I'm not sure about https://bugzilla.kernel.org/show_bug.cgi?id=216961 but bug 2193259 (this bug) strikes me as similar to bug 2009585. The gist there is kernel 5.19 works ok with mq-deadline but not bfq. And then kernel 6.0 works with neither bfq nor mq-deadline. And it doesn't matter what the file system is. The commonality is megaraid sas. So I'm suspicious the problem is buried somewhere in SCSI or SAS.

My previous attempt to bisect the kernel for bug 2009585 involved kernel 5.11 and 5.12, and that was a clusterfuck. I got to a point where git bisect produced kernels that wouldn't boot. I once skipped 20 times in a row and none of them would boot. There was no evidence I'd ever make progress so I gave up.

Comment 14 Gabriel Somlo 2023-05-25 15:56:04 UTC
After upgrading both host and guest machines to 6.2.15-300.fc38.x86_64, I can no longer reproduce the stalls (things *do* get slow when I have lots of disk write activity (both inside the guests and directly on the host), but nothing "freezes" or "locks up" anymore like it used to earlier on.

Not sure it's worth bisecting anything any longer, planning to close this with NOTABUG or CURRENTRELEASE or WORKSFORME, whichever may be appropriate here, unless anyone else advises otherwise...