Monday, February 3, 2014

Run-time Memory Hog Mitigation Techniques in Linux


In my last post, I mentioned that memory hogs can bring down an entire system. To reduce the possibility of this situation, Linux provides some techniques to limit the impact of memory hogging user space programs on entire system. I don't know of any memory hogging mitigation techniques available/possible for linux kernel space. I'm yet to explore whether SLUB has any mitigation techniques built in, but I doubt it.

User space memory hog mitigation techniques:
  • Per-process memory limits: Linux provides setrlimit/prlimit system calls to configure a process's resource limits. We can us this to configure per-process memory limit. getrlimit/prlimit system call fetches the current per-process limits. Man pages of setrlimit/getrlimit/prlimit at http://man7.org/linux/man-pages/man2/getrlimit.2.html.

      Similarly, linux also has ulimit system call. I believe this is obsoleted by setrlimit/getrlimit. 

      We can also configure per-process memory limit using CLI command ulimit. Though ulimit system call is obsolete, I believe ulimit command internally uses setrlimit/getrlimit to configure the resource limits. Here are a few screens which show the usage of ulimit command:
 








                                   


     Similar to ulimit, I heard about cgroups tool that helps configure memory limits, but I haven't used it yet.


Usefulness of this feature for embedded systems

Even though linux provides this feature, I haven't seen embedded applications using this feature. This is primarily because it is a difficult design decision to pre-estimate the amount of memory to set aside for each application running in the system. Instead, a typical system design doesn't limit application memory & instead expect application developers to write safer code.

No comments:

UA-48797665-1