This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM3xx - SD card writting is very slow

Hello,

We are writting to a SDHC card from the DM355.

A test with dd shows very high speed performaces (around 8MBs transfer rates in writing)

However when we copy an image bufffer from DDR to SD using fwrite command, the transfer rates goes down to 0.7MBs which is not acceptable.

It looks like the system is not optimizing the copy.

Anyone ever had this issue ?

Thanks & Kind regards

  • 1. Are you writing the file when using dd and fwrite?

    2) What arguments do you specify when mounting the SDHC card? Can you also share the output of "mount" command?

  • Dear Sanjeev,

    Thank you for your reply.

    1) Are you writing the file when using dd and fwrite?

    Yes the files are correctly written to the SD card when using dd from command line or fwrite from our program

    See the results given by dd for a 100 MB file :

    time dd if=/dev/zero of=/mnt/usb/toto bs=1M count=100
    100+0 records in
    100+0 records out
    real 0m 37.16s
    user 0m 0.00s
    sys 0m 8.97s

    When writing a 100 MB file using fwrite (a simple buffer copy from DDR to SD) we need around 140s which is very high..

    2) What arguments do you specify when mounting the SDHC card? Can you also share the output of "mount" command?

    mount does not return any output (even in verbose mode)

    Here is the command we are using :

    mount -vt vfat /dev/mmcblk0p1 /mnt/usb -o async

    Any help or advice would be very appreciated.

    Thanks again

    Richard

  • Richard,

    It may not be right to compare dd and fwrite - due to level of abstractions involved. The comparison gets skewed a lot when you use /dev/null vs another file.

    When you read from the file, the time you attribute to write also includes the time for reading the contents of the source file as well.

    To do a more apple-to-apple comparison, use /dev/urandom instead of /dev/zero; and write a sequence of buffers from memory - eliminating any fread() operation.

    I believe you should see considerable difference in both measurements.

    You can also consider using low level read/write operations instead of fread/write. I am not sure about relative gains - but you can try async IO operations - aio_read/aio_write.

    giro360 said:

    Here is the command we are using : mount -vt vfat /dev/mmcblk0p1 /mnt/usb -o async

    This is good - i wanted to check if you are mounting the card in SYNC mode. Do note that you will need to manually "sync" the data before removing the card.

  • Sanjeev,

    We just tried with /dev/random instead of /dev/null

    time dd if=/dev/random of=/mnt/usb/toto bs=1M count=10
    10+0 records in
    10+0 records out
    real 5m 3.87s
    user 0m 0.01s
    sys 0m 0.19s

    not sure if we are doing an apple-to-apple comparison considering the results we have :)

    Also, we wrote a simple test code that does a 7MB write to SD with good performances (2 sec run time for the 7MB) but could not reproduce this when taking 12 MB from DDR to SD.

    #include <stdio.h>
    #include <string.h>

    int main()
    {
    FILE * f;
    char s[] = "Bonjour";
    int i;
    f = fopen("bonjour.txt", "wb");

    if (f != NULL)
    {
    for(i=0; i<1000000; i++)
    {
    fwrite(s, sizeof(char), strlen(s), f);
    }
    fclose(f);
    }
    else
    perror("bonjour.txt");

    return 0;
    }


    Any comment ?
  • If you compare these:

    time dd if=/dev/zero of=/mnt/usb/toto bs=1M count=100
    100+0 records in
    100+0 records out
    real 0m 37.16s
    user 0m 0.00s
    sys 0m 8.97s

    time dd if=/dev/random of=/mnt/usb/toto bs=1M count=10
    10+0 records in
    10+0 records out
    real 5m 3.87s
    user 0m 0.01s
    sys 0m 0.19s

    The time to write from /dev/random would be on higher side (as compared to /dev/urandom) due to blocking nature of reads from /dev/random. But i guess, you get overall picture.

    The code example you provided seems much similar to the /dev/zero situation. The buffer is exactly same across each fwrite(), and you get better numbers. Use a real file instead. You can use gettimeofday() for profiling across the file IO - including open, write, close and sync - operations.

    I also noticed that your out location is "/mnt/usb/toto". Are you using a USB based SD card writer?