0

When a user performs some setup via a Web GUI, I'm calling sync() to ensure the setup changement is immediately saved to the SD Card. (I'm doing this because the user sometimes switches off the power after doing the setup task)

I'm working with raspbian. My SD Card is a 16GB Kingston Class 10 (industrial).

Calling the sync() system call (from unistd.h) will block normally about 1-2 seconds, but sometimes it can block up to >5 secs. IMHO: Between two calls of sync() I'm not writing more than 1MB to the persistent filesystem.

I've disabled a lot of logs. /var/log, /run, /tmp are tempfs

Is this normal that sync() blocks as this long? What can I do to reduce the consumed time by sync() ?

Additional Info

I've checked the disk IO with sudo iotop -o -a for some minutes:

  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN      IO    COMMAND
   95 be/3 root          0.00 B   1544.00 K  0.00 %  1.03 % [jbd2/mmcblk0p2-]
32254 be/4 root          0.00 B      0.00 B  0.00 %  0.63 % [kworker/u8:2]
 5975 be/4 root          0.00 B    528.00 K  0.00 %  0.32 % myapp.elf

Is syncing to SD Card really that slow?

  • I have never noticed a delay but only use the command from a shell. The obvious answer is the time is due to writing the buffered data. Are you confident that is not the reason? – joan Jun 20 '18 at 10:37
  • calling time syncon the shell gives me also several seconds – powerpete Jun 20 '18 at 11:03
  • I have just tried on a Pi freshly booted. The first (shell) sync took 5 seconds, subsequent ones 5 to 6 milliseconds. That is much faster than my laptop, 200-400 milliseconds. My laptop has an older version of Linux, which might explain its comparative slowness. – joan Jun 20 '18 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.