user3337215
user3337215

Reputation: 101

usage of void put_page(struct page *page) in Linux

I trace Linux source code and find this function: void put_page(struct page *page)

I Googled it and some people say this function use to construct a map from physical frame address to virtual address.

But I trace the put_page function in mm/swap.c. The code behavior seems not used for mapping physical to virtual address.

Any one know what this function do?

Upvotes: 4

Views: 5350

Answers (3)

Mahonri Moriancumer
Mahonri Moriancumer

Reputation: 6013

A "put_page" will copy the page to transcendent memory and associate it with the type and offset associated with the page.

A "get_page" will copy the page, if found, from transcendent memory into kernel memory, but will NOT remove the page from from transcendent memory.

See the Linux kernel doc: frontswap.txt for details.

Upvotes: 2

Giacomo1968
Giacomo1968

Reputation: 26024

I just found this which seems very succinct & useful:

There are two phases of these functions:

  1. delete the page from lru cache (__page_cache_release)
  2. freeing the page to memory allocator

Consider the allocation process:

  1. page is allocated
  2. page table entries are fixed
  3. page is added to lru cache.

In the put_page functions, page table entries are not handled. So the control path should fix/remove appropriate page table entries depending before calling thes functions.

Upvotes: 1

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137557

In the Linux kernel, a function named put_ generally means "freeing" or "releasing" something. (As "put" is the opposite of "get"). From a brief look through the code, it appears that function is called to release a struct page.

The (related) function put_pages_list is actually documented:

/**
 * put_pages_list() - release a list of pages
 * @pages: list of pages threaded on page->lru
 *
 * Release a list of pages which are strung together on page.lru.  Currently
 * used by read_cache_pages() and related error recovery code.
 */

To me, this confirms that put_page "releases" a single struct page.

Upvotes: 2

Related Questions