cfq scheduler can write parts of sequential write in reverse order

Bug #1737522 reported by Boris Gjenero
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Expired
Medium
Unassigned

Bug Description

I'm opening a raw disk device (like /dev/sdb) with O_DIRECT and then doing write() calls. The device is actually USB mass storage. Looking at the USB packets with Wireshark, I see that the write() calls are being split into multiple SCSI writes. That part is okay I guess. The problem is that these writes can happen in reverse order. Suppose the write() call is writing to sectors 100 to 200. The first SCSI write may write 150 to 200 and the second SCSI write may write 100 to 149.

Correctness does appear to be maintained. I only had a problem with correctness because I'm abusing the protocol for writing to a hacked digital photo frame via https://github.com/dreamlayers/st220x/blob/master/libst2205/st2205.c . The photo frame doesn't fully process the protocol and only looks at the data as a series of USB packets.

However, this is bad for performance with hard disks. Surely if you have a sequential write, the optimal way to do that write is sequentially from start to finish. Since changing the scheduler for that block device from cfq to noop fixes this problem, I assume it has to do with the elevator algorithm use to optimize hard disk access. But surely such optimization only makes sense between contiguous sequential writes, and not for splitting up one such write.

ProblemType: Bug
DistroRelease: Ubuntu 17.10
Package: linux-image-4.13.0-19-generic 4.13.0-19.22
ProcVersionSignature: Ubuntu 4.13.0-19.22-generic 4.13.13
Uname: Linux 4.13.0-19-generic x86_64
NonfreeKernelModules: nvidia_uvm nvidia
AlsaVersion: Advanced Linux Sound Architecture Driver Version k4.13.0-19-generic.
ApportVersion: 2.20.7-0ubuntu3.6
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: bgjenero 2116 F.... pulseaudio
Card0.Amixer.info:
 Card hw:0 'Intel'/'HDA Intel at 0xfa200000 irq 30'
   Mixer name : 'Realtek ALC889A'
   Components : 'HDA:10ec0885,1458a002,00100101'
   Controls : 63
   Simple ctrls : 26
CurrentDesktop: XFCE
Date: Mon Dec 11 05:23:12 2017
HibernationDevice: RESUME=UUID=a44c3385-e1ba-4456-91ec-be27c892ff11
IwConfig:
 eth0 no wireless extensions.

 lo no wireless extensions.
MachineType: Gigabyte Technology Co., Ltd. P35-DS3R
ProcFB:

ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-4.13.0-19-generic root=UUID=52543c1b-1764-4766-a504-f4b94422fa6e ro
RelatedPackageVersions:
 linux-restricted-modules-4.13.0-19-generic N/A
 linux-backports-modules-4.13.0-19-generic N/A
 linux-firmware 1.169.1
RfKill: Error: [Errno 2] No such file or directory: 'rfkill': 'rfkill'
SourcePackage: linux
UpgradeStatus: Upgraded to artful on 2017-09-30 (71 days ago)
dmi.bios.date: 06/19/2009
dmi.bios.vendor: Award Software International, Inc.
dmi.bios.version: F13
dmi.board.name: P35-DS3R
dmi.board.vendor: Gigabyte Technology Co., Ltd.
dmi.chassis.type: 3
dmi.chassis.vendor: Gigabyte Technology Co., Ltd.
dmi.modalias: dmi:bvnAwardSoftwareInternational,Inc.:bvrF13:bd06/19/2009:svnGigabyteTechnologyCo.,Ltd.:pnP35-DS3R:pvr:rvnGigabyteTechnologyCo.,Ltd.:rnP35-DS3R:rvr:cvnGigabyteTechnologyCo.,Ltd.:ct3:cvr:
dmi.product.name: P35-DS3R
dmi.sys.vendor: Gigabyte Technology Co., Ltd.

Revision history for this message
Boris Gjenero (boris-gjenero) wrote :
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote : Status changed to Confirmed

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Joseph Salisbury (jsalisbury) wrote :

Did this issue start happening after an update/upgrade? Was there a prior kernel version where you were not having this particular problem?

Would it be possible for you to test the latest upstream kernel? Refer to https://wiki.ubuntu.com/KernelMainlineBuilds . Please test the latest v4.15 kernel[0].

If this bug is fixed in the mainline kernel, please add the following tag 'kernel-fixed-upstream'.

If the mainline kernel does not fix this bug, please add the tag: 'kernel-bug-exists-upstream'.

Once testing of the upstream kernel is complete, please mark this bug as "Confirmed".

Thanks in advance.

[0] http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15-rc3

Changed in linux (Ubuntu):
importance: Undecided → Medium
status: Confirmed → Incomplete
tags: added: kernel-da-key
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for linux (Ubuntu) because there has been no activity for 60 days.]

Changed in linux (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.