Francis Devereux

May 21, 2008

A Memory Management Idea

Filed under: Operating Systems — frankoid @ 11:53 am

There is often a trade-off between speed and memory usage.  For example, when a web browser loads a new page, it can do a number of things with the old page, including:

  • nothing (throw it away)
  • cache the files that it downloaded from the server
  • cache the fully rendered version of the page

The first of these options uses the least memory and the last one (probably) uses the most.  Unfortunately, the first option also makes going back to the old page the slowest (because the browser must get the files for the page from the server again and render them again).  Now, the browser on my Nokia N95 seems use the first option.  This makes sense, because mobile phones don’t have very much RAM and don’t have virtual memory, so if the N95’s web browser cached pages in RAM then there wouldn’t be much RAM left form other applications to use.

The Idea

My idea is that when the OS notices that free RAM is low it could make a call to applications to say “please free some RAM”.  Then apps could merrily use RAM without having to worry about that causing problems for other apps.  If memory started to get tight the OS would ask the apps to free up some RAM and they could discard their caches.

Of course, there wouldn’t be much point in allocating some memory for a cache only to be told to free it up again straight away, so their should also be a way to allocate memory that would fail if there wasn’t plenty free – an “malloc if possible” OS call.

This idea would not only be useful on devices without virtual memory, like phones.  It would also be useful on desktop computers; for example the OS could ask apps to free up RAM before it started to page to disk.

Potential Problems

Memory management is already a difficult problem, especially in a virtual memory environment; it is difficult for the OS to determine what to keep in RAM and what to page to disc (or throw away, in the case of disc caches).  This idea would make things even more complicated.

There could be some interesting reentrancy issues too.  For example, an application could be asked to free RAM as a result of it requesting RAM itself.

I wonder whether this idea has ever been implemented?  If you’ve come across a system that implements this idea I’d be very interested to hear about it…

Create a free website or blog at WordPress.com.