[En-Nut-Discussion] Improvement for faster mounting of large SD cards

Rob van Lieshout (PragmaLab) info at pragmalab.nl
Tue Jan 19 09:33:52 CET 2010

Hello Malte

> I am using a 4GB SD card together with Nut/OS. Unfortunately, mounting
> a volume took several minutes. 

Using up to 8GB SD-HC cards, we have to same problem regarding the long
mounting time. Since the number of free clusters is only needed when you
start  write operations, I slightly modified the code so that the free
clusters are not counted during the mount process (that now takes less than
a second on a 14.57 MHz Mega256). The first time the card is asked to write
data, the clusters are counted, which indeed takes a long time with large
capacity cards. It's not really an optimization, just a way to make things
less annoying for the user.

Mixing up the code like you did by saving calls doesn't sound like a good
idea to me and I would not encourage you to put the code in NutOS. The
FS-module in the current NutOS benefits from functional separated parts
within that module. Increasing the cluster size is of course an almost
linear optimization: the bigger the size, the less cluster-entries there
will be in the FAT table to examine. Large cluster size makes the waste on a
card a little bit bigger, but since the capacity of the cards concerned is
quite big, it is not a big problem (except when dealing with lots of small
files). The problem here is that you need to instruct your end-users to
format the cards in a special way (4K is the standard cluster size).

I did not found the time yet to optimize the counting of the free clusters
but it sure is on my list. One approach could be to mount the card without
counting clusters and start a background thread that does the job. Although
for sure the code can be optimized (like you proved already), we'll have to
accept that FAT32 gets slow with large cards on a 8-bit CPU with 16 Mhz

Please keep in mind that, if you need the card for reading only, you can
omit the counting of the free clusters.


Rob van Lieshout 

More information about the En-Nut-Discussion mailing list