Page 2 of 2

Re: Handling SWAP

Posted: Tue Apr 01, 2008 5:06 am
by mrvn
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?
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.


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

Posted: Tue Apr 01, 2008 6:37 am
by z180
i think you could write a swap storage structure for
multiple swap backing storage modules
that contains following function pointers
init
pagein
pageout
add_swap
remove_swap

and you could write seperate drivers
for regular files
for partitions
for swapping over network
for compress in ram (I dont know a system that does this)