On Wednesday 19 January 2011, Dave Martin wrote:
> It works well enough that e2fsck passes after a writing an image to a
> card which was previously full of random data.
> 
> Anyway, it's there if anyone wants to play with it -- comments welcome.

* You write with a block size of just 4kb here, which is really suboptimal
when talking to SD cards. The performance should be best if you write only
aligned 64kb blocks or larger. In particular, it's faster to fill 64kb
with zeros when writing just one non-zero byte than it is to skip the
remaining space.

* At least for the output, I'd do O_DIRECT, since you don't care if the
block device ends up in your page cage or not. For the input, you might
want to mmap the image file into memory and do madvise(MADV_DONTNEED)
on the data you have already written out, to evict it from your page cache.

* In the cases where we have an actual SD card reader, it would be really
cool to use ioctl(BLKDISCARD) on the medium to erase it before writing to
it. This has two effects:
  1. For data you want to write immediately, the following write is faster,
     especially if you don't write 4MB at a time.
  2. The card's wear levelling works much better if some of the space has
     been marked as erased. You know which parts are zero, so erasing them
     would be a signficant speedup for the life-time of the system.
Note that some cards fill erased space with 0xff bytes, while others fill
the card with 0x00. Erase does not work if you are dealing with a USB
card reader.

* I'd like to see this program do a ioctl(HDIO_GETGEO) to verify that the
partition is aligned. You should probably print a warning if the alignment
of the ext3 partition is less than 4MB, and bail out if it is less than 64kb,
as that is the point where it gets really slow.

        Arnd

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to