This question relates to a generic question on operating system resource management. There are many ways of managing memory, whether you are talking about 'working set sizes', page-able memory, segmented memory, etc.
If you are very curious about the exact algorithms used, check out the source code for the kernel to trace through the logic. The methods used by Ubuntu and other systems are too complex to be covered in a single question.
Chat with our AI personalities