linuxmemorymemory-managementpage-fault

How to measure number of allocated page tables?


As far as I know, Linux does not allocate page tables until needed (allocation happens on-demand as pages are used). I want to check how many page tables are really allocated during program execution. Could you please let me know how can I measure the number of actually allocated pages?


Solution

  • If I understood correctly you want to measure number of page tables of running program.

    You can use RSS value to calculate number of active page tables:

    RSS is the Resident Set Size and is used to show how much memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory.

    Use the RSS and divide into page table size (by default it is 4KB).

    For instance, I want to count page tables of tmux on my machine:

    $ ps aux | grep tmux
    da       21995  0.0  0.0  26416  2768 ?        Ss   May17   4:16 tmux
    

    The RSS value is 2768 and if we divide it by 4: 692.

    But note that RSS also counts shared libraries. If I do cat /proc/21995/maps, there will be complete list of memory mappings of tmux, most of them are glibc shared libraries.

    References: