Can multiple vm_pages refer to a same swap device page?

Konstantin Belousov kostikbel at gmail.com
Thu Oct 3 08:33:22 UTC 2019


On Wed, Oct 02, 2019 at 04:31:41PM -0400, Yoshihiro Ota wrote:
> Hi forks,
> 
> Given a process can allocate lot of memory even cosuming swap space, then fork a child process, and both parent and child processes stay live while doing differen things, I expect a system needs to track how many processes are refering to same swap pages.
> 
No, it does not.

> How does FreeBSD keep track of multiple processes refering to same swap pages?
> Is it by multiple vm_page objects pointing to same swap device pages with daddr_t?
> 
> I've been looking around swap_pager.h, vm_page, vm_object, struct swblk, and struct swdevt but I don't find reference count for swap device pages.
> 
> Am I missing something?
Yes, the mechanism for CoW sharing the same read-only page is called
shadowing and it is a form of the content inheritance, where we insert a
new default (later swap) object on top of existing object on forking.

The sentence above perhaps sounds too cryptic, I recommend you to look
at the 'Design and Implementation' book by McKusick and this old article
by Dillon
https://www.freebsd.org/doc/en_US.ISO8859-1/articles/vm-design/index.html
The part about vm objects is still relevant and should answer your question.


More information about the freebsd-hackers mailing list