Init.d/sysctl min_free_kbytes and OOM

I've been going through all boot scripts, just to get to know OpenWrt better. The current script I'm working on is init.d/sysctl and I have some questions if someone is willing to answer them.

Now this script seems untouched in forever reading the copyright statement. A lot has changed since then, memory included, does it still hold up today?

vm.min_free_kbytes is set to prevent system instability under heavy memory utilization which is more of a problem for memory constraint devices I think because that limit can be reached more easily.

Converting the OpenWrt table of hardware into sql and dumping out rammb's unique values this gave me a 2^x list:
16,32,64,128,256,512,1024,2048,4096,8192

Reading up on different locations because docs.kernel.org for me is a bit lacking in its description regarding recommendations and use cases, I found that widely used settings ranges between 1%~5% when it comes to servers.

The current code has 3 options:

  1. greater than 65536 kb which is 128M+ reserves 16M
  2. greater than 32768 kb which is 64M reserves 8M
  3. and less than 64M reserves 1M

My assumption when reading the code that it compensates for the fact that the amount of memory in /proc/meminfo is always a bit less, forcing it to take one stepback. This way 127M will still reserve 16M.

At this point I have the following questions:

  • Did I read the code correctly ?

  • What is the reason behind reserving 12.5% for 64M-128M devices?

  • Would reserving more memory for high memory devices have any benefits or
    is 16M enough?

Personally I found that 1 out of every 32mb set aside gives an acceptable number
for high-memory device if more is needed, but deviates quite a bit:

total memory	: 16,32,64,128,256,512,1024,2048,4096,8192
reserved in code:  1, 1, 8, 16, 16, 16,  16,  16,  16,  16
1/32M (~3%)		:  1, 1, 2,  4,  8, 16,  32,  64, 128, 256

Thanks in advance.

Does OpenWRT with 32MB of RAM sound like a server to you?
What problem you are trying to fix?

In 1996 maybe :rofl: but no, I was focused on the more memory rich devices.

  • Code readability
  • Optimization if possible
  • My understanding of init.d scripts, in this case sysctl

Somewhat better explanation:

1 Like

Thanks that's quite helpful.

2 Likes