The one of the biggest problems of usb flash drives is a slow data write speed. This article will guide you through the process that can possibly increase your flash stick write speed. Okay, first I bought Transcend 8GB usb flash stick. It had been formatted with FAT32 filesystem initially.
Not sure if it can be used to test external usb devices (specifically a usb flash stick). Test USB 3.0 Device Speed. Ask Question 2. Browse other questions tagged linux ubuntu bash dd usb-3 or ask your own question. 3 years, 10 months ago.
So I decided to run data read/write speed test. Mount the filesystem and execute following # hdparm -t /dev/sdb /dev/sdb: Timing buffered disk reads: 102 MB in 3.05 seconds = 33.43 MB/sec $ dd count=100 bs=1M if=/dev/urandom of=/media/disk/test 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 29.5112 s, 3.6 MB/s The disk read speed is good enough, but the write speed is not so good.
That's because most of NAND flash drives (the most commonly used flash sticks) have 128k erase block size. Filesystems usually have 4k (4096 bytes) block size. And here we came into problem.
If the filesystem blocks are not aligned to flash drive blocks, the performance overhead during disk writes will increase. So what we can do is to align filesystem properly. The best way to do this is to use 224 (32.7) heads and 56 (8.7) sectors/track. This produces 12544 (256.49) sectors/cylinder, so every cylinder is 49.128k.
# fdisk -H 224 -S 56 /dev/sdb Now turn on expert mode with fdisk and force the partition to begin on 128k alignment. In my case I have set new beginning of data to 256. Create as many partitions as you need (I created only one - /dev/sdb1).
Do not forget to save changes and write new layout to flash drive (all data on the flash disk will be lost) Now it's time to create the filesystem. I used ext4 because there is a way to tell it to specify a strip width to keep your filesystem aligned: # mke2fs -t ext4 -E stripe-width=32 -m 0 /dev/sdb1 Now lets mount the filesystem and test the overall performance # hdparm -t /dev/sdb /dev/sdb: Timing buffered disk reads: 102 MB in 3.01 seconds = 33.94 MB/sec $ dd count=100 bs=1M if=/dev/urandom of=/media/disk/test 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 17.0403 s, 6.2 MB/s As we can see, the data read performance is almost the same while the write speed is considerably faster. Thank you for your tip! I have run your test and get dd count=100 bs=1M if=/dev/urandom of=/dev/null 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 11.6463 s, 9.0 MB/s dd count=100 bs=1M if=/dev/zero of=/dev/null 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 0.0862834 s, 1.2 GB/s Also I didn't consider that for precise test we need to append `sync` mount option. This option disables write cache buffer. Moreover, today's tests show me extremely good performance with ntfs file system having 64k cluster size and aligned the same way as mentioned in the article (basically it is the same flash drive).
![Cpu Cpu](https://img.raymond.cc/blog/wp-content/uploads/2009/07/usbdeview.png)
Take a look at these values: $ sudo mount -t ntfs-3g -o sync,user,umask=0002 /dev/sdb1 /mnt/flash/ $ dd if=/dev/zero bs=1M count=200 of=/mnt/flash/z 200+0 records in 200+0 records out 209715200 bytes (210 MB) copied, 14.7261 s, 14.2 MB/s It would be good if someone make the same tests to confirm these results. Dear Michael, Could you please explain what you are doing with the number of heads and sectors? Why are you changing them?
Are you trying to get track size to be the same as the filesystem block size? And what does the number of heads mean? I know it does not mean physical heads, but what does it mean? Is the track size derived from total disk capacity divided by number of heads divided by number of cylinders divided by number of sectors per track? That does not seem to add up, for example: # fdisk -l /dev/sda Disk /dev/sda: 500.1 GB, 16 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065. 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1.
1 13 104391 83 Linux /dev/sda2 14 79610 8e Linux LVM # perl -e 'print 16/21,' n' 578606 # Cheers, Aleksey. Anonymous @Alex: Read 'heads' as 'tracks/ cylinder' in the computer outputs and explanations. Now re-read the third paragraph of the blog above that begins with: 'The disk read speed is good enough. ' and ends with: '. Key concept is: 'Adjusting disk geometry of flash drive to multiples of the 128k NAND flash erase block.' The 4k OS read/ write size IS bound by disk geometry parameters, and the 128k erase block size IS NOT.
This way any 4k write operation will be within one 128k erase block. You have 16065 sectors/ cylinder total, which is 8225280 bytes/ cylinder. 8225280 bytes is not evenly divisible by 128k (= 128.1024bytes): Actually, 8225280/ 128k= 62.753. You can't even begin to 'align' the 4k read size to the 128k erase block size in this case. Interesting, but confusing (for a noob like me.) 1. For the read-test you use '/dev/sdb' and for the write-test '/media/disk/test'. Am I correct that this should also be /dev/sdb?
Shouldn't people be warned NOT to run dd on a stick containing data!?!? Can you explain a bit more about the fdisk/expert/begin partition please?
Do I first create the partition and then hit 'x' for expert and then change to. My default states 2048, do I change that to 256? Is that the same for every size stick? I tried this and the outcom is exactly the same speed. Hi Michael, my case is a Kingston DT 101 2G 32GB using NTFS. Are you really serious with this 'guide'? It's really impossible to repartitioning and reformating every USB stick I can use;) Some of them doesn't belongs to me and I use them to write some data to anyone else.
Why the Windows (2k,xp,) can write 8-10 times faster than Linux? Linux have serious problem with USB sticks - yeah! It is unusable.
I had hope that it will be fixed soon, but waiting about 5 years with no advance. Yes i tried all these tricks with ehci and others, sync and async options but still no change. My writing speed on flash disks is about 400kB/s - various HW with linux - the same poor results. Using the same HW with Windows work fine. But any other work in windows is much worse than in linux.
Writing to SSD card in my (Samsung) mobile connected via USB is almost instant. Cannot find any difference in mounting parameters. It is much faster to burn data to DVD than copy data to flash disk. That's really poor and sad. This is insane! Using if=/dev/zero almost writes in an instant!
I tried testing this on my Transcend JetFlash 32GB having an ext4 and an xfs filesystem and below are the results. Here are the partition of my Flash Drive. 1st Partition - 1GB (ext4) Label: boot-os 2nd Partition - 30GB- (xfs) Label: Transcend32G The way I format the 1st partition is: mkfs.ext4 -E stripe-width=32 -m 0 -O ^hasjournal,largefile -L boot-os -vvv /dev/sdc1 mke2fs 1.42 (29-Nov-2011) fstypes for mke2fs.conf resolution: 'ext4' warning: 224 blocks unused. Tim B Using /dev/zero to test is actually a bad idea (usually.), as filesystems such as ext4 will store files full of zero using 'sparse blocks', meaning that they don't actually write the data to the disk. (Instead, they will just write a small amount of data saying, effectively, 'this is a 2GB file full of zeros'.) This is why John above observed such a fast write speed with /dev/zero - because it wasn't actually writing the data. I'd suggest running dd count=100 bs=1M if=/dev/urandom of=/dev/null and checking how fast it goes - if your drive is slower than this, then you should be right with urandom for input.
Otherwise, I'd suggest that the next best bet is to create a 100MB file on a fast storage device (another flash drive?) and use that as the input file, so that you're not generating the randomness on-the-fly. Of course, if you're using an older/simpler filesystem such as FAT32, that doesn't support sparse blocks, then using /dev/zero is not a problem. Tim B I've tested this out, and found that at least with Ubuntu 12.04, following these steps gives no speed increase compared to just creating and formatting the partition with gparted. I also found that the stripewidth parameter to mke2fs didn't make any noticeable different to write speed for me.
In fact, I'm not sure that making these changes should even in principle speed up your drive. While it's true that flash drives use large (eg 128k) erase-block sizes, my understanding is that they still write data in sector-sized blocks (512 bytes), and therefore aligning your partition to 128k will not make a difference to write speeds, at least on a fresh drive. It should only make a difference when the drive starts deleting blocks of data, which only happens once the drive gets full. (And even then, partition alignment has very little to do with the speed.) So I don't think that following these steps will actually make your drive any faster. My suspicion is that the only reason the OP found that his drive ran 2x faster than before, is because he changed the filesystem from FAT32 to ext4, and ext4 is a much faster filesystem than FAT. (Or, at a minimum, the linux ext4 driver is faster than the linux VFAT driver.) Postscript: I think I've confirmed this theory. I reformatted with FAT32 on the exact same disk I was testing on before, and found that my write speed went from 7MB/s down to 4.4MB/s.
So, moral of the story: if you want it to work faster (at least under Linux), reformat it with ext4 instead of FAT32. Anonymous On the subject of FAT32, let's not forget that the default format parameters are wrong. In particular it seems you generally need 32K cluster sizes from what I understand, but the best thing to do purportedly is to format it with the Panasonic SD formatter (which of course is Windows only.) Before testing its speeds, try that.
As far as aligning things properly goes though, if nothing else it might help decrease the actual number of erases and therefore improve the lifetime of the memory card. BTW, it seems most people feel that turning off journalization is the way to go for the best performance. Though honestly, I think it depends on what you're doing with it. For operations where the data on it is unimportant (say videos thrown onto a card to watch later for instance) performance might be the most important. But for more important stuff the compromise might be necessary. I think this could also be impacting people's results though potentially as it increases the bottleneck somewhat.
Ok, so I'm trying to make ext4 work as well as possible with SDHC cards and I ran across this. There are a few things I'm wondering though. Firstly, it says 'Now turn on expert mode with fdisk and force the partition to begin on 128k alignment.
In my case I have set new beginning of data to 256.' How do you know exactly what number to put in? Do we just put 256 for anything, or does it vary? And I'm assuming you mean the 'b' command in expert mode. Anonymous Well, while you are wondering here how factory-made partition and fs layout may not be optimal I faced such a problem. My wife bought Silicon power luxmini 32gb fladh drive with significant discount.
And write speed is nightmare 2mbyte/s. Its default layout:the only fat32 partition starts at 1.28mb!!!! Not 1,2,4 mb, not multiple of 64k or so!!!!!
512b sector size 4k cluster After reading lot of howtos I tested it with flashbench and found peaks of performance at 64k and 4m block sizes at 7 mbytes/s. First should be pagesize×'number of parallel pages could be read/written' Second probably allocation group. Alignment of partition start to 4m + creating fat32 with 64k cluster size and alignment of its start of data section to 4m made large progress to copying files. It is 3.5mbytes/s now under linux but this flash is not seen in win Vista:angry smile. Anonymous This flash is seen under android tablet, and ancient laptop with winxp.
Copying in xp from flash to flash has 1.8mb/s. Addition: write speed i measured by simply copying 9gb of large movie files from external usb hdd to flash. I also reserved 512 clusters after fat for vfat data alignment. I made partitioning with gparted and dont remember drive geometry or whether lba mode is used. Can modifying drive geometry/setting lba mode help to speed up this flash?
![Usb performance test linux download Usb performance test linux download](https://thewirecutter.com/wp-content/uploads/2018/09/usb-3-drives-top-2x1-lowres1024-00247.jpg)
Why is this flash is not seen by Vista? What can I try more in order to speed it up to normal 7mb/s, shown by flashbench?
Thanks to all in advance, Igor.