Composite page (Compound page)

Source: Internet
Author: User

Composite pages (Compound page) are two or more pages that are physically contiguous as one
Separate large pages, which can be used to create large pages (hugepage) used in Hugetlbfs,
You can also use to create a transparent large page (transparent huge page) subsystem. But
It cannot be used in page cache because it is managed in the page cache
A single page.


The way to assign a composite page is to use the Alloc_pages function, which has a parameter order of at least 1,
and set the __gfp_comp tag. Because, depending on the definition of a composite page, it typically consists of 2 or more
A contiguous physical memory page, which is determined by its implementation, so the order parameter cannot
to 0.


The memory allocation method for calling Alloc_pages is usually as follows:


     p = alloc_pages (Gfp_kernel, 2);


But how is this different from creating a composite page? The difference is in creating a composite
page, the metadata associated with this composite page (metadata) is created.


Represents the metadata for a composite page that exists in the page structure body, and the flag flag in page pages is used to
Identify the composite page. In a composite page, the first normal page of the beginning becomes the "head page", with
Pg_head tag, and all subsequent pages are called "tail pages", marked with Pg_tail.
In a 64-bit system, you can have extra tokens to represent the page header and footer of a composite page;
There are not so many tags in the 32-bit system, so a scheme for reusing other tokens is used.
All pages in the composite page are marked with Pg_compound, and then for the last
Use the Pg_reclaim tag, because Pg_reclaim is only used in the page cache, and

Composite pages are not used in the page cache at all.


You can use the Pagecompound function to detect whether a page is a composite page, and another function pagehead
and function Pagetail are used to detect whether a page is a page header or footer. At each end of the page
The struct contains a pointer to the header page-first_page, which can be used Compound_head
function is obtained.


So when a composite page is no longer being used by the system, how do we know how much the composite page contains
A normal page, and how do you know where the destructor for the composite page (destructor) exists?
First, one might think that this information exists in the page structure of the header, but it is not
Fortunately, there is no space available in this structure. Therefore, all of this information is stored
In the LRU field of the first end, cast the size of the composite page (order) first
As a pointer type, and then stored in Lru.prev, the destructor is stored in the Lru.next.
This explains why a composite page must be at least two pages.


A destructor that lives on two composite pages in the kernel, which is called by default Free_compound_page
To return all pages to the system's page-box allocator, and the HUGETLBFS subsystem calls Free_huge_page
To do some statistics and release.


One of the most classic examples of using composite pages is THP (transparent huge page),
Other drivers use composite pages to facilitate the management of the cache.


Ref
===
1. https://lwn.net/Articles/619514/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Composite page (Compound page)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.