I'm using an XU4 running Ubuntu as a samba server for several IP cameras. The cameras will write video to the XU4 continuously at roughly 300 KB/s (combined), or 2.4 mbps. So I need a stable network connection. Experience with wifi causes the cameras to drop frames, so a good link is important. I therefore use 100 mbps ethernet, which should be plenty. Still the cameras drop frames, but not always:

When the exported file system is on the emmc card, everything is rock solid.When the exported file system is on an extern USB disk, there are occational frame drops.When the exported file system is on an SD card, there are frequent frame drops.

But the SD card is good for write speeds up to 10 MB/s, and if I log into the camera and write to the mounted disk, I achieve write speeds of a few MB/s, much higher than the write speed of the video. So for some reason, the camera is very picky when it writes video. What I can't understand is why the camera should care, or even know, what the physical medium is. Even if latency is an issue when writing to an SD card, I think smbfs or at least the Linux kernel, should hide this through caching. I've tried to increase the write caching both in smbd and in the Linux kernel, but it makes no impact. I've also tried increasing the priority of smbd through renice and chrt, but that doesn't help either.

I could perhaps export the emmc card and then let XU4 copy to the SD card as new files appear, but that is cumbersome (and if the problem is that writing to SD locks up the XU4 sufficiently to make the cameras drop frames, it wont help).

SSD probably helps, but I'm trying using a 256 GB SD card now to see if it's possible to move to that, since it will be such a physically compact setup. So far, it's not a 100% success, but I don't really understand why. 300 KB/s should not be much, not even for SD. So I wonder if it rather has something to do with latency (in particular because I can run dd commands on the camera writing to the samba mount at great speed), but if so, that again should be amendable through caching. It's odd that the samba client should notice what the physical medium is, when the physical medium should support at least 10x the transfer speed. Another explanation could be that writing to SD locks up the entire XU4 long enough for the samba client to notice. So I tried to have smbd run with realtime priority with chrt, but that didn't help.

I've tried to ping the cameras from the XU4. The response time is always well below 1 ms, so the network seems fine.

I.e. the exported emmc directory is monitored for new files, and once one is written, they are moved to the sd card. This actually works. I no longer see frame drops from the camera, or at least they are greatly reduced. I could also try to export a ramdisk, but caching either by Linux or smbd really should have made that unneccessary.

While this "works", it's kludgy and not probably entirely safe. But it should prove that there is no hardware limitation.

This hack could be a case for unionfs, where an upper layer acts as a faster cache for the slower lower layer, but I don't think this is supported?

I tried numerous samba options, I tried to tune kernel parameters, I tried to make a file system wrapper looking at unionfs, overlayfs and aufs, but all in vain. But finally, I think I've managed to solve my problem in a clean way.

My SD card was ext4 formatted. When I tried to reformat using f2fs, the troubles seem to have gone away. To use f2fs on an SD card, for which f2fs was designed, makes a huge difference.

The root filesystem on the emmc card has ext4. If f2fs can make such a difference on an SD card, I wonder whether it has been considered to use f2fs on the emmc card?

I've been using F2FS on my SD card for about 18 months and I regularly stream video off my XU4 (via Samba) while writing to the SD card at the same time and I don't think it's ever dropped frames on me, so hopefully you should get good performance with it. I don't use the stock version of Samba available though as I always build my own from source.

I'd also recommend mounting the SD card with the discard option. Will make the initial file deletion take longer but will give you more stable performance during the file writes.

I've now seen the cameras write up to 6 MB/s to the SD card over samba, and it works perfectly. That's 20x the rate when ext4 caused problems, and much more what I could do on an external hard disk over USB.

midtskogen wrote:I've now seen the cameras write up to 6 MB/s to the SD card over samba, and it works perfectly. That's 20x the rate when ext4 caused problems, and much more what I could do on an external hard disk over USB.