USB 3 写入速度慢

JPW*_*JPW 8 performance io usb-drive

在 Linux 上写入我的 USB 3 拇指驱动器 (SanDisk Extreme SDCZ80-064G-FFP) 非常慢:1 GB 需要超过 200 秒。使用 Windows(在同一台计算机上双启动),可以在大约 8 秒内复制相同的 1 GB 文件。棒是用 FAT 格式化的(它是预先格式化的,我没有改变它),我想保持这种方式,因为我也在 Windows 上使用它,

我该如何解决?我可以执行哪些步骤来诊断导致这种情况的原因?

我正在使用内核版本 4.5.4-1 运行 Manjaro/Arch。

编辑: 首先:当我尝试使用-o big_writes. 对错误表示抱歉!

我正在添加评论中提到的命令的输出。我认为这些都没有问题。

journalctl -f连接驱动器时的输出,安装它并写入一些数据:

Mai 23 20:32:37 manjaro kernel: usb 2-6: USB disconnect, device number 7
Mai 23 20:32:39 manjaro dbus[608]: [system] Activating via systemd: service name='org.freedesktop.Avahi' unit='dbus-org.freedesktop.Avahi.service'
Mai 23 20:32:39 manjaro dbus[608]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.Avahi.service': Unit dbus-org.freedesktop.Avahi.service not found.
Mai 23 20:32:41 manjaro kernel: usb 2-6: new SuperSpeed USB device number 8 using xhci_hcd
Mai 23 20:32:41 manjaro kernel: usb-storage 2-6:1.0: USB Mass Storage device detected
Mai 23 20:32:41 manjaro kernel: scsi host12: usb-storage 2-6:1.0
Mai 23 20:32:41 manjaro mtp-probe[3627]: checking bus 2, device 8: "/sys/devices/pci0000:00/0000:00:14.0/usb2/2-6"
Mai 23 20:32:41 manjaro mtp-probe[3627]: bus: 2, device: 8 was not an MTP device
Mai 23 20:32:42 manjaro kernel: scsi 12:0:0:0: Direct-Access     SanDisk  Extreme          0001 PQ: 0 ANSI: 6
Mai 23 20:32:42 manjaro kernel: sd 12:0:0:0: [sdc] 122544516 512-byte logical blocks: (62.7 GB/58.4 GiB)
Mai 23 20:32:42 manjaro kernel: sd 12:0:0:0: [sdc] Write Protect is off
Mai 23 20:32:42 manjaro kernel: sd 12:0:0:0: [sdc] Mode Sense: 53 00 00 08
Mai 23 20:32:42 manjaro kernel: sd 12:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Mai 23 20:32:42 manjaro kernel:  sdc: sdc1
Mai 23 20:32:42 manjaro kernel: sd 12:0:0:0: [sdc] Attached SCSI removable disk
Mai 23 20:32:43 manjaro dbus[608]: [system] Activating via systemd: service name='org.freedesktop.Avahi' unit='dbus-org.freedesktop.Avahi.service'
Mai 23 20:32:43 manjaro dbus[608]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.Avahi.service': Unit dbus-org.freedesktop.Avahi.service not found.
Mai 23 20:32:52 manjaro sudo[3667]: user : TTY=pts/1 ; PWD=/home/user ; USER=root ; COMMAND=/usr/bin/mount /dev/sdc1 /mnt/
Mai 23 20:32:52 manjaro sudo[3667]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mai 23 20:32:52 manjaro sudo[3667]: pam_unix(sudo:session): session closed for user root
Mai 23 20:33:11 manjaro sudo[3676]: user : TTY=pts/1 ; PWD=/home/user ; USER=root ; COMMAND=/usr/bin/dd bs=1M count=1024 if=/dev/zero of=/mnt/test conv=fdatasync status=progress
Mai 23 20:33:11 manjaro sudo[3676]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mai 23 20:35:01 manjaro anacron[2235]: Job `cron.daily' started
Mai 23 20:35:03 manjaro anacron[2235]: Job `cron.daily' terminated
Mai 23 20:35:45 manjaro sudo[3676]: pam_unix(sudo:session): session closed for user root
Run Code Online (Sandbox Code Playgroud)

的输出dmesg

[ 2507.302345] usb 2-6: new SuperSpeed USB device number 8 using xhci_hcd
[ 2507.317395] usb-storage 2-6:1.0: USB Mass Storage device detected
[ 2507.317758] scsi host12: usb-storage 2-6:1.0
[ 2508.319922] scsi 12:0:0:0: Direct-Access     SanDisk  Extreme          0001 PQ: 0 ANSI: 6
[ 2508.333123] sd 12:0:0:0: [sdc] 122544516 512-byte logical blocks: (62.7 GB/58.4 GiB)
[ 2508.333353] sd 12:0:0:0: [sdc] Write Protect is off
[ 2508.333362] sd 12:0:0:0: [sdc] Mode Sense: 53 00 00 08
[ 2508.333634] sd 12:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 2508.346488]  sdc: sdc1
[ 2508.347918] sd 12:0:0:0: [sdc] Attached SCSI removable disk
Run Code Online (Sandbox Code Playgroud)

用于挂载和写入的命令:

$ sudo mount /dev/sdc1 /mnt/
$ sudo dd bs=1M count=1024 if=/dev/zero of=/mnt/test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1,1 GB, 1,0 GiB) copied, 154,158 s, 7,0 MB/s
Run Code Online (Sandbox Code Playgroud)

的输出lsusb -t

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/10p, 5000M
    |__ Port 6: Dev 8, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
    |__ Port 9: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
    |__ Port 10: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
    |__ Port 10: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
Run Code Online (Sandbox Code Playgroud)

编辑 2:我尝试了另外两个内核:4.4.11 和 4.6.0。他们俩的写作仍然很慢。此外,问题似乎与驱动器有关,因为我为外部 USB 3 硬盘获得了更高的传输速度 (90 MB/s)。

编辑 3:我在 Ubuntu 16.04 Live System 上做了一些基准测试。结果要好得多(虽然仍然不是很好):

ubuntu@ubuntu:/media/ubuntu/274D-D62C$ dd bs=1M count=1024 if=/dev/zero of=./test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 12.2623 s, 87.6 MB/s
ubuntu@ubuntu:/media/ubuntu/274D-D62C$ dd bs=1M count=1024 if=/dev/zero of=./test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 64.5742 s, 16.6 MB/s
ubuntu@ubuntu:/media/ubuntu/274D-D62C$ dd bs=1M count=1024 if=/dev/zero of=./test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 83.6521 s, 12.8 MB/s
ubuntu@ubuntu:/media/ubuntu/274D-D62C$ dd bs=1M count=1024 if=/dev/zero of=./test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 21.842 s, 49.2 MB/s
ubuntu@ubuntu:/media/ubuntu/274D-D62C$ dd bs=1M count=1024 if=/dev/zero of=./test conv=fdatasync status=progress
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 16.3149 s, 65.8 MB/s
Run Code Online (Sandbox Code Playgroud)

编辑 4:我刚刚使用最近的 Arch/Manjaro 内核 (4.11.1) 再次尝试了它,结果要好一些:我的传输速度约为 10 MB/s(对于 1GB 大约为 100s)。但是,这仍然比 Windows 慢得多。

编辑 5:我终于找到时间回到这个问题。运行当前的 Manjaro 内核Linux janmanjaro 5.4.74-1-MANJARO #1 SMP PREEMPT Sun Nov 1 13:43:13 UTC 2020 x86_64 GNU/Linux,我得到 15 - 30 MB/s(通常接近 15 MB/s)。安装sudo mount -o async,flush /dev/sdc1 /mnt/(如在 Linux 中写入 USB FAT32 驱动器时速度极慢中所建议的)将速度提高了大约 5 MB/s。这比 Windows 慢得多,也比 Ubuntu 慢得多。

我也sudo fio --name TEST --eta-newline=5s --filename=test.img --rw=randrw --size=500m --io_size=10g --blocksize=4k --ioengine=libaio --iodepth=1 --direct=1 --numjobs=1 --runtime=60 --group_reportin按照@Mikko Rantalainen 的建议跑步。结果是:

Run status group 0 (all jobs):
   READ: bw=3444KiB/s (3527kB/s), 3444KiB/s-3444KiB/s (3527kB/s-3527kB/s), io=202MiB (212MB), run=60001-60001msec
   WRITE: bw=3432KiB/s (3514kB/s), 3432KiB/s-3432KiB/s (3514kB/s-3514kB/s), io=201MiB (211MB), run=60001-60001msec
Run Code Online (Sandbox Code Playgroud)

我还没有在 Ubuntu 上运行它。

Rem*_*ica 4

由于没有更好的答案,我只是想指出,您的值对于一般闪存驱动器来说非常好,并且完全在您的特定闪存驱动器的预期范围内。

诸如 190MB/s 写入速度之类的营销值一般来说是不可持续的(它们最多有效几秒钟,直到内部缓冲区被填满,并且不反映实际的闪存性能),并且仅适用于顺序写入。一旦涉及文件系统,速度就会大大降低。即使在高级快速 USB 驱动器上,随机访问写入速度通常也小于 1MB/s,因此少量随机写入(如文件系统通常要求的那样)就会破坏写入性能。

您可以尝试使用对闪存更友好的文件系统,例如 f2fs(建议使用 4.4 或更高版本的内核),它在减少随机写入方面做得很好,看看是否有帮助。

  • 您可能会发现 Ubuntu 安装的可移动介质带有主动刷新写入的选项,以避免在未先卸载钥匙而拔出钥匙时丢失数据。请参阅https://superuser.com/questions/970594/extremely-slow-speed-when-writing-to-usb-fat32-drive-in-linux,这似乎是同一个问题。 (3认同)