简体   繁体   中英

linux kernel function page_address()

I'm confused with the function:

void * page_address(struct page *page)

which (1) "convert a given page to its logical address" according to "Linux Kerenl developement 3rd edition" (2) "returns the linear address associated with the page frame" according to "understanding the linux kernel>>" (3) "returns the physical address of the page" according to "understanding the linux virtual memory manager"

which one is correct then?

Let's take (1): this function takes a pointer to the physical page (page frame), isn't that pointer the "logical address associated with that page frame" already? what's the difference between that pointer value and the returned value then? thanks.

1 and 2 are both correct - they are two ways of saying the same thing (although explanation 2 is clearer). Explanation 3 is incorrect - page_address() returns the virtual address, not the physical address, of the page frame.

page_address() does not take a pointer to the page / page frame. It takes a pointer to the struct page , which is a kernel data object that represents the page.

page_address() returns virtual address of the page.

http://lxr.free-electrons.com/source/mm/highmem.c#L408

/**
 * page_address - get the mapped virtual address of a page
 * @page: &struct page to get the virtual address of
 *
 * Returns the page's virtual address.
 */
 void *page_address(const struct page *page)
 {
          unsigned long flags;
          void *ret;
          struct page_address_slot *pas;

          if (!PageHighMem(page))
                  return lowmem_page_address(page);

          pas = page_slot(page);
          ret = NULL;
         spin_lock_irqsave(&pas->lock, flags);
         if (!list_empty(&pas->lh)) {
                 struct page_address_map *pam;

                 list_for_each_entry(pam, &pas->lh, list) {
                         if (pam->page == page) {
                                 ret = pam->virtual;
                                 goto done;
                         }
                 }
         }
 done:
         spin_unlock_irqrestore(&pas->lock, flags);
         return ret;
}

page_address() returns the physical address, not the virtual address:

https://www.kernel.org/doc/gorman/html/understand/understand023.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM