Thursday, March 22, 2012
The memory monitor
Memory in embedded systems is a limited resource. The m9 has just 16 MB RAM on the base station, and even the upcoming m9r has only 32 MB RAM. That used to be a lot in the 1990s, but today this is almost nothing. Because of this, the design of the m9 had to keep the memory usage in mind. After the motto “what you see is what you get” the m9 has a memory monitor that checks the memory usage of the last 24 hours.
But what is free memory? That is a little bit hard to say in the Linux environment, because the operating system tends to keep things in memory that are not actually needed. In order to speed up later loading, this makes sense. But for the accurate measurement of how much memory is exactly free, the number might be misleading. The m9 reads every 6 minutes the file /proc/meminfo from the operating system, and then stores the number which is in the “MemFree” line. You get a picture like this:
As you can see, the memory is not a one-way street down to zero. The operating system sometimes frees some memory too, and then the graph jumps up again. However, when the graph gets into the area where only a few hundred KB are available, things get tight. This might happen if you have a busy system, and for example all accounts use Microsoft Lync registrations. Well there is a reason why the m9r has more memory.
Anyway if the m9 should really run out of memory, it does some desperate measures. It actually writes a file with some booting information, so that on the next reboot you can see on the status screen why the device was rebooted. After the writing of the file, it does reboot. This is ugly, however just hanging there doing nothing would be even worse.Once that the system is running, the probability that the system is running out of memory is relatively low. Most of the memory is taken during the provisioning and registration phase and after making the first couple of calls. After that, the device has only a few reasons to allocate more memory. The goal with the m9 and with every other embedded device is that it should be running forever without ever running out of memory. The biggest practical obstacle for this is the software update. Unfortunately, updating software that is actually running is very difficult and as with the most embedded systems, the m9 requires a reboot after a software upgrade.