linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Free the 2nd vmemmap page associated with each HugeTLB page
@ 2021-07-14  9:17 Muchun Song
  2021-07-14  9:17 ` [PATCH 1/5] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) Muchun Song
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Muchun Song @ 2021-07-14  9:17 UTC (permalink / raw)
  To: mike.kravetz, akpm, osalvador, mhocko, song.bao.hua, david,
	chenhuang5, bodeddub, corbet
  Cc: duanxiongchun, fam.zheng, linux-doc, linux-kernel, linux-mm,
	zhengqi.arch, Muchun Song

After the feature of "Free sonme vmemmap pages of HugeTLB page" is enabled,
the mapping of the vmemmap addresses associated with a 2MB HugeTLB page
becomes the figure below.

     HugeTLB                  struct pages(8 pages)         page frame(8 pages)
 +-----------+ ---virt_to_page---> +-----------+   mapping to   +-----------+---> PG_head
 |           |                     |     0     | -------------> |     0     |
 |           |                     +-----------+                +-----------+
 |           |                     |     1     | -------------> |     1     |
 |           |                     +-----------+                +-----------+
 |           |                     |     2     | ----------------^ ^ ^ ^ ^ ^
 |           |                     +-----------+                   | | | | |
 |           |                     |     3     | ------------------+ | | | |
 |           |                     +-----------+                     | | | |
 |           |                     |     4     | --------------------+ | | |
 |    2MB    |                     +-----------+                       | | |
 |           |                     |     5     | ----------------------+ | |
 |           |                     +-----------+                         | |
 |           |                     |     6     | ------------------------+ |
 |           |                     +-----------+                           |
 |           |                     |     7     | --------------------------+
 |           |                     +-----------+
 |           |
 |           |
 |           |
 +-----------+

As we can see, the 2nd vmemmap page frame (indexed by 1) is reused and remaped.
However, the 2nd vmemmap page frame is also can be freed to the buddy allocator,
then we can change the mapping from the figure above to the figure below.

    HugeTLB                  struct pages(8 pages)         page frame(8 pages)
 +-----------+ ---virt_to_page---> +-----------+   mapping to   +-----------+---> PG_head
 |           |                     |     0     | -------------> |     0     |
 |           |                     +-----------+                +-----------+
 |           |                     |     1     | ---------------^ ^ ^ ^ ^ ^ ^
 |           |                     +-----------+                  | | | | | |
 |           |                     |     2     | -----------------+ | | | | |
 |           |                     +-----------+                    | | | | |
 |           |                     |     3     | -------------------+ | | | |
 |           |                     +-----------+                      | | | |
 |           |                     |     4     | ---------------------+ | | |
 |    2MB    |                     +-----------+                        | | |
 |           |                     |     5     | -----------------------+ | |
 |           |                     +-----------+                          | |
 |           |                     |     6     | -------------------------+ |
 |           |                     +-----------+                            |
 |           |                     |     7     | ---------------------------+
 |           |                     +-----------+
 |           |
 |           |
 |           |
 +-----------+

After we do this, all tail vmemmap pages (1-7) are mapped to the head vmemmap
page frame (0). In other words, there are more than one page struct with
PG_head associated with each HugeTLB page.  We __know__ that there is only one
head page struct, the tail page structs with PG_head are fake head page structs.
We need an approach to distinguish between those two different types of page
structs so that compound_head(), PageHead() and PageTail() can work properly
if the parameter is the tail page struct but with PG_head.

The following code snippet describes how to distinguish between real and fake
head page struct.

	if (test_bit(PG_head, &page->flags)) {
		unsigned long head = READ_ONCE(page[1].compound_head);

		if (head & 1) {
			if (head == (unsigned long)page + 1)
				==> head page struct
			else
				==> tail page struct
		} else
			==> head page struct
	}

We can safely access the field of the @page[1] with PG_head because the @page
is a compound page composed with at least two contiguous pages. The main
implementation is in the patch 3.

In our server, we can save extra 2GB memory with this patchset applied if there
are 1 TB HugeTLB (2 MB) pages. If the size of the HugeTLB page is 1 GB, it only
can save 4MB. For 2 MB HugeTLB page, it is a nice gain.

Muchun Song (5):
  mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1)
  mm: introduce save_page_flags to cooperate with show_page_flags
  mm: hugetlb: free the 2nd vmemmap page associated with each HugeTLB
    page
  mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key
  mm: sparsemem: use page table lock to protect kernel pmd operations

 Documentation/admin-guide/kernel-parameters.txt |   2 +-
 include/linux/hugetlb.h                         |   6 +-
 include/linux/page-flags.h                      | 103 ++++++++++++++++++++++--
 include/trace/events/mmflags.h                  |   4 +
 include/trace/events/page_ref.h                 |   8 +-
 lib/test_printf.c                               |   2 +-
 lib/vsprintf.c                                  |   2 +-
 mm/hugetlb_vmemmap.c                            |  67 ++++++++-------
 mm/ptdump.c                                     |  16 +++-
 mm/sparse-vmemmap.c                             |  70 ++++++++++++----
 10 files changed, 218 insertions(+), 62 deletions(-)

-- 
2.11.0



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-07-29  6:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14  9:17 [PATCH 0/5] Free the 2nd vmemmap page associated with each HugeTLB page Muchun Song
2021-07-14  9:17 ` [PATCH 1/5] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) Muchun Song
2021-07-26 21:04   ` Mike Kravetz
2021-07-27  6:27     ` Muchun Song
2021-07-29  6:00       ` Muchun Song
2021-07-14  9:17 ` [PATCH 2/5] mm: introduce save_page_flags to cooperate with show_page_flags Muchun Song
2021-07-26 23:18   ` Mike Kravetz
2021-07-27  7:06     ` Muchun Song
2021-07-14  9:17 ` [PATCH 3/5] mm: hugetlb: free the 2nd vmemmap page associated with each HugeTLB page Muchun Song
2021-07-26 21:16   ` Matthew Wilcox
2021-07-26 23:56     ` Mike Kravetz
2021-07-27  7:15     ` Muchun Song
2021-07-14  9:17 ` [PATCH 4/5] mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key Muchun Song
2021-07-14  9:18 ` [PATCH 5/5] mm: sparsemem: use page table lock to protect kernel pmd operations Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).