title: How to print 'flags' field in 'struct page' in Linux-based user program
body: <p>
  Hi,</p>
  
  <p>I am trying to write a user program to print the value of the 'flags' field of all the pages in the 'mem_map' array. I then want to see if the reserved bit is set. </p>
  
  <p>For starters, I wrote a kernel module to print the value of the first 20 pages in the 'mem_map' array, their respective 'flags' fields and the output of the PageReserved macro. </p>
  
  <pre><code>for (;i &lt; 20; ++i) {
    unsigned long *value = &amp;(mem_map[i].flags);
    printk("i = %u page-&gt;flags value = %u phy address = %#x isReserved = %d\n", i,mem_map[i].flags, virt_to_phys(&amp;(mem_map[i].flags)),PageReserved(&amp;mem_map[i]));
  }
  </code></pre>
  
  <p>When I run "dmesg | tail -50", I see the following values:
  </p>
  
  <pre>
  [ 2858.387520] i = 0 page->flags value = 0    phy address = 0x36840000 isReserved = 0
  [ 2858.387520] i = 1 page->flags value = 1024 phy address = 0x36840020 isReserved = 1
  [ 2858.387520] i = 2 page->flags value = 1024 phy address = 0x36840040 isReserved = 1
  [ 2858.387520] i = 3 page->flags value = 1024 phy address = 0x36840060 isReserved = 1
  </pre>
  
  <p>Note that I am printing the Physical address of the 'flags' field along with the value. </p>
  
  <p>I want to reproduce the above result in a user program by just looking at the addresses via pointers. </p>
  
  <p>I opened '/dev/mem', with the offset of the first page's 'flag' field: 0x36840000 . I made sure I compiled the kernel with STRICT_DEVMEM off and added a default 'return 1' in 'devmem_is_allowed()' function.</p>
  
  <pre><code> /* create the offset for mmap() using the physical address of the
      mem_map[] array*/
      off_t offset = 0x36840000;
  
      /* /dev/mem contains the physical memory map */
      if ((fd = open("/dev/mem", O_RDONLY)) == -1) {
          printf("/dev/mem could not be opened.\n");
          perror("open");
          exit(1);
      else {
          printf("/dev/mem opened.\n");
      }
  
      starting_page = (char*)mmap(0, MAP_SIZE, PROT_READ,MAP_SHARED, fd,offset);
  
      if (starting_page == MAP_FAILED) {
          perror("mmap");
          return -1;
      } 
      else {
          printf("Memory mapped at address %p.\n", starting_page);
      }
      mapped_page = starting_page;
      for (i=0;i&lt;10;++i,mapped_page+=32) { 
          printf("\npage i = %u flags value %ul  ", i, *(mapped_page));
      }
  </code></pre>
  
  <p>However, when I simply print out the value of the "flags value" ,I get zeros.  Any suggestions on what I am getting zeroes and how to debug this?</p>
  
  <p>Thanks!
  -RR</p>