Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the dirtiness of pages of a mmap be found from userspace?

Can dirtiness of pages of a (non-shared) mmap be accessed from userspace under linux 2.6.30+? Platform-specific hacks and kludges welcome.

Ideally, I'm looking for an array of bits, one per page (4kB?) of the mmap'ed region, which are set if that page has been written to since the region was mmap'ed.

(I am aware, that the process doing the writing could keep track of this information - but it seems silly to do so if the kernel is doing it anyway.)

Thanks,

Chris.

like image 582
fadedbee Avatar asked Jun 17 '10 09:06

fadedbee


2 Answers

See /proc/*/pagemap and /proc/kpageflags interfaces. First tells you PFN for an address, second tells you dirty bit given PFN.

See fs/proc/task_mmu.c , Documentation/vm/pagemap.txt, Documentation/vm/page-types.c .

like image 134
adobriyan Avatar answered Oct 17 '22 06:10

adobriyan


The traditional solution is to mprotect to read only, and then handle the sigsegv and mark dirty before reprotecting to allow writes. We did this at ObjectStore a long time ago for this very purpose.

like image 42
bmargulies Avatar answered Oct 17 '22 08:10

bmargulies