next up previous
Next: Managing jobs Up: Introduction to the Linux Previous: Finding out what's running:

Memory Management

Linux splits the computer's memory into chunks called pages. Every process that runs requires a certain amount of RAM to store its code and data, and Linux manages all of the computer's memory and allocates it to processes as and when they request it. However not all of a process' data is likely to be needed at the same time, so Linux keeps track of when pages were last used by a process and if it was a long time ago it may write the data to a special area of disk, allowing another process to use the RAM. This special disk space is called swap space and writing of memory pages to disk is called paging or swapping. If the original process requests the information that has been paged to disk, Linux will automatically read it and put it in a page in memory; the process will not notice, although it will take longer for it to access the memory.

In the output from top you can see that it reports the swap space usage as well as the main memory. In addition to this is prints the total size of each process, i.e. how much memory it needs, and the resident size, which is how much actual RAM the process is using. For small processes these are often very similar, but it is not unusual for big calculations to have a total size which is hundreds of megabytes more than the resident size.

Because Linux can swap memory pages to disk, it is capable of running processes whose total memory requirement is more than the physical RAM in the machine. This will work OK provided the data that has been paged to disk is only needed rarely. If the data is needed frequently, however, the computer will spend a lot of time swapping data in and out of RAM and it will slow down dramatically. The hard disk will be in constant use, and this is sometimes called disk thrashing.


next up previous
Next: Managing jobs Up: Introduction to the Linux Previous: Finding out what's running:
Phil Hasnip 2007-08-23