user1544314
user1544314

Reputation: 43

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.

Upvotes: 3

Views: 6498

Answers (3)

Subbu
Subbu

Reputation: 2101

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;
}

Upvotes: 2

user3341973
user3341973

Reputation: 13

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

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

Upvotes: -2

caf
caf

Reputation: 239321

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.

Upvotes: 11

Related Questions