1

We know this following function from Linux kernel, which takes a pointer to the struct page and outputs the virtual address of the page frame:

void * page_address(struct page *page)

So I wonder if a function in a reserved version is available: taking a virtual memory address and outputting the corresponding virtual page id? (The output should not be a struct page in-memory data structure because of the assumption, that a page could be swapped to the disk.)

Thanks. Correct me, if I am wrong or have a duplicated question over SO.

1 Answer 1

1

After reading several virtual address translation post, I found the virtual page number is an intermediate result in the translation and is mentioned in those posts.

Here is an example: https://stackoverflow.com/a/45128487/10971650.

What's relevant here is the variable vpn for the virtual page number. (I use the function getpagesize instead.)

#include <unistd.h>
#include <stdint.h>

uintptr_t get_virtual_page_number (uintptr_t vaddr) {
  return vaddr / getpagesize();
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .