Saltstack : state for SDCard / flash storage optimization (Arm SBC)
All my servers are small Arm SBCs that use SDCards or eMMC for storage. For all of them, I use the same optimization state that basically do 2 things :
- Change commit and barrier settings of ext4 (with a proper backup-ed power system)
- Set the scheduler to deadline, which is the more efficient one for my usage
The state:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# define sdcard optimized mounting option for root fs on sdcards or emm flash /: mount.mounted: - device: {{ grains['rootfs'] }} - fstype: ext4 - opts: defaults,async,barrier=0,commit=100,noatime,nodiratime,errors=remount-ro - dump: 0 - pass_num: 1 # set default IO sceduler to deadline for sdcard # deadline scheduler could group small accesses to lesser sdcard latency /etc/udev/rules.d/60-schedulers.rules: file.managed: - source: salt://sdcard_optim/60-schedulers.rules - user: root - group: root - mode: 644 |
As you can see, I use a custom grains to determine the root partition, because I have several servers with different configurations.
Here is my “rootfs” grains, stored in <salt home>/states/base/_grains/rootfs.py:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/usr/bin/python import subprocess def function(): ''' Return the rootfs partition ''' grains = {} command = ('df -h | grep \'\/$\' | awk \'{ print $1 }\'') p = subprocess.Popen(command, universal_newlines=True,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE) grains['rootfs'] = p.stdout.read() retcode = p.wait() return grains |
The “60-schedulers.rules” files is a simple udev order to force the deadline scheduler on all SDCards :
1 2 |
# set deadline scheduler for sdcard ACTION=="add|change", KERNEL=="mmcblk[0-9]", ATTR{queue/scheduler}="deadline" |