Like linux I woudn't specialize this to a partition. Make it a mmap()-able file (of which a partition is a special case). That way you need only one function for demand page loading of binaries, swap partition and swap file.MarkOS wrote:I'm thinking about handling swap of memory to my disk.
I will use another partition (like linux does) to handle swap.
How must I decide memory to swap?
What are the best methods?
As to what to swap: Swap out the page that you won't need again for the longest time.
Unless you have a crystal ball device in your system you won't be able to achive that though. Use the random or LRU methods others already mentioned.
From my algorithm class I remember that the random method is on average no more than twice as bad as swapping out the page not needed longest, i.e. you get twice as much swapping as the clairvoyant ideal algorithm.
LRU on the other hand has worst case scenarios that are truely evil. Imagine a program using a working set one page larger than you have and going over it again and again. Every page you get a page fault, swap out the next page, swap in this page and go on. But they don't happen too often with the amount of ram people have nowadays.
MfG
Mrvn