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. # define sdcard optimized mounting option for root fs on sdcards or emm flash
  2. /:
  3.  mount.mounted:
  4.  - device: {{ grains['rootfs'] }}
  5.  - fstype: ext4
  6.  - opts: defaults,async,barrier=0,commit=100,noatime,nodiratime,errors=remount-ro
  7.  - dump: 0
  8.  - pass_num: 1
  9.  
  10.  
  11. # set default IO sceduler to deadline for sdcard
  12. # deadline scheduler could group small accesses to lesser sdcard latency
  13. /etc/udev/rules.d/60-schedulers.rules:
  14.  file.managed:
  15.  - source: salt://sdcard_optim/60-schedulers.rules
  16.  - user: root
  17.  - group: root
  18.  - 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. #!/usr/bin/python
  2. import subprocess
  3.  
  4. def function():
  5.  '''
  6.  Return the rootfs partition
  7.  '''
  8.  
  9.  grains = {}
  10.  command = ('df -h | grep \'\/$\' | awk \'{ print $1 }\'')
  11.  
  12.  p = subprocess.Popen(command, universal_newlines=True,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  13.  grains['rootfs'] = p.stdout.read()
  14.  retcode = p.wait()
  15.  
  16. return grains

The “60-schedulers.rules” files is a simple udev order to force the deadline scheduler on all SDCards :

# set deadline scheduler for sdcard
ACTION=="add|change", KERNEL=="mmcblk[0-9]", ATTR{queue/scheduler}="deadline"

Leave a Reply

Your email address will not be published. Required fields are marked *


*