add two more zeros to the for loop upper bound, and ran time ./a.out got longer time:
uid=1007:
real 0m1.141s
user 0m0.209s
sys 0m0.932s
uid=1008:
real 0m1.095s
user 0m0.199s
sys 0m0.896s
@forest thanks a lot! I tried a variant of your c code, and indeed setuid to 1007 didn't matter. So it's only the user that's logged in that causes the speed gap.
@forest indeed I have been using /dev/null since half an hour ago. The results remain unchanged. I also noticed that with /dev/zero replaced by /dev/urandom, the 4x gap disappears. With bs=1M the gap also disappears, but not with large bs like 1G, 2G. Somehow 1007 is configured differently but don't know where to look.
@forest Indeed there was also a "tmpfs /run/user/0" entry under "df -h". I removed both, and ran dd command without sudo, but still got about 40 MB/s under the account with uid 1007. I started looking into this because the 1007 user on this machine ran wget much slower than other user/machines.
@forest df -h indeed reveals the following mount point "tmpfs 26G 0 26G 0% /run/user/1007". I will umount it and try again. Meanwhile could you shed some light on why it can slow disk down? Thanks!
@forest Thanks. I just tried and succeeded with " sudo sh -c ' echo 3 > /proc/sys/vm/drop_caches ' ", but still got ulimit -m 100000000; dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync 1+0 records in 1+0 records out 1073741824 bytes (1.1 GB) copied, 27.1012 s, 39.6 MB/s