[haiku-gsoc] Re: vm_store_anonymous

  • From: "Zhao Shuai" <upczhsh@xxxxxxx>
  • To: haiku-gsoc@xxxxxxxxxxxxx
  • Date: Tue, 27 May 2008 16:25:38 +0800 (CST)

>I'd strongly recommend to have a look at how other systems (Linux, FreeBSD, 
>OpenSolaris)
>implement swap file support. 

That's what I did in the last 2 weeks. I hacked the swap file implementation in 
the Linux and FreeBSD system. Both of them use a disk partition as the swap 
area. Since the swap partition is not formatted, reading/writing is faster than 
accessing a file in the filesystem.
In the Linux system, there is a page cache layer. The contents of recently 
accessed files is stored in the page cache to avoid unnecessary disk activity. 
The pageout dameon periodically flushed the modified pages to the disk. If it 
is an anonymous page, it will be written to the swap partition. Then the page 
table entry related to that page is zeroed. Next time we use the page, a page 
fault will be invoked. And zeroed pte indicates that the page is on swap area, 
so we can fetch it. 
In  FreeBSD, there is a pager layer which moves the page between RAM and the 
secondary storage. There are mainly 3 kinds of pager: vnode_pager, 
device_pager, swap_pager. It's very similar to the Haiku vm system. I think I 
can use it for reference.
I suddenly found myself focus too much on the interaction between swap and 
other parts of vm rather than swap itself.  I will get deeper into the FreeBSD 
swap implementation and re-consider my design.

>Each swap file is divided into allocatable units of, say, 16 pages, each 
>referenced by a handle:
>
>struct swap_file_chunk {
>       swap_file_chunk*        next;
>       addr_t                          cache_offset;
>};
Thanks for your proposal, I will consider that.

Other related posts: