How to know whether a copy-on-write page is an actual copy?

前端 未结 6 775
感情败类
感情败类 2020-12-29 13:49

When I create a copy-on-write mapping (a MAP_PRIVATE) using mmap, then some pages of this mapping will be copied as soon as I write to specific addresses. At a certain point

6条回答
  •  梦毁少年i
    2020-12-29 14:39

    It is not easy, but possible to determine this. In order to find out whether a page is a copy of another page (possibly another process's) then you need to do the following (recentish kernels):

    1. Read the entry in /proc/pid/pagemap for the appropriate pages in the process(es)
    2. Interrogate /proc/kpageflags

    You can then determine that two pages are actually the same page, in memory.

    It is fairly tricky to do this, you need to be root, and whatever you do will probably have some race conditions in it, but it is possible.

提交回复
热议问题