LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 11-12-2006, 02:36 PM   #1
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Rep: Reputation: 15
USB 2.0 slow write but fast read, solution yet?


Hello,

details:
- 2.6.16 kernel ehci, uhci, ohci compiled as modules
- Kingston 1GB USB2.0 pendrive
- read approx 800kb/s
- write approx 8-10mb/s

I've bought a Kingston 1GB USB2.0 pendrive, and I was shocked to see that linux was using a writing speed of 800kb/s, while reading it 8-10mb/s. On Windows the speeds are OK. Not surprisingly.

I first suspected an ehci-uhci mixup, but according to dmesg, it is using EHCI all right. [code #1]

I tried to google, and i found some post within the last 2 years, but none of them presented a solution. I found a couple of threads here, but no solution there as well.
I checked the linux-usb.org, but no sign of this problem was found.

I tried setting the drive in fstab to 'sync', which resulted in a constant slow speed, since the cache was turned off that way. Changing back to 'async' caused a fast copying up to 50% and then slow as hell. I guess caching is like that. I found a solution to set fstab entry to 'nosync', but nosync isn't an option, generates an error.

Now I see that I'm not the only one with this problem. But I guess that there are many folks who can utilize their USB2 storage just fine, and I really want to be one of them.

Thanks for your kind help!

A.

Code:
usb 3-6: new high speed USB device using ehci_hcd and address 10
usb 3-6: configuration #1 chosen from 1 choice
scsi7 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 10
usb-storage: waiting for device to settle before scanning
  Vendor: Kingston  Model: DataTraveler 2.0  Rev: PMAP
  Type:   Direct-Access                      ANSI SCSI revision: 00
SCSI device sda: 2015232 512-byte hdwr sectors (1032 MB)
sda: Write Protect is off
sda: Mode Sense: 23 00 00 00
sda: assuming drive cache: write through
SCSI device sda: 2015232 512-byte hdwr sectors (1032 MB)
sda: Write Protect is off
sda: Mode Sense: 23 00 00 00
sda: assuming drive cache: write through
 sda: sda1
sd 7:0:0:0: Attached scsi removable disk sda
sd 7:0:0:0: Attached scsi generic sg0 type 0
usb-storage: device scan complete

Last edited by ArchNGEL; 11-12-2006 at 04:09 PM.
 
Old 11-13-2006, 11:34 AM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,983

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
I don't think it's a usb issue per se. I've noticed write peeds to pen drives are much slower than write speeds to external hard drives connected by usb. I thought this was due to the fact that pendrives have write algorithms to prevent you from writing to the same sectors too much as pen drive memory only has a limited number of writes. The net effect is to slow down writes.

I really haven't bothered about it since the amount of data I would transfer to a pen drive is genrally limited due to the size of a pen drive as compared to an external hard drive. Perhaps something in the linux usb driver interacts with those pendrive write algorithms adversely.
 
Old 11-13-2006, 03:57 PM   #3
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
Thank You for your answer!

Well, since as none of the threads actually led to the conclusion that every USB2.0 thumbdrive is bitchy on linux, I believe that there should be some other explanation.

And I wouldn't care either if it was 256MB drive, but writing 1GB with 800k/s or 8000k/s does make a difference. And since USB2.0 works fine on Windows (which i'm not planning to use just for that) I have to believe that the device itself works properly.

I kinda felt that noone would show me the big trick, i guess there is not. Ehci driver is not something to configure in /etc, and thus I have to rely on the kernel driver developers or my distro to come up with something. This just doesn't feel right provided that USB2.0 isn't a fresh standard.
 
Old 11-13-2006, 05:12 PM   #4
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,983

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
I guess my point is I'm getting 20MB/sec when writng to and external hard drive connected by usb. I haven't timed anything but my subjective feel is that writing to flash memory is considerably slower in both linux and windows. However, windows seems to cache a lot of writes to ram and only complete the write when you disconnect the flash drive which takes a while in windows. Unmounting my flash drive is much faster in linux. Comparing write times between linux and windows could get tricky because of differences in write caching.

Post back how you are getting your write times and I'll try and see if I can reproduce your problem. It might just be a fedora kernel problem; 800kb/sec seems way slow to me. I think I would have noticed that kind of lag.
 
Old 11-14-2006, 06:57 AM   #5
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
Hello dear Vonnegut reader!

I know about the caching possibility, and I can assure you, that Windows really copied the files much quicker. I removed the drive after the writing had been finished, just to see if it's for real.

Being a Fedora problem... I hope so. However I saw reported cases from the SUSE environment. I'm not expecting 20-40MB/s, but a 8-10MB/s would be nice.

I measured the time running 'time', like so:
]# time cp this_big_file /media/usbdisk && time umount /media/usbdisk

and then I simply calculated a speed average which was below 1MB/s always. Also tried using /dev/zero like so:
]# time dd if=/dev/zero of=/media/usbdisk/testfile bs=16k count=[some huge number] && time umount /media/usbdisk

Files were 300-400MB.

These kind of tests resulted in a higher average speed, between 1MB/s and 2MB/s. (Of course the 'dd' calculated a 5MB/s, but it was only writing to cache - just as you suggested about Windows.

Thank You!
 
Old 11-19-2006, 02:15 PM   #6
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
What does dd know that cp doesn't?

Code:
[angel@SAL-9000 Studio 60]$ time dd if=Studio.60.on.the.Sunset.Strip.S01E08.HDTV.XviD-XOR.avi of=/media/usbdisk/studio.avi && time umount /media/usbdisk
716763+1 records in
716763+1 records out
366982786 bytes (367 MB) copied, 198.016 seconds, 1.9 MB/s

real    3m18.272s
user    0m1.268s
sys     0m5.580s

real    1m1.448s
user    0m0.004s
sys     0m0.292s
[angel@SAL-9000 Studio 60]$ mount /media/usbdisk
[angel@SAL-9000 Studio 60]$ time cp Studio.60.on.the.Sunset.Strip.S01E08.HDTV.XviD-XOR.avi /media/usbdisk/studio.avi && time umount /media/usbdisk

real    6m35.890s
user    0m0.044s
sys     0m2.636s

real    1m44.830s
user    0m0.000s
sys     0m0.260s
[angel@SAL-9000 Studio 60]$
 
Old 03-28-2007, 10:51 AM   #7
UltraZelda64
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Rep: Reputation: 0
I'm a Zenwalk user, originally a Windows user until a year or two ago, and have an old Western Digital external 120GB drive that supports both USB 2.0 and FireWire. I used it without problems with Windows, normally connected with FireWire, but due to some error where it would detect itself as eight different drives in Linux (which has corrected itself since I formatted it with XFS instead of NTFS), I connected it with USB for use in Linux.

Long story short... I'm experiencing the same problems as the topic starter. The drive, using a USB 2.0 cable and connected to a brand-new USB 2.0 card, goes *slow*. Typically just a couple megabytes per second. I tried connecting it with FireWire, and it's even worse... I'm lucky to get even one megabyte a second. I went and got a new cable, thinking maybe my previous cable was a USB 1 cable and wasn't optimal. Apparently, I was wrong.

Yet, this drive can read at insanely high speeds. To be fair, it's going to be mainly for storage, so for the most part data will stay on it, but still... even copying five gigs is quite painful, and considering every file I'll move over to it is massive... hopefully it's fixed soon. Even worse, I don't know if it had to do with the speed or not, but I can only guess it did... the file system claimed to have around 99 percent (!) fragmentation after the initial moving of files from the internal drive. Ouch. BTW, files are all large (mostly in the hundreds of megs) ISO images. An xfs_fsr brought the fragmentation level down to 0.0%.

It was the last drive I had for data storage that I had to rid of Windows partitions and switch to Linux, and my first experience is not too good... frankly, the drive's performance in Windows with NTFS ran circles around its current XFS-formatted state. Still moving files over now, BTW.

Edit: After moving over several more gigs worth of CD images, check it out:

root[jeffrey]# umount /dev/sdc1
root[jeffrey]# xfs_db /dev/sdc1
xfs_db> frag
actual 219856, ideal 145, fragmentation factor 99.93%
xfs_db>

...and I just defragged it before moving the files. :/

Last edited by UltraZelda64; 03-28-2007 at 10:56 AM.
 
Old 03-28-2007, 11:00 AM   #8
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
My bad, I should have posted the solution, or at least the solution that worked for me. I upgraded the kernel to 2.6.18 on my FC5 box. Since Fc6 comes with 2.6.18, there was no problem, and the Western Digital Mybook works nice. Even Firewire400 works, although I found that there was no significant difference between USB2 and FW400.
 
Old 03-28-2007, 11:14 AM   #9
UltraZelda64
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Rep: Reputation: 0
Zenwalk 4.4.1 has the 2.6.20 kernel, so I don't think upgrading will help in my case. Thanks anyway, though.

But man... looking at the fragmentation on this drive... it's insane. I've never seen anything before like it (and I thought I've seen it all, being a past Windows user), and my internal XFS drives have never had this problem. For those interested, here's a little sample of the verbose output XFS' defragmenter is giving me:

root[jeffrey]# xfs_fsr -v /dev/sdd1
/mnt/extfiles start inode=0
ino=471359922
extents before:38265 after:1 DONE ino=471359922
ino=471359909
extents before:36734 after:1 DONE ino=471359909
ino=471359916
extents before:30221 after:1 DONE ino=471359916
ino=471359920
extents before:21409 after:1 DONE ino=471359920
ino=471359927
extents before:14485 after:1 DONE ino=471359927
ino=471359917
extents before:14210 after:1 DONE ino=471359917
ino=471359926
extents before:11426 after:1 DONE ino=471359926
ino=471359919
extents before:10060 after:1 DONE ino=471359919
ino=471359918
extents before:9905 after:1 DONE ino=471359918

...and it continues to defrag.

Last edited by UltraZelda64; 03-28-2007 at 11:16 AM.
 
Old 03-28-2007, 12:19 PM   #10
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
You have a more cardinal problem than I could help you with.
What if you tried a Vanilla kernel? Ah, frankly I have no idea.
Good hunting!
 
Old 03-29-2007, 02:59 AM   #11
UltraZelda64
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Rep: Reputation: 0
I can't believe it. After tons of research, I saw this quote:

Quote:
Another thing that can kill your usb 2 hard drive performance
is if the mount is setup to be synchronous. I have
a large usb 2 disk formatted as an XFS volume. I was
noticing even rather small files were very slow to
copy. The drive icon showed that checkbox "synchronous"
was checked, after putting that off the speed got much
better.
Mark
...in another thread, which got me thinking... maybe that's the problem. I've tried just about everything else. Zenwalk features automount, and I figured maybe it's using suboptimal (or, in this case, really bad) mount options. I unmounted the automounted drive, created an entry in /etc/fstab, and manually mounted the drive. Moved over a test file of around 600 megs, and it worked--and fast. Around 60 megs a second, as it should have been all along. Not to mention, far fewer fragments on this test file, and the drive sounded healthier while moving (it was pretty noisy while copying previously, don't know why, since it was only doing 1-3 megs a second...).

If only I would have known this sooner, before already moving 50 gigs worth of files over to it. Now, I'm just trying to figure out how to disable the automount feature... at least until this problem is fixed.
 
Old 03-29-2007, 02:18 PM   #12
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
I guess it has something to do with udev?
Glad you found a temporary solution. Does automount still screws up even if you have the correct entry in your /etc/fstab?
 
Old 05-29-2007, 01:47 PM   #13
jagakatt
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
Well, I do not have a final solution, but more information for other sharp brains.

On my Dell Laptop D620 I get around 20MB/s both read and write to both my USB-disks (Iomega / PackadBell).
On my P4 Compaq I get around 20MB/s read and 1,5MB write to the same disks.

Both are running updated Kubuntu 7.04 / kernel 2.6.20-18

"mount" -output before remount
/dev/sda1 on /media/disk type ext3 (rw,noexec,nosuid,nodev,sync,data=ordered)

After getting rid of the "sync" I got 35MB/s write !! (did not belive USB-disk cold be that fast!)
After power off/on the drive it automatically mounts without the "sync"-option (unchecked a checkbox after clicking on properties of the drive).

So, thank's a lot UltraZelda64!!!

Last edited by jagakatt; 05-29-2007 at 02:10 PM.
 
Old 05-29-2007, 05:40 PM   #14
ArchNGEL
Member
 
Registered: Apr 2003
Location: Hungary
Distribution: Fedora Core 6 (2.6.18)
Posts: 61

Original Poster
Rep: Reputation: 15
kernel 2.6.18 resolved my issues
 
Old 12-12-2007, 02:44 AM   #15
chadwick
Member
 
Registered: Apr 2005
Location: At the 100th Meridian where the great plains begin
Distribution: Debian Testing on T60 laptop
Posts: 105

Rep: Reputation: 17
On my thinkpad T60 using Debian testing, uname -a says I'm using kernel 2.6.22-3-686. I was having this same problem until I came across this thread.

When I mount a USB drive on /dev/sdc1 with the following line
Code:
/dev/sdc1       /mnt/sdc1     auto    sync,noauto,user,exec     0       0
in /etc/fstab, and try to copy a 5.2 MB file to the drive from the local hard disk, then after an entire minute, 244 KB have been transferred. Copying a 29 MB file from the external drive to the local drive takes about 10 seconds.

Then if I unmount it, change the line in /etc/fstab to
Code:
/dev/sdc1       /mnt/sdc1     auto    noauto,user,exec     0       0
then copying the 29 MB file to the external disk takes an unnoticeable fraction of a second. Same with copying to the local disk from the external disk.
 
  


Reply

Tags
cp, dd, ehci, ehcihcd, file, transfer, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nfs write == super slow; read == super fast - problem? BrianK Linux - Networking 4 08-23-2007 10:59 PM
remount USB Disk Read Write poetfreak MEPIS 1 08-30-2006 01:49 PM
k3b - slow read, but fast write bob66 Linux - Software 5 05-13-2005 05:35 PM
Read/Write LEGO USB Tower swinchen Programming 0 01-25-2005 09:36 PM
How i can read/write data from USB PIC16? njel Programming 0 07-14-2004 10:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration