0

I want to track down which pages of a memory region mapped with mmap have been modified.

Can the dirtiness of pages of a mmap be found from userspace? porved to be pretty useful.

On linux (ubuntu @ 5.15.0-46-generic) I can see once the memory is mapped all pages are marked dirty (the SOFT-DIRTY page table entry bit) in the /proc/pid/pagemap file. Doing an echo 4 >> /proc/pid/clear_refs clears the bit. Every write in the mapped regio sets the appropriate page's dirty bit, as expected(?).

On Android (Android 12 AOSP @ 5.10.43-android12-9-00005-g740f7fbe5f39-ab7943734) that't not the case though. When a region is mapped, the dirty bit is 0. Writing to the region still does not raise the soft-dirty bit.

Any ideas why Android is behaving differently and/or if it's possible to control that behavior and how?

hiddenbit
  • 333
  • 1
  • 2
  • 11
  • I could be wrong but I think this is because arm/arm64 does not have support for soft dirty pages. I.E. `CONFIG_HAVE_ARCH_SOFT_DIRTY` is `=n` or unset. – Marco Bonelli Aug 31 '22 at 16:52
  • right, this makes sense but I'm seeing other people doing the same thing on arm (e.g. https://stackoverflow.com/questions/47137413/c-know-when-a-variable-is-read-or-written/) Guess I'll have to dive into the kernel code and see for myself – hiddenbit Sep 01 '22 at 07:37
  • To be honest that question you link doesn't say anything about using the soft-dirty bit. The answer just mentions it, possibly overlooking the fact that the question was tagged arm. Checking kernel sources I cannot see `HAVE_ARCH_SOFT_DIRTY` under arm/arm64, might require some more digging than a simple grep though. – Marco Bonelli Sep 01 '22 at 12:22
  • Yeah you're right. I just got carried away as in my search for ways to track modified memory I just discovered about the `pagemap` and `kpageflags` files. – hiddenbit Sep 01 '22 at 16:48

0 Answers0