Skip to contentSkip to conversation

Zone write plugging and the queue full condition

DISCUSSION Bart Van Assche 3 participants 4 messages Nov 23, 2024 – Nov 25, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

Hi Damien,

If I run the following shell commands:

modprobe -r scsi_debug
modprobe scsi_debug delay=0 dev_size_mb=256 every_nth=2 max_queue=1 \
opts=0x8000 sector_size=4096 zbc=host-managed zone_nr_conv=0
zone_size_mb=4
while true; do

    bdev=$(cd 
/sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block && echo *) 2>/dev/null
    if [ -e /dev/"${bdev}" ]; then break; fi
    sleep .1
done
dev=/dev/"${bdev}"
[ -b "${dev}" ]
fio --direct=1 --filename=$dev --iodepth=1 --ioengine=io_uring \
    --ioscheduler=none --gtod_reduce=1 --hipri=0 --name="$(basename 
"${dev}")" \
    --runtime=30 --rw=rw --time_based=1 --zonemode=zbd &

sleep 2
echo w > /proc/sysrq-trigger

then the following appears in the kernel log:

sysrq: Show Blocked State
task:(udev-worker) state:D stack:0 pid:3121 tgid:3121
ppid:2191 fl
ags:0x00000006

    Call Trace:
     <TASK>
     __schedule+0x3e8/0x1410
     schedule+0x27/0xf0
     blk_mq_freeze_queue_wait+0x6f/0xa0
     queue_attr_store+0x60/0xc0
     kernfs_fop_write_iter+0x13e/0x1f0
     vfs_write+0x25b/0x420
     ksys_write+0x65/0xe0
     do_syscall_64+0x82/0x160
     entry_SYSCALL_64_after_hwframe+0x76/0x7e

Do you agree that the above indicates that blk_mq_freeze_queue_wait() hangs? I think it is waiting for a q_usage_counter reference that is held by a bio on a zwplug->bio_list.

Do you agree that the best way to solve this is to modify blk_mq_submit_bio() by moving the blk_zone_plug_bio() call after the blk_crypto_rq_get_keyslot() call and also to change the zwplug bio list into a request list?

If you agree with the above, do you want to implement these changes or do you perhaps prefer that I implement these changes myself?

Thanks,

Bart.

#1 lore raw
Quoted 4 lines · Bart Van Assche

Hi Damien,

If I run the following shell commands:

Quoted 9 lines

modprobe -r scsi_debug
modprobe scsi_debug delay=0 dev_size_mb=256 every_nth=2 max_queue=1 \
  opts=0x8000 sector_size=4096 zbc=host-managed zone_nr_conv=0 zone_size_mb=4 while true; do
    bdev=$(cd /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block && echo *) 2>/dev/null
    if [ -e /dev/"${bdev}" ]; then break; fi
    sleep .1
done

Running this script, I never get out of this loop... Weird. I changed the script to this:

...
while true; do

	bdev="$(lsscsi -g | grep scsi_debug | cut -d'/' -f3)"
	if [ ! -z "${bdev}" ]; then
		break;
       	fi
	sleep .1

done
dev="/dev/${bdev}"
[ -b "${dev}" ]
...

and then it runs, but I do not see anything blocked. All is fine. Could you share your kernel config to see what I am missing may be ?

Quoted 25 lines

dev=/dev/"${bdev}"
[ -b "${dev}" ]
fio --direct=1 --filename=$dev --iodepth=1 --ioengine=io_uring \
    --ioscheduler=none --gtod_reduce=1 --hipri=0 --name="$(basename "${dev}")" \
    --runtime=30 --rw=rw --time_based=1 --zonemode=zbd &
sleep 2
echo w > /proc/sysrq-trigger

then the following appears in the kernel log:

    sysrq: Show Blocked State
    task:(udev-worker)   state:D stack:0     pid:3121  tgid:3121 ppid:2191   fl ags:0x00000006

    Call Trace:
     <TASK>
     __schedule+0x3e8/0x1410
     schedule+0x27/0xf0
     blk_mq_freeze_queue_wait+0x6f/0xa0
     queue_attr_store+0x60/0xc0
     kernfs_fop_write_iter+0x13e/0x1f0
     vfs_write+0x25b/0x420
     ksys_write+0x65/0xe0
     do_syscall_64+0x82/0x160
     entry_SYSCALL_64_after_hwframe+0x76/0x7e
Quoted 8 lines

Do you agree that the above indicates that blk_mq_freeze_queue_wait() hangs? I think it is waiting for a q_usage_counter reference that is held by a bio on a zwplug->bio_list.

Do you agree that the best way to solve this is to modify blk_mq_submit_bio() by moving the blk_zone_plug_bio() call after the blk_crypto_rq_get_keyslot() call and also to change the zwplug bio list into a request list?

I am not following... blk_zone_plug_bio() acts on BIOs, not on requests, but blk_crypto_rq_get_keyslot() is a request operation. Also, a requeue list is a list of requests, not BIOs. One of the main point of zone write plugs is to operate on BIOs so that:
1) we have code that is common for regular block devices and for BIO based device-mapper devices.
2) Blocking writes to preserve per-zone write ordering does not result in device resources (TAGS !) being held for nothing and potentially delaying/starving read accesses or other operations that do not need ordering.

How can a requeue list help ? Please provide details.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw
In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche

Hi Damien,

If I run the following shell commands:

Quoted 16 lines

modprobe -r scsi_debug
modprobe scsi_debug delay=0 dev_size_mb=256 every_nth=2 max_queue=1 \
  opts=0x8000 sector_size=4096 zbc=host-managed zone_nr_conv=0 zone_size_mb=4 while true; do
    bdev=$(cd /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block && echo *) 2>/dev/null
    if [ -e /dev/"${bdev}" ]; then break; fi
    sleep .1
done
dev=/dev/"${bdev}"
[ -b "${dev}" ]
fio --direct=1 --filename=$dev --iodepth=1 --ioengine=io_uring \
    --ioscheduler=none --gtod_reduce=1 --hipri=0 --name="$(basename "${dev}")" \
    --runtime=30 --rw=rw --time_based=1 --zonemode=zbd &
sleep 2
echo w > /proc/sysrq-trigger

Another thing, probably unrelated. Running the above script with Linus current tree, when killing fio, I got this:

[ 2302.022055] ------------[ cut here ]------------
[ 2302.028312] WARNING: CPU: 2 PID: 252 at io_uring/io_uring.c:2889
io_ring_exit_work+0x160/0x4d6
[ 2302.038566] Modules linked in: scsi_debug rpcsec_gss_krb5 auth_rpcgss nfsv4

dns_resolver nfs lockd grace netfs nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set nf_tables sunrpc intel_rapl_common intel_uncore_frequency intel_uncore_frequency_common nls_ascii vfat fat x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm rapl intel_cstate iTCO_wdt iTCO_vendor_support btrfs ipmi_ssif intel_uncore lpc_ich igb mfd_core i2c_i801 ioatdma xor intel_pch_thermal dca ipmi_si ipmi_devintf ipmi_msghandler acpi_power_meter raid6_pq zstd_decompress zstd_compress zstd_common mq_deadline bfq loop dm_mod nfnetlink sd_mod usbhid crct10dif_pclmul crc32_pclmul crc32c_intel ast ghash_clmulni_intel drm_client_lib i2c_algo_bit ahci sha512_ssse3 mpt3sas sha256_ssse3 smartpqi raid_class drm_shmem_helper libahci xhci_pci xhci_hcd sha1_ssse3 scsi_transport_sas drm_kms_helper nvme libata usbcore usb_common sg

[ 2302.038813]  scsi_mod scsi_common pkcs8_key_parser fuse [last unloaded:
scsi_debug]
[ 2302.140759] CPU: 2 UID: 0 PID: 252 Comm: kworker/u64:5 Not tainted 6.12.0+ #2107
[ 2302.148854] Hardware name: Supermicro Super Server/X11SPL-F, BIOS 3.8a
10/28/2022
[ 2302.157033] Workqueue: iou_exit io_ring_exit_work
[ 2302.162466] RIP: 0010:io_ring_exit_work+0x160/0x4d6
[ 2302.168044] Code: ff 4c 89 ff e8 c1 45 a1 ff 4c 89 e7 e8 e9 f5 ff ff 31 ff
48 89 bd 40 ff ff ff 48 8b 05 19 3f 9c 00 48 39 85 38 ff ff ff 79 08 <0f> 0b 41
bd 60 ea 00 00 48 8d 7b 58 4c 89 ee e8 2c 97 03 00 48 85
[ 2302.187537] RSP: 0018:ffff9c1d8335fd50 EFLAGS: 00010287
[ 2302.193510] RAX: 00000001001e8356 RBX: ffff8ef8ccd3a658 RCX: 0000000000000000
[ 2302.201389] RDX: 0000000000000000 RSI: ffffffffa4c482d7 RDI: 0000000000000000
[ 2302.209266] RBP: ffff9c1d8335fe20 R08: 0000000000000000 R09: 0000000000000000
[ 2302.217139] R10: 0000000000000000 R11: 00000000004debf3 R12: ffff8ef8ccd3a000
[ 2302.225008] R13: 0000000000000032 R14: ffff8ef8ccd3a040 R15: 0000000000000000
[ 2302.232878] FS:  0000000000000000(0000) GS:ffff8f07c0e80000(0000)
knlGS:0000000000000000
[ 2302.241711] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 2302.248202] CR2: 00002241ff81a000 CR3: 0000000c35637006 CR4: 00000000007726f0
[ 2302.256083] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 2302.263968] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 2302.271834] PKRU: 55555554
[ 2302.275280] Call Trace:
[ 2302.278465]  <TASK>
[ 2302.281294]  ? __warn.cold+0xb7/0x156
[ 2302.285679]  ? io_ring_exit_work+0x160/0x4d6
[ 2302.290749]  ? report_bug+0xfb/0x140
[ 2302.295064]  ? handle_bug+0x4f/0x90
[ 2302.299280]  ? exc_invalid_op+0x17/0x60
[ 2302.303827]  ? asm_exc_invalid_op+0x1a/0x20
[ 2302.308729]  ? io_ring_exit_work+0x147/0x4d6
[ 2302.313709]  ? io_ring_exit_work+0x160/0x4d6
[ 2302.318691]  ? lock_release+0x1fa/0x290
[ 2302.323239]  ? lock_release+0x1fa/0x290
[ 2302.327766]  ? process_one_work+0x21f/0x5a0
[ 2302.332649]  ? process_one_work+0x1f9/0x5a0
[ 2302.337532]  process_one_work+0x21f/0x5a0
[ 2302.342246]  worker_thread+0x1dc/0x3c0
[ 2302.346690]  ? rescuer_thread+0x480/0x480
[ 2302.351382]  kthread+0xe0/0x110
[ 2302.355220]  ? kthread_insert_work_sanity_check+0x60/0x60
[ 2302.361303]  ret_from_fork+0x31/0x50
[ 2302.365553]  ? kthread_insert_work_sanity_check+0x60/0x60
[ 2302.371623]  ret_from_fork_asm+0x11/0x20
[ 2302.376227]  </TASK>
[ 2302.379085] irq event stamp: 9210
[ 2302.383074] hardirqs last  enabled at (9209): [<ffffffffa4c8af28>]
_raw_spin_unlock_irq+0x28/0x40
[ 2302.392619] hardirqs last disabled at (9210): [<ffffffffa4c8052e>]
__schedule+0xede/0x1700
[ 2302.401558] softirqs last  enabled at (9172): [<ffffffffa40a1027>]
__irq_exit_rcu+0xc7/0xf0
[ 2302.410573] softirqs last disabled at (9131): [<ffffffffa40a1027>]
__irq_exit_rcu+0xc7/0xf0
[ 2302.419587] ---[ end trace 0000000000000000 ]---

Did you see anything similar ?

Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw
In reply to Damien Le Moal
Quoted 2 lines · Damien Le Moal

and then it runs, but I do not see anything blocked. All is fine. Could you share your kernel config to see what I am missing may be ?

The different results are probably because of a udev rule that is present on my setup (coming from the Linux distributor). Can you please verify whether test zbd/012 triggers a hang on your test setup? In that test a variant of the udev rule has been converted into a background process. On my test setup (x86 VM) test zbd/012 passes with kernel v6.9 and hangs with Jens' for-next branch (commit 7eb75c9e3b24 ("Merge branch 'for-6.13/block' into for-next")).

See also https://lore.kernel.org/linux-block/[email protected]/

Thanks,

Bart.