4

您好,我正在使用 Linux usb 小工具工具来模拟 USB 闪存驱动器。除了性能非常低外,它工作正常。

我使用由 dd 创建的 4Gb 文件,并在其上创建了 ext2 或 vfat(都尝试过)分区。比我使用以下命令序列安装它:

# modprobe dummy_hcd is_super_speed=1 # I tried is_high_speed=1, and no parameter too
# modprobe g_mass_storage file=/home/del/img/flash stall=0 # tried w/o stall=0 too
# mount /dev/sdc1 /mnt/tmp

之后,我在 dmesg 中创建了 /dev/sdc 和 /dev/sdc1 设备,没有任何错误:

[1256700.986581] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256701.022551]  gadget: high-speed config #1: Linux File-Backed Storage
[1256701.242481] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256701.278422]  gadget: high-speed config #1: Linux File-Backed Storage
[1256701.422339]  gadget: high-speed config #1: Linux File-Backed Storage
[1256934.915697] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256934.951628]  gadget: high-speed config #1: Linux File-Backed Storage
[1256935.915155] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256935.951090]  gadget: high-speed config #1: Linux File-Backed Storage
[1256936.095018]  gadget: high-speed config #1: Linux File-Backed Storage
[1317073.396892] usb-storage 3-1:1.0: Quirks match for vid 0525 pid a4a5: 10000
[1317073.396995] scsi53 : usb-storage 3-1:1.0
[1317074.411883] scsi 53:0:0:0: Direct-Access     Linux    File-CD Gadget   0302 PQ: 0 ANSI: 2
[1317074.412669] sd 53:0:0:0: Attached scsi generic sg3 type 0
[1317074.431910] sd 53:0:0:0: [sdc] 8388608 512-byte logical blocks: (4.29 GB/4.00 GiB)
[1317074.443816] sd 53:0:0:0: [sdc] Write Protect is off
[1317074.443821] sd 53:0:0:0: [sdc] Mode Sense: 0f 00 00 00
[1317074.455839] sd 53:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[1317074.551757]  sdc: sdc1
[1317074.683704] sd 53:0:0:0: [sdc] Attached SCSI removable disk

问题是IO性能很差。写入 200Mb 文件需要相当长的时间:

$ ls -lh file
-rw-rw-r-- 1 root del 206M Sep  4 09:34 file
$ time sudo cp file /mnt/tmp/
real    11m59.618s
user    0m0.000s
sys     0m0.260s

大约是 300K/秒。但是,同一系统上的同一文件会在不到一分钟的时间内复制到真正的 USB 闪存中。

Iotop 显示如下内容:

 TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                
 9986 be/4 root        0.00 B/s  262.05 K/s  0.00 % 99.86 % cp file /mnt/tmp/
20651 be/4 root       51.77 K/s  238.95 K/s  0.00 % 93.23 % [file-storage]

可以做些什么来提高 g_mass_storage 模拟 USB 驱动器的性能吗?

PS:我正在使用内核

$ uname -rm
3.2.0-4-686-pae i686
4

1 回答 1

3

同样在这里。

在 6:00 住了一晚后,我找到了解决方案。

modprobe g_mass_storage file=/home/del/img/flash stall=0 buflen=65536

这高达 5MByte/sec

modprobe g_mass_storage file=/home/del/img/flash stall=0 nofua=1

这高达 11MByte/sec

“buflen”和“nofua”的组合并没有真正帮助。关于“nufua”在这里阅读:http://lxr.free-electrons.com/source/drivers/usb/gadget/file_storage.c?v= 3.5

超软/

于 2014-04-19T00:29:21.197 回答