Search code examples
gem5

Access pagemap in gem5 FS mode


I am trying to run an application which uses pagemap in gem5 FS mode. But I am not able to use pagemap in gem5. It throws below error -

"assert(pagemap>=0) failed"

The line of code is:

int pagemap = open("/proc/self/pagemap", O_RDONLY);
  assert(pagemap >= 0);

Also, If I try to run my application on gem5 terminal with sudo ,it throws error-

sudo command not found

How can I use sudo in gem5 ??


Solution

  • These problems are not gem5 specific, but rather image / Linux specific, and would likely happen on any simulator or real hardware. So I recommend that you remove gem5 from the equation completely, and ask a Linux or image specific question next time, saying exactly what image your are using, kernel configs, and provide a minimal C example that reproduces the problem: this will greatly improve the probability that you will get help.

    I have just done open("/proc/self/pagemap", O_RDONLY) successfully with: this program and on this fs.py setup on aarch64, see also these comments.

    If /proc/<pid>/pagemap is not present for any file, do the following:

    • ensure that procfs is mounted on /proc. This is normally done with an fstab entry of type:

      proc            /proc       proc    defaults    0   0
      

      but your init script needs to use fstab as well.

      Alternatively, you can mount proc manually with:

       mount -t proc proc proc/
      

      you will likely want to ensure that /sys and /dev are mounted as well.

    • grep the kernel to see if there is some config controlling the file creation.

      These kinds of things are often easy to find without knowing anything about the kernel.

      If I do:

      git grep '"pagemap'
      

      to find the pagemap string, which is likely the creation point, on v4.18 this leads me to fs/proc/base.c, which contains:

      #ifdef CONFIG_PROC_PAGE_MONITOR
          REG("pagemap",    S_IRUSR, proc_pagemap_operations),
      #endif
      

      so make sure CONFIG_PROC_PAGE_MONITOR is set.

    sudo: most embedded / simulator images don't have it, you just login as root directly and can do anything by default without it. This can be seen by the conventional # in the prompt instead of $.