1

My embedded system has 2 GB RAM and 100 MB swap partition. I recognize, after continues monitoring that average memory usage of RAM is ~50 %. For some reason system start use SWAP memory and use almost 40 % of it (40 MB). I want prevent such thing because my device flash has a big problem with number of writes and I need it for ~10 years of use. After run these set of commands I get to list of processes that use SWAP :

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less​

My system file /etc/sysctl.conf confiured with parameter : vm.swappiness=1 , so according articles I read it should use SWAP only if it really need. (I investigated the results with vm.sappiness=0, but didn't have results yet.)

I know that there is a way to prevent from specific processes use swap, but what is a correct one?

  • This doesn't answer your question, but with that setup, do you need the swap in the first place? 100 MB isn't that much on a 2 GB machine, so you could probably do without it, and avoid this issue too. Also, the amount of swap in use at one time doesn't tell how much writes go to the swap: some rarely-if-ever used data might end up in swap the first the memory is full, and if it's never modified, there are no further writes. – ilkkachu Nov 6 '17 at 14:56
  • This sounds like a job for the nice family... ionice nice renice – RubberStamp Nov 6 '17 at 15:03
  • You may also want to decrease verbosity level of logs in rsyslog configuration. – Jaroslav Kucera Nov 6 '17 at 15:36
  • my system is embedded base very shrink Debian 8 based system , that has problem with number of writes/read per-block on his flash drive, but it run an application that use pretty more resources. This is a reason why we declare swap partition if system get to critical point it will use swap partition. – Sergey Meerovich Nov 7 '17 at 12:15
4

You can set swappiness per process with cgroups

echo 0 > /sys/fs/cgroup/<your custom group>/memory.swappiness

Anyway my advice is to use zram for compressed swapping in ram.

  • Just to add, this can also be achieved with the libcgroup and the cgset command. – Raman Sailopal Nov 6 '17 at 15:28
0

I test on two systems , where I detect previously use of 40% of SWAP option of :

vm.swappiness=0

This option really helped . I didn't see any use of swap for last 4 days

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.