Skip to main content
Ask for more context re internals of usb drives.
Source Link
Daniel Näslund
  • 1.9k
  • 1
  • 17
  • 19

I'm writing an initramfs-script and want to detect usb-sticks as fast as possible.

When I insert an usb 2.0 stick, the detection of idVendor, idProduct and USB class happens within 100 ms. But the scsi subsystem does not "attach" until about 1 s has passed and it takes another 500 ms before the partition is fully recognized.

I assume that the driver needs to read the partition table in order to detect partitions. Why does it take so long? I don't expect the urb send/recev time to be that long or the access time of the flash to take so much time.

I've tried 5 sticks from different vendors and the result is about the same.

[ 5731.097540] usb 2-1.2: new high-speed USB device number 7 using ehci-pci [ 5731.195360] usb 2-1.2: New USB device found, idVendor=0951, idProduct=1643 [ 5731.195368] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 5731.195372] usb 2-1.2: Product: DataTraveler G3 [ 5731.195376] usb 2-1.2: Manufacturer: Kingston [ 5731.195379] usb 2-1.2: SerialNumber: 001CC0EC32BCBBB04712022C [ 5731.196942] usb-storage 2-1.2:1.0: USB Mass Storage device detected [ 5731.197193] scsi host9: usb-storage 2-1.2:1.0 [ 5732.268389] scsi 9:0:0:0: Direct-Access Kingston DataTraveler G3 PMAP PQ: 0 ANSI: 0 CCS [ 5732.268995] sd 9:0:0:0: Attached scsi generic sg2 type 0 [ 5732.883939] sd 9:0:0:0: [sdb] 7595520 512-byte logical blocks: (3.88 GB/3.62 GiB) [ 5732.884565] sd 9:0:0:0: [sdb] Write Protect is off [ 5732.884568] sd 9:0:0:0: [sdb] Mode Sense: 23 00 00 00 [ 5732.885178] sd 9:0:0:0: [sdb] No Caching mode page found [ 5732.885181] sd 9:0:0:0: [sdb] Assuming drive cache: write through [ 5732.903834] sdb: sdb1 [ 5732.906812] sd 9:0:0:0: [sdb] Attached SCSI removable disk 

Edit So I've found the delay_use module parameter that by default is set to 1 second, which explains the delay I'm seeing. But I'm wondering if someone can provide context as to why that parameter is needed? A comment suggested that for older usb sticks, delay_use might need to be set to as much as 5 seconds. What is it inside the usb stick that takes so much time; firmware initialization; reads from the flash? I find it hard to belive that we need delays as long as 1 second or more when the latency for accessing flash is in the order of tens of microseconds.

I realize that this might be slightly off-topic for this channel, if so, I'll go to electronics.stackexchange.com

I'm writing an initramfs-script and want to detect usb-sticks as fast as possible.

When I insert an usb 2.0 stick, the detection of idVendor, idProduct and USB class happens within 100 ms. But the scsi subsystem does not "attach" until about 1 s has passed and it takes another 500 ms before the partition is fully recognized.

I assume that the driver needs to read the partition table in order to detect partitions. Why does it take so long? I don't expect the urb send/recev time to be that long or the access time of the flash to take so much time.

I've tried 5 sticks from different vendors and the result is about the same.

[ 5731.097540] usb 2-1.2: new high-speed USB device number 7 using ehci-pci [ 5731.195360] usb 2-1.2: New USB device found, idVendor=0951, idProduct=1643 [ 5731.195368] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 5731.195372] usb 2-1.2: Product: DataTraveler G3 [ 5731.195376] usb 2-1.2: Manufacturer: Kingston [ 5731.195379] usb 2-1.2: SerialNumber: 001CC0EC32BCBBB04712022C [ 5731.196942] usb-storage 2-1.2:1.0: USB Mass Storage device detected [ 5731.197193] scsi host9: usb-storage 2-1.2:1.0 [ 5732.268389] scsi 9:0:0:0: Direct-Access Kingston DataTraveler G3 PMAP PQ: 0 ANSI: 0 CCS [ 5732.268995] sd 9:0:0:0: Attached scsi generic sg2 type 0 [ 5732.883939] sd 9:0:0:0: [sdb] 7595520 512-byte logical blocks: (3.88 GB/3.62 GiB) [ 5732.884565] sd 9:0:0:0: [sdb] Write Protect is off [ 5732.884568] sd 9:0:0:0: [sdb] Mode Sense: 23 00 00 00 [ 5732.885178] sd 9:0:0:0: [sdb] No Caching mode page found [ 5732.885181] sd 9:0:0:0: [sdb] Assuming drive cache: write through [ 5732.903834] sdb: sdb1 [ 5732.906812] sd 9:0:0:0: [sdb] Attached SCSI removable disk 

I'm writing an initramfs-script and want to detect usb-sticks as fast as possible.

When I insert an usb 2.0 stick, the detection of idVendor, idProduct and USB class happens within 100 ms. But the scsi subsystem does not "attach" until about 1 s has passed and it takes another 500 ms before the partition is fully recognized.

I assume that the driver needs to read the partition table in order to detect partitions. Why does it take so long? I don't expect the urb send/recev time to be that long or the access time of the flash to take so much time.

I've tried 5 sticks from different vendors and the result is about the same.

[ 5731.097540] usb 2-1.2: new high-speed USB device number 7 using ehci-pci [ 5731.195360] usb 2-1.2: New USB device found, idVendor=0951, idProduct=1643 [ 5731.195368] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 5731.195372] usb 2-1.2: Product: DataTraveler G3 [ 5731.195376] usb 2-1.2: Manufacturer: Kingston [ 5731.195379] usb 2-1.2: SerialNumber: 001CC0EC32BCBBB04712022C [ 5731.196942] usb-storage 2-1.2:1.0: USB Mass Storage device detected [ 5731.197193] scsi host9: usb-storage 2-1.2:1.0 [ 5732.268389] scsi 9:0:0:0: Direct-Access Kingston DataTraveler G3 PMAP PQ: 0 ANSI: 0 CCS [ 5732.268995] sd 9:0:0:0: Attached scsi generic sg2 type 0 [ 5732.883939] sd 9:0:0:0: [sdb] 7595520 512-byte logical blocks: (3.88 GB/3.62 GiB) [ 5732.884565] sd 9:0:0:0: [sdb] Write Protect is off [ 5732.884568] sd 9:0:0:0: [sdb] Mode Sense: 23 00 00 00 [ 5732.885178] sd 9:0:0:0: [sdb] No Caching mode page found [ 5732.885181] sd 9:0:0:0: [sdb] Assuming drive cache: write through [ 5732.903834] sdb: sdb1 [ 5732.906812] sd 9:0:0:0: [sdb] Attached SCSI removable disk 

Edit So I've found the delay_use module parameter that by default is set to 1 second, which explains the delay I'm seeing. But I'm wondering if someone can provide context as to why that parameter is needed? A comment suggested that for older usb sticks, delay_use might need to be set to as much as 5 seconds. What is it inside the usb stick that takes so much time; firmware initialization; reads from the flash? I find it hard to belive that we need delays as long as 1 second or more when the latency for accessing flash is in the order of tens of microseconds.

I realize that this might be slightly off-topic for this channel, if so, I'll go to electronics.stackexchange.com

edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Tweeted twitter.com/StackUnix/status/702483811385352193
Source Link
Daniel Näslund
  • 1.9k
  • 1
  • 17
  • 19

Why does it take so long to detect an usb stick?

I'm writing an initramfs-script and want to detect usb-sticks as fast as possible.

When I insert an usb 2.0 stick, the detection of idVendor, idProduct and USB class happens within 100 ms. But the scsi subsystem does not "attach" until about 1 s has passed and it takes another 500 ms before the partition is fully recognized.

I assume that the driver needs to read the partition table in order to detect partitions. Why does it take so long? I don't expect the urb send/recev time to be that long or the access time of the flash to take so much time.

I've tried 5 sticks from different vendors and the result is about the same.

[ 5731.097540] usb 2-1.2: new high-speed USB device number 7 using ehci-pci [ 5731.195360] usb 2-1.2: New USB device found, idVendor=0951, idProduct=1643 [ 5731.195368] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 5731.195372] usb 2-1.2: Product: DataTraveler G3 [ 5731.195376] usb 2-1.2: Manufacturer: Kingston [ 5731.195379] usb 2-1.2: SerialNumber: 001CC0EC32BCBBB04712022C [ 5731.196942] usb-storage 2-1.2:1.0: USB Mass Storage device detected [ 5731.197193] scsi host9: usb-storage 2-1.2:1.0 [ 5732.268389] scsi 9:0:0:0: Direct-Access Kingston DataTraveler G3 PMAP PQ: 0 ANSI: 0 CCS [ 5732.268995] sd 9:0:0:0: Attached scsi generic sg2 type 0 [ 5732.883939] sd 9:0:0:0: [sdb] 7595520 512-byte logical blocks: (3.88 GB/3.62 GiB) [ 5732.884565] sd 9:0:0:0: [sdb] Write Protect is off [ 5732.884568] sd 9:0:0:0: [sdb] Mode Sense: 23 00 00 00 [ 5732.885178] sd 9:0:0:0: [sdb] No Caching mode page found [ 5732.885181] sd 9:0:0:0: [sdb] Assuming drive cache: write through [ 5732.903834] sdb: sdb1 [ 5732.906812] sd 9:0:0:0: [sdb] Attached SCSI removable disk