Less known Solaris Features: Resource Management - Part 5: Management of memory resources
So far we configured limits on the usage of operating syste resources and the CPU. Let´s get back to the class room example used before. A different course at the unseen university is “Memory Management for beginners”. And at start our students have problem with severe memory leaks. It would be useful to impose resource management to the memory management.
Without Resource Management
Bob wrote a little script within Perl that eats a large amount of the available memory.
When we start this script, it will allocate memory by pushing blocks of 1 Megabyte of x chars onto a stack.
When you look in the forth column you see the resident set size. The resident set is the amout of data of a process in the real memory. After a short moment the process
./memoryhog.pl uses 24 MB of our precious memory (20 times 1 MB plus the perl interpreter minus some shared stuff).
Memory resource management
It would be nice to control the amount of data, that resides in the real memory. Solaris has such a capability. At first we have to activate the resource cap enforcement daemon. You have to login as root to do so:
The rcapd daemon enforces resource caps on a group of processes. The rcapd supports caps on projects and zones at the moment. When the resident set size of a group of processes exceeds the defined cap. To reduce the resource consumption of a process group, the daemon can page out infrequently uses pages of memory to swap.
For testing purposes we configure the daemon in such a way, that it scans every second for new processes in projects with a resource cap. Furthermore we configure it to sample the resident set size every 1 second, too. Additionally the pageout statistics of the rcapd will be updated every second, too.
For testing purposes we define a new project called mmgntcourse and add the user bob to this project:
Now we set an resource cap for the resident set size of 5 Megabytes for this project:
Okay, now get back to the window with the login of user
bob. Let´s start the
memoryhog.pl in the
Okay, get back to a different window and login as root. With the
rcapstat you can observe the activities of the rcapd. In our example we tell
rcapstat to print the statistics every 5 seconds:
As you see, the resident set size stays at approx. 5 Megabyte. The RSS may increase above the configured size, as the applications may allocate memory between the RSS sampling intervals. But at the next sampling size the
rcap starts to force the page out of this exceeding pages. After a few seconds the resident set size is enforced, again. You can observe this behaviour in column 5 of the rcapstat printout.