Handling SWAP

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
mrvn
Member
Member
Posts: 43
Joined: Tue Mar 11, 2008 6:56 am

Re: Handling SWAP

Post 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
Life - Don't talk to me about LIFE!
So long and thanks for all the fish.
z180
Member
Member
Posts: 32
Joined: Tue Mar 04, 2008 12:32 pm

Post 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)
Post Reply