# high kernel load when writing files to usb pen drve

## manojpm

hi, 

i just got myself a 2GB iball usb pen drive. i tried copying 2GBs of data from my hard disk to the usb drive. it took me around 30 minutes on gentoo(amd64).Also, while copying, the kernel load was around 7-8 thoughout the copying process.to read the same 2 GB data back from the device, took just 3 minutes on gentoo. On windows xp, writing 2Gbs to usb drive took just 15 minutes and it was pretty smooth. what could be wrong ?? 

proc: amd athlon 64 3500+

motherbaord: ASUS A8N-VM

RAM: 1GB

kernel: 2.6.19

I used nautilus to do the copy operation.

----------

## NeddySeagoon

manojpm,

Do you have any USB drive errors in dmesg ?

Which USB block device drive are you using (what device does your USB pen appear as)?

Both those times are pretty dire - it shows a data rate of 1 or 2 MB/sec.

A USB 2 FLASH drive should get better than 4Mb/sec in write mode, the limit being the FLASH write speed.

----------

## manojpm

This is what i get in dmesg, when i plugin my usb pen drive

usb 1-8: new high speed USB device using ehci_hcd and address 2

usb 1-8: configuration #1 chosen from 1 choice

scsi2 : SCSI emulation for USB Mass Storage devices

usb-storage: device found at 2

usb-storage: waiting for device to settle before scanning

scsi 2:0:0:0: Direct-Access     Generic  USB Disk         0.00 PQ: 0 ANSI: 2

SCSI device sdb: 4030463 512-byte hdwr sectors (2064 MB)

sdb: Write Protect is off

sdb: Mode Sense: 00 00 00 00

sdb: assuming drive cache: write through

SCSI device sdb: 4030463 512-byte hdwr sectors (2064 MB)

sdb: Write Protect is off

sdb: Mode Sense: 00 00 00 00

sdb: assuming drive cache: write through

 sdb: sdb1

sd 2:0:0:0: Attached scsi removable disk sdb

usb-storage: device scan complete

when i read/write  from/to  the usb drive, i get no extra messages in dmesg

gnome volume manager auto mounts the usb pen at "/media/USB Disk" , it appears as /dev/sdb1

the usb pen drive package says

"Date transfer rate : read speed 14 MB/sec max, write speed: 8 MB/sec max"

----------

## manojpm

dmesg | grep -i usb

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

usbmon: debugfs is not available

ehci_hcd 0000:00:0b.1: new USB bus registered, assigned bus number 1

ehci_hcd 0000:00:0b.1: USB 2.0 started, EHCI 1.00, driver 10 Dec 2004

usb usb1: configuration #1 chosen from 1 choice

hub 1-0:1.0: USB hub found

ohci_hcd: 2006 August 04 USB 1.1 'Open' Host Controller (OHCI) Driver (PCI)

ohci_hcd 0000:00:0b.0: new USB bus registered, assigned bus number 2

usb usb2: configuration #1 chosen from 1 choice

hub 2-0:1.0: USB hub found

Initializing USB Mass Storage driver...

usbcore: registered new interface driver usb-storage

USB Mass Storage support registered.

usbcore: registered new interface driver hiddev

usbcore: registered new interface driver usbhid

drivers/usb/input/hid-core.c: v2.6:USB HID core driver

usb 1-8: new high speed USB device using ehci_hcd and address 2

usb 1-8: configuration #1 chosen from 1 choice

scsi2 : SCSI emulation for USB Mass Storage devices

usb-storage: device found at 2

usb-storage: waiting for device to settle before scanning

scsi 2:0:0:0: Direct-Access     Generic  USB Disk         0.00 PQ: 0 ANSI: 2

usb-storage: device scan complete

usb 1-8: USB disconnect, address 2

usb 1-7: new high speed USB device using ehci_hcd and address 3

usb 1-7: configuration #1 chosen from 1 choice

scsi3 : SCSI emulation for USB Mass Storage devices

usb-storage: device found at 3

usb-storage: waiting for device to settle before scanning

scsi 3:0:0:0: Direct-Access     Generic  USB Disk         0.00 PQ: 0 ANSI: 2

usb-storage: device scan complete

----------

## NeddySeagoon

manojpm,

That all looks good. You are using the faster usb-storage block driver and the device is detected as USB 2.0

As there are no errors in dmesg, you are not getting any retries, which slow down the useful data transfer rate.

The transfer rates on the device package are those dictated by the FLASH memory itself. You should expect something lower in practice because of the need to write file system meta data. e.g. the FAT, directory information and so on. Thats true in both Windows and Linux.

What else shares the USB root hub (the connector on the PC) with pen drive ?

Sharing with other devices including USB hubs can slow things down.

Linux writes to a buffer in main RAM and only flushes the buffer to disk when it needs the memory, has nothing else to do or you issue the sync or umount commands, so Linux may not actually commit much of the data to the device until later that windows. You can turn off this caching by using the  *Quote:*   

> -o sync

 option to mount.

----------

## manojpm

when i use -o sync, the data transfer is very very very pathetically slow. although the kernel load is reduced by half and the usb LED doesnt blink so often, for a 2 Gb data transfer, it shows estimated time to be 6 hours . i cancelled it after 10 minutes as it was still showing 6hrs remaining.

----------

## NeddySeagoon

manojpm,

Yep -o sync is not a speed up.

----------

## manojpm

what else could be the problem? . it works properly on win xp. could it be some driver issues ?

----------

## Janne Pikkarainen

Please try with another I/O scheduler. I think cfq might be pretty good for USB sticks, but your mileage may vary.

----------

## manojpm

I am already using the cfq i/o scheduler. i have tried kernel versions 2.6.18-r6 and 2.6.20 as well. still the same heavy kernel load and very low data write speed.

----------

## manojpm

i changed the kernel pre-emption to voluntary instead of low latency desktop and also changed the i/o scheduler to deadline i/o schduler.

so now 2GB data transfer takes about half the time, about 15-20 minutes. but the kernel load is still high(6-7)  during the entire process. Also, even after the data transfer is over, it takes 3-4 minutes for the USB LED to actually stop blinking indicating that a lot of data is getting cached during the write operation(how do i prevent this ??) and only getting flushed after the copy operation. high cache usage is also reported by gnome system monitor applet. This(cache flushing) used to happen before(when i used the default CFQ I/O sheduler), but now the time taken for the last flush operation is comparatively less.

----------

## ArNiS

The same problem here. My 512Mb USB flash drive worked well a pair months ago. I worked under KDE. After some updates it became slow. A week ago I switched to Gnome and I experience the same problem again. The most interesting is 

```
antares arnis # hdparm -tT /dev/sda1

/dev/sda1:

 Timing cached reads:   1948 MB in  2.00 seconds = 973.94 MB/sec

 Timing buffered disk reads:   26 MB in  3.06 seconds =   8.49 MB/sec

```

973 MB/s should be enough to copy an elephant in minutes!  :Smile:  But it seems so slow in the real. Any suggestions are greatly appreciated.

----------

## manojpm

sudo hdparm -tT /dev/sda1 

/dev/sda1:

 Timing cached reads:   2476 MB in  2.00 seconds = 1237.28 MB/sec

 Timing buffered disk reads:  210 MB in  3.02 seconds =  69.51 MB/sec

i am getting good read speeds. how do i test write speeds ?

----------

## Evincar

 *manojpm wrote:*   

> sudo hdparm -tT /dev/sda1 
> 
> /dev/sda1:
> 
>  Timing cached reads:   2476 MB in  2.00 seconds = 1237.28 MB/sec
> ...

 

That seems like the speed of your hard drive, not your USB stick. There's simply no way to achieve 69 MB/s in an USB. And mind you, I think the first result is more related to your memory/CPU speed than anything else.

Check what the device of your USB is, most likely it is /dev/sdb. Well, actually, I am pretty sure

[code]sdb: Write Protect is off 

sdb: Mode Sense: 00 00 00 00 

sdb: assuming drive cache: write through 

SCSI device sdb: 4030463 512-byte hdwr sectors (2064 MB) 

sdb: Write Protect is off 

EDIT: Fixed the code mess.

----------

## manojpm

you are absolutely correct.

here are the real read speeds of my usb  :Smile: 

 sudo hdparm -tT /dev/sdb1

/dev/sdb1:

 Timing cached reads:   2440 MB in  2.00 seconds = 1218.93 MB/sec

 Timing buffered disk reads:   36 MB in  3.13 seconds =  11.48 MB/sec

any idea how to test write speeds ??

----------

## the_enigma

I'm just going to add in my two cents here.  Unfortunately I don't have a solution, but I seem to have a similar problem.  One particular brand of CF card reader here in the office is impossible for me to use.  Transfers start at ~1-2MB/s and dwindle to 30kB/s when copying 512MB.  And by copying, I mean 'dd if=raw.image of=/dev/sdb'.  No filesystem stuff, the card isn't mounted etc.

As reported above, load averages hit around 7 during these times, and I can see that one core in my system (Centrino Duo) is in "wait" pretty much constantly.  Also I get the following printed in dmesg

```

sd 4:0:0:0: [sdb] Sense Key : 0x0 [current] 

sd 4:0:0:0: [sdb] ASC=0x0 ASCQ=0x0

sd 4:0:0:0: [sdb] Sense Key : 0x0 [current] 

sd 4:0:0:0: [sdb] ASC=0x0 ASCQ=0x0

sd 4:0:0:0: [sdb] Sense Key : 0x0 [current] 

sd 4:0:0:0: [sdb] ASC=0x0 ASCQ=0x0

sd 4:0:0:0: [sdb] Sense Key : 0x0 [current] 

sd 4:0:0:0: [sdb] ASC=0x0 ASCQ=0x0
```

That repeats continuously, but roughly once every 10-15 seconds, no more.  Also if I try to 'lsusb' while a transfer is in place, I get 

```
usb 2-1: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110

usb 2-1: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110

usb 2-1: usbfs: USBDEVFS_CONTROL failed cmd lsusb rqt 128 rq 6 len 255 ret -110
```

Don't know if this will help anyone, but it'd be good to find a solution.

----------

